diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-04-16 23:40:39 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-04-16 23:40:39 -0400 |
commit | c6770ac83c49f4adb7e2c2a6ee6290f0487a3873 (patch) | |
tree | 0b3b52f31ba5663d33aa7cef02d1621d9dceeb5b /Archipelago | |
parent | 7aa62e5c0ac0d86e5aed2ead2a7116ea0edbffde (diff) | |
download | lingo-archipelago-c6770ac83c49f4adb7e2c2a6ee6290f0487a3873.tar.gz lingo-archipelago-c6770ac83c49f4adb7e2c2a6ee6290f0487a3873.tar.bz2 lingo-archipelago-c6770ac83c49f4adb7e2c2a6ee6290f0487a3873.zip |
Implemented panel shuffle
Diffstat (limited to 'Archipelago')
-rw-r--r-- | Archipelago/client.gd | 12 | ||||
-rw-r--r-- | Archipelago/load.gd | 57 |
2 files changed, 68 insertions, 1 deletions
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 = [ | |||
10 | "White", "Black", "Red", "Blue", "Green", "Brown", "Gray", "Orange", "Purple", "Yellow" | 10 | "White", "Black", "Red", "Blue", "Green", "Brown", "Gray", "Orange", "Purple", "Yellow" |
11 | ] | 11 | ] |
12 | 12 | ||
13 | const kTHE_END = 0 | ||
14 | const kTHE_MASTER = 1 | ||
15 | |||
16 | const kNO_PANEL_SHUFFLE = 0 | ||
17 | const kREARRANGE_PANELS = 1 | ||
18 | |||
13 | var _client = WebSocketClient.new() | 19 | var _client = WebSocketClient.new() |
14 | var _last_state = WebSocketPeer.STATE_CLOSED | 20 | var _last_state = WebSocketPeer.STATE_CLOSED |
15 | var _should_process = false | 21 | var _should_process = false |
@@ -41,6 +47,8 @@ var _death_link = false | |||
41 | var _victory_condition = 0 # THE END, THE MASTER | 47 | var _victory_condition = 0 # THE END, THE MASTER |
42 | var _door_shuffle = false | 48 | var _door_shuffle = false |
43 | var _color_shuffle = false | 49 | var _color_shuffle = false |
50 | var _panel_shuffle = 0 # none, rearrange | ||
51 | var _slot_seed = 0 | ||
44 | 52 | ||
45 | var _map_loaded = false | 53 | var _map_loaded = false |
46 | var _held_items = [] | 54 | var _held_items = [] |
@@ -165,6 +173,10 @@ func _on_data(): | |||
165 | _color_shuffle = _slot_data["shuffle_colors"] | 173 | _color_shuffle = _slot_data["shuffle_colors"] |
166 | if _slot_data.has("shuffle_doors"): | 174 | if _slot_data.has("shuffle_doors"): |
167 | _door_shuffle = (_slot_data["shuffle_doors"] > 0) | 175 | _door_shuffle = (_slot_data["shuffle_doors"] > 0) |
176 | if _slot_data.has("shuffle_panels"): | ||
177 | _panel_shuffle = _slot_data["shuffle_panels"] | ||
178 | if _slot_data.has("seed"): | ||
179 | _slot_seed = _slot_data["seed"] | ||
168 | 180 | ||
169 | _localdata_file = "user://archipelago/%s_%d" % [_seed, _slot] | 181 | _localdata_file = "user://archipelago/%s_%d" % [_seed, _slot] |
170 | var ap_file = File.new() | 182 | 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(): | |||
38 | "answer_correct", location, "handle_correct" | 38 | "answer_correct", location, "handle_correct" |
39 | ) | 39 | ) |
40 | 40 | ||
41 | # Randomize the panels, if necessary. | ||
42 | var rng = RandomNumberGenerator.new() | ||
43 | rng.seed = apclient._slot_seed | ||
44 | |||
45 | var gamedata = apclient.get_node("Gamedata") | ||
46 | if apclient._panel_shuffle == apclient.kREARRANGE_PANELS: | ||
47 | var panel_pools = {} | ||
48 | for panel in gamedata.panels: | ||
49 | if not panel_pools.has(panel["tag"]): | ||
50 | panel_pools[panel["tag"]] = {} | ||
51 | var pool = panel_pools[panel["tag"]] | ||
52 | var subtag = "default" | ||
53 | if panel.has("subtag"): | ||
54 | subtag = panel["subtag"] | ||
55 | if not pool.has(subtag): | ||
56 | pool[subtag] = [] | ||
57 | |||
58 | var panel_node = panels_parent.get_node(panel["id"]) | ||
59 | pool[subtag].append( | ||
60 | { | ||
61 | "id": panel["id"], | ||
62 | "hint": panel_node.text, | ||
63 | "answer": panel_node.answer, | ||
64 | "link": panel["link"] | ||
65 | } | ||
66 | ) | ||
67 | |||
68 | for tag in panel_pools.keys(): | ||
69 | if tag == "forbid": | ||
70 | continue | ||
71 | |||
72 | var pool = panel_pools[tag] | ||
73 | for subtag in pool.keys(): | ||
74 | pool[subtag].sort_custom(self, "sort_by_link") | ||
75 | |||
76 | var count = pool[pool.keys()[0]].size() | ||
77 | var iota = range(0, count) | ||
78 | var order = [] | ||
79 | while not iota.empty(): | ||
80 | var i = rng.randi_range(0, iota.size() - 1) | ||
81 | order.append(iota[i]) | ||
82 | iota.remove(i) | ||
83 | |||
84 | for subtag in pool.keys(): | ||
85 | for i in range(0, count): | ||
86 | var source = pool[subtag][i] | ||
87 | var target = pool[subtag][order[i]] | ||
88 | var target_panel_node = panels_parent.get_node(target["id"]) | ||
89 | |||
90 | target_panel_node.text = source["hint"] | ||
91 | target_panel_node.answer = source["answer"] | ||
92 | |||
41 | # Attach a script to every panel so that we can do things like conditionally | 93 | # Attach a script to every panel so that we can do things like conditionally |
42 | # disable them. | 94 | # disable them. |
43 | var gamedata = apclient.get_node("Gamedata") | ||
44 | var panel_script = ResourceLoader.load("user://maps/Archipelago/panel.gd") | 95 | var panel_script = ResourceLoader.load("user://maps/Archipelago/panel.gd") |
45 | for panel in gamedata.panels: | 96 | for panel in gamedata.panels: |
46 | var panel_node = panels_parent.get_node(panel["id"]) | 97 | var panel_node = panels_parent.get_node(panel["id"]) |
@@ -75,3 +126,7 @@ func _load(): | |||
75 | # Process any items received while the map was loading, and send the checks | 126 | # Process any items received while the map was loading, and send the checks |
76 | # from the save load. | 127 | # from the save load. |
77 | apclient.mapFinishedLoading() | 128 | apclient.mapFinishedLoading() |
129 | |||
130 | |||
131 | func sort_by_link(a, b): | ||
132 | return a["link"] < b["link"] | ||