From f834267a75c873d143e1f7f56f73faaa5e15cf2f Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 9 Dec 2024 12:50:24 -0500 Subject: First pass at panel randomization --- Archipelago/settings_screen.gd | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'Archipelago/settings_screen.gd') diff --git a/Archipelago/settings_screen.gd b/Archipelago/settings_screen.gd index 6c64b15..956d966 100644 --- a/Archipelago/settings_screen.gd +++ b/Archipelago/settings_screen.gd @@ -1,5 +1,10 @@ extends Spatial +var generator_thread = Thread.new() +var generator + +signal finished_randomizing + func _ready(): # Some helpful logging. @@ -25,6 +30,7 @@ func _ready(): apclient_instance.SCRIPT_doorControl = load("user://maps/Archipelago/doorControl.gd") apclient_instance.SCRIPT_effects = load("user://maps/Archipelago/effects.gd") + apclient_instance.SCRIPT_generator = load("user://maps/Archipelago/generator.gd") apclient_instance.SCRIPT_location = load("user://maps/Archipelago/location.gd") apclient_instance.SCRIPT_multiplayer = load("user://maps/Archipelago/multiplayer.gd") apclient_instance.SCRIPT_mypainting = load("user://maps/Archipelago/mypainting.gd") @@ -123,6 +129,16 @@ func installScriptExtension(childScript: Resource): childScript.take_over_path(parentScriptPath) +func getVariantFromFile(path): + var cbin = File.new() + var err = cbin.open_compressed( + "%s\\%s" % [filename.get_base_dir(), path], File.READ, File.COMPRESSION_ZSTD + ) + if err != OK: + global._print("Error: %d" % err) + return cbin.get_var() + + func connectionStatus(message): var popup = self.get_node("Panel/AcceptDialog") popup.window_title = "Connecting to Archipelago" @@ -135,6 +151,36 @@ func connectionStatus(message): func connectionSuccessful(): var apclient = global.get_node("Archipelago") + if apclient._panel_shuffle == apclient.kEXPERIMENTAL_PANELS: + #connect("finished_randomizing", self, "loadLevel") + + #generator_thread.start(self, "doGeneration", null, Thread.PRIORITY_HIGH) + #yield(self, "finished_randomizing") + #generator_thread.wait_to_finish() + doGeneration() + + loadLevel() + else: + loadLevel() + + +func doGeneration(): + var apclient = global.get_node("Archipelago") + var gpv = getVariantFromFile("generated_puzzles.bin") + global._print("Forms: %d" % gpv[0].size()) + generator = apclient.SCRIPT_generator.new(gpv) + generator.name = "Generator" + apclient.add_child(generator) + + generator.connect("generator_status", self, "connectionStatus") + generator.generate(str(apclient._slot_seed)) + + emit_signal("finished_randomizing") + + +func loadLevel(): + var apclient = global.get_node("Archipelago") + # Save connection details var connection_details = [apclient.ap_server, apclient.ap_user, apclient.ap_pass] if apclient.connection_history.has(connection_details): -- cgit 1.4.1