From 437438ad6aed07a2c1d149a72759f7f2a3277ea6 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 12 Apr 2023 16:22:38 -0400 Subject: Created global client object --- Archipelago/client.gd | 44 +++++++++++++++++++++++++++++++++++++++++ Archipelago/settings_buttons.gd | 24 +++++----------------- Archipelago/settings_screen.gd | 22 ++++++++++----------- 3 files changed, 59 insertions(+), 31 deletions(-) create mode 100644 Archipelago/client.gd (limited to 'Archipelago') diff --git a/Archipelago/client.gd b/Archipelago/client.gd new file mode 100644 index 0000000..1d2affd --- /dev/null +++ b/Archipelago/client.gd @@ -0,0 +1,44 @@ +extends Node + +var ap_server = "" +var ap_user = "" +var ap_pass = "" + + +func _init(): + global._print("Instantiated APClient") + + # Read AP settings from file, if there are any + var file = File.new() + if file.file_exists("user://settings/archipelago"): + file.open("user://settings/archipelago", File.READ) + var data = file.get_var(true) + file.close() + + if data.size() > 0: + ap_server = data[0] + if data.size() > 1: + ap_user = data[1] + if data.size() > 2: + ap_pass = data[2] + + +func _ready(): + pass + + +func saveSettings(): + # Save the AP settings to disk. + var dir = Directory.new() + var path = "user://settings" + if dir.dir_exists(path): + pass + else: + dir.make_dir(path) + + var file = File.new() + file.open("user://settings/archipelago", File.WRITE) + + var data = [ap_server, ap_user, ap_pass] + file.store_var(data, true) + file.close() diff --git a/Archipelago/settings_buttons.gd b/Archipelago/settings_buttons.gd index 5b4d837..1ab3788 100644 --- a/Archipelago/settings_buttons.gd +++ b/Archipelago/settings_buttons.gd @@ -6,25 +6,11 @@ func _ready(): func _connect_pressed(): - # Save the AP settings to disk. - var dir = Directory.new() - var path = "user://settings" - if dir.dir_exists(path): - pass - else: - dir.make_dir(path) - - var file = File.new() - file.open("user://settings/archipelago", File.WRITE) - - var data = [ - self.get_parent().get_node("server_box").text, - self.get_parent().get_node("player_box").text, - self.get_parent().get_node("password_box").text - ] - - file.store_var(data, true) - file.close() + var apclient = global.get_node("Archipelago") + apclient.ap_server = self.get_parent().get_node("server_box").text + apclient.ap_user = self.get_parent().get_node("player_box").text + apclient.ap_pass = self.get_parent().get_node("password_box").text + apclient.saveSettings() func _back_pressed(): diff --git a/Archipelago/settings_screen.gd b/Archipelago/settings_screen.gd index 91f233d..3740751 100644 --- a/Archipelago/settings_screen.gd +++ b/Archipelago/settings_screen.gd @@ -6,16 +6,14 @@ func _ready(): get_tree().get_root().set_disable_input(false) Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) - # Read AP settings from file, if there are any - var file = File.new() - if file.file_exists("user://settings/archipelago"): - file.open("user://settings/archipelago", File.READ) - var data = file.get_var(true) - file.close() + # Create the global AP client, if it doesn't already exist. + if not global.has_node("Archipelago"): + var apclient = ResourceLoader.load("user://maps/Archipelago/client.gd") + var apclient_instance = apclient.new() + apclient_instance.name = "Archipelago" + global.add_child(apclient_instance) - if data.size() > 0: - self.get_node("Panel/server_box").text = data[0] - if data.size() > 1: - self.get_node("Panel/player_box").text = data[1] - if data.size() > 2: - self.get_node("Panel/password_box").text = data[2] + # Populate textboxes with AP settings. + self.get_node("Panel/server_box").text = global.get_node("Archipelago").ap_server + self.get_node("Panel/player_box").text = global.get_node("Archipelago").ap_user + self.get_node("Panel/password_box").text = global.get_node("Archipelago").ap_pass -- cgit 1.4.1