about summary refs log tree commit diff stats
path: root/Archipelago/load.gd
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-04-16 23:40:39 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-04-16 23:40:39 -0400
commitc6770ac83c49f4adb7e2c2a6ee6290f0487a3873 (patch)
tree0b3b52f31ba5663d33aa7cef02d1621d9dceeb5b /Archipelago/load.gd
parent7aa62e5c0ac0d86e5aed2ead2a7116ea0edbffde (diff)
downloadlingo-archipelago-c6770ac83c49f4adb7e2c2a6ee6290f0487a3873.tar.gz
lingo-archipelago-c6770ac83c49f4adb7e2c2a6ee6290f0487a3873.tar.bz2
lingo-archipelago-c6770ac83c49f4adb7e2c2a6ee6290f0487a3873.zip
Implemented panel shuffle
Diffstat (limited to 'Archipelago/load.gd')
-rw-r--r--Archipelago/load.gd57
1 files changed, 56 insertions, 1 deletions
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
131func sort_by_link(a, b):
132 return a["link"] < b["link"]