From c6770ac83c49f4adb7e2c2a6ee6290f0487a3873 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 16 Apr 2023 23:40:39 -0400 Subject: Implemented panel shuffle --- Archipelago/client.gd | 12 +++++++++++ Archipelago/load.gd | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) (limited to 'Archipelago') diff --git a/Archipelago/client.gd b/Archipelago/client.gd index 8f20d0a..c5f1488 100644 --- a/Archipelago/client.gd +++ b/Archipelago/client.gd @@ -10,6 +10,12 @@ const color_items = [ "White", "Black", "Red", "Blue", "Green", "Brown", "Gray", "Orange", "Purple", "Yellow" ] +const kTHE_END = 0 +const kTHE_MASTER = 1 + +const kNO_PANEL_SHUFFLE = 0 +const kREARRANGE_PANELS = 1 + var _client = WebSocketClient.new() var _last_state = WebSocketPeer.STATE_CLOSED var _should_process = false @@ -41,6 +47,8 @@ var _death_link = false var _victory_condition = 0 # THE END, THE MASTER var _door_shuffle = false var _color_shuffle = false +var _panel_shuffle = 0 # none, rearrange +var _slot_seed = 0 var _map_loaded = false var _held_items = [] @@ -165,6 +173,10 @@ func _on_data(): _color_shuffle = _slot_data["shuffle_colors"] if _slot_data.has("shuffle_doors"): _door_shuffle = (_slot_data["shuffle_doors"] > 0) + if _slot_data.has("shuffle_panels"): + _panel_shuffle = _slot_data["shuffle_panels"] + if _slot_data.has("seed"): + _slot_seed = _slot_data["seed"] _localdata_file = "user://archipelago/%s_%d" % [_seed, _slot] var ap_file = File.new() diff --git a/Archipelago/load.gd b/Archipelago/load.gd index f9dc65f..47f51a6 100644 --- a/Archipelago/load.gd +++ b/Archipelago/load.gd @@ -38,9 +38,60 @@ func _load(): "answer_correct", location, "handle_correct" ) + # Randomize the panels, if necessary. + var rng = RandomNumberGenerator.new() + rng.seed = apclient._slot_seed + + var gamedata = apclient.get_node("Gamedata") + if apclient._panel_shuffle == apclient.kREARRANGE_PANELS: + var panel_pools = {} + for panel in gamedata.panels: + if not panel_pools.has(panel["tag"]): + panel_pools[panel["tag"]] = {} + var pool = panel_pools[panel["tag"]] + var subtag = "default" + if panel.has("subtag"): + subtag = panel["subtag"] + if not pool.has(subtag): + pool[subtag] = [] + + var panel_node = panels_parent.get_node(panel["id"]) + pool[subtag].append( + { + "id": panel["id"], + "hint": panel_node.text, + "answer": panel_node.answer, + "link": panel["link"] + } + ) + + for tag in panel_pools.keys(): + if tag == "forbid": + continue + + var pool = panel_pools[tag] + for subtag in pool.keys(): + pool[subtag].sort_custom(self, "sort_by_link") + + var count = pool[pool.keys()[0]].size() + var iota = range(0, count) + var order = [] + while not iota.empty(): + var i = rng.randi_range(0, iota.size() - 1) + order.append(iota[i]) + iota.remove(i) + + for subtag in pool.keys(): + for i in range(0, count): + var source = pool[subtag][i] + var target = pool[subtag][order[i]] + var target_panel_node = panels_parent.get_node(target["id"]) + + target_panel_node.text = source["hint"] + target_panel_node.answer = source["answer"] + # Attach a script to every panel so that we can do things like conditionally # disable them. - var gamedata = apclient.get_node("Gamedata") var panel_script = ResourceLoader.load("user://maps/Archipelago/panel.gd") for panel in gamedata.panels: var panel_node = panels_parent.get_node(panel["id"]) @@ -75,3 +126,7 @@ func _load(): # Process any items received while the map was loading, and send the checks # from the save load. apclient.mapFinishedLoading() + + +func sort_by_link(a, b): + return a["link"] < b["link"] -- cgit 1.4.1