extends Node const layout = { "outside": ["Panel_begin_begin",[["Door_3", "carnation"], ["Door_2", "rose"], ["Door_1", "lilac"]]], "lilac":["Panel_lielack_lilac",[["Door_1","outside"],["Door_5","amethyst"],["Door_vert_1","rose"]]], "rose":["Panel_soar_rose",[["Door_vert_1","lilac"],["Door_6","ruby"],["Door_vert_2","carnation"],["Door_2","outside"]]], "carnation":["Panel_incarnation_carnation",[["Door_vert_2","rose"],["Door_7","amber"],["Door_vert_3","sunflower"],["Door_3","outside"]]], "sunflower":["Panel_sun_sunflower",[["Door_8","topaz"],["Door_vert_3","carnation"],["Door_4","achievement"],["","lime"]]], "emerald":["Panel_herald_emerald",[["Door_9","lime"],["Door_vert_4","sapphire"],["","lemon"]]], "sapphire":["Panel_sap_sapphire",[["Door_vert_4","emerald"],["Door_10","blueberry"],["Door_vert_5","amethyst"]]], "amethyst":["Panel_thistle_amethyst",[["Door_vert_5","sapphire"],["Door_11","plum"],["Door_vert_6","ruby"],["Door_5","lilac"]]], "ruby":["Panel_bury_ruby",[["Door_vert_6","amethyst"],["Door_12","cherry"],["Door_vert_7","amber"],["Door_6","rose"]]], "amber":["Panel_antechamber_amber",[["Door_vert_7","ruby"],["Door_13","orange"],["Door_vert_8","topaz"],["Door_7","carnation"]]], "topaz":["Panel_top_topaz",[["Door_vert_8","amber"],["Door_14","lemon"],["Door_8","sunflower"]]], "lime":["Panel_limelight_lime",[["Door_vert_9","blueberry"],["Door_9","emerald"]]], "blueberry":["Panel_blue_blueberry",[["Door_vert_9","lime"],["Door_10","sapphire"],["Door_vert_10","plum"]]], "plum":["Panel_lump_plum",[["Door_vert_10","blueberry"],["Door_11","amethyst"],["Door_vert_11","cherry"]]], "cherry":["Panel_hairy_cherry",[["Door_vert_11","plum"],["Door_12","ruby"],["Door_vert_12","orange"]]], "orange":["Panel_blue_orange",[["Door_vert_12","cherry"],["Door_13","amber"],["Door_vert_13","lemon"]]], "lemon":["Panel_melon_lemon",[["Door_vert_13","orange"],["Door_14","topaz"]]], } var _visited var _door_mapping var _flood_boundary var _panel_boundary func generate(rng): _visited = [] _door_mapping = {} _flood_boundary = [] _panel_boundary = [] enterRoom("outside") while !_panel_boundary.empty(): var filtered = [] for door in _flood_boundary: if _door_mapping.has(door[1]): continue if _visited.size() < 18: if _visited.has(door[2]): continue if _panel_boundary.size() == 1 and door[2] == "achievement": continue if _door_mapping.size() == 16 and door[2] == "achievement" and !_visited.has("achievement"): filtered = [door] break filtered.append(door) var chosen_door = _pickRandom(filtered, rng) _door_mapping[chosen_door[1]] = _panel_boundary.pop_front() enterRoom(chosen_door[2]) _flood_boundary.erase(chosen_door) func enterRoom(room): if _visited.has(room): return _visited.append(room) if room == "achievement": return _panel_boundary.append(layout[room][0]) for door in layout[room][1]: if door[0] == "": enterRoom(door[1]) else: _flood_boundary.append([room, door[0], door[1]]) func _pickRandom(set, rng): var id = rng.randi_range(0, set.size() - 1) return set[id]