From 38175bd12c1a0a2c80be5f4011f69e4659f61ccd Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 3 Apr 2024 14:31:51 -0400 Subject: Added player position tracking --- Archipelago/client.gd | 18 +++++++++++++++++- Archipelago/player.gd | 28 ++++++++++++++++++++++++++++ Archipelago/settings_buttons.gd | 1 + Archipelago/settings_screen.gd | 1 + 4 files changed, 47 insertions(+), 1 deletion(-) (limited to 'Archipelago') diff --git a/Archipelago/client.gd b/Archipelago/client.gd index 47357ee..b825aaa 100644 --- a/Archipelago/client.gd +++ b/Archipelago/client.gd @@ -14,6 +14,7 @@ var ap_user = "" var ap_pass = "" var confusify_world = false var enable_multiplayer = false +var track_player = false const my_version = "2.0.0" const ap_version = {"major": 0, "minor": 4, "build": 5, "class": "Version"} @@ -158,6 +159,8 @@ func _init(): confusify_world = data[4] if data.size() > 5: enable_multiplayer = data[5] + if data.size() > 6: + track_player = data[6] processDatapackages() @@ -298,6 +301,11 @@ func _on_data(): if _slot_data.has("early_color_hallways"): _early_color_hallways = _slot_data["early_color_hallways"] + if track_player: + setValue("PlayerPos", {"x": 0, "z": 0}) + else: + setValue("PlayerPos", null) + _puzzle_skips = 0 _localdata_file = "user://archipelago_data/%s_%d" % [_seed, _slot] @@ -470,7 +478,15 @@ func saveSettings(): var file = File.new() file.open("user://settings/archipelago", File.WRITE) - var data = [ap_server, ap_user, ap_pass, _datapackages, confusify_world, enable_multiplayer] + var data = [ + ap_server, + ap_user, + ap_pass, + _datapackages, + confusify_world, + enable_multiplayer, + track_player + ] file.store_var(data, true) file.close() diff --git a/Archipelago/player.gd b/Archipelago/player.gd index 87d9d0c..49d907d 100644 --- a/Archipelago/player.gd +++ b/Archipelago/player.gd @@ -1,6 +1,34 @@ extends "res://scripts/player.gd" +var _oldpos = Vector3(0, -200, 0) + + +func _ready(): + _oldpos = translation + _oldpos.y = 0 + + var apclient = global.get_node("Archipelago") + if apclient.track_player: + var tracking_timer = Timer.new() + tracking_timer.name = "TrackingTimer" + tracking_timer.wait_time = 5.0 + add_child(tracking_timer) + tracking_timer.connect("timeout", self, "_tick_tracking") + tracking_timer.start() + + +func _tick_tracking(): + var newpos = translation + newpos.y = 0 + + if newpos != _oldpos && newpos.distance_to(_oldpos) > 10: + _oldpos = newpos + + var apclient = global.get_node("Archipelago") + apclient.setValue("PlayerPos", {"x": int(_oldpos.x), "z": int(_oldpos.z)}) + + func _solving(): ._solving() diff --git a/Archipelago/settings_buttons.gd b/Archipelago/settings_buttons.gd index e9cff9d..9193b61 100644 --- a/Archipelago/settings_buttons.gd +++ b/Archipelago/settings_buttons.gd @@ -14,6 +14,7 @@ func _connect_pressed(): apclient.ap_pass = self.get_parent().get_node("password_box").text apclient.confusify_world = self.get_parent().get_node("confusing_box").pressed apclient.enable_multiplayer = self.get_parent().get_node("multiplayer_box").pressed + apclient.track_player = self.get_parent().get_node("position_box").pressed apclient.saveSettings() apclient.connectToServer() diff --git a/Archipelago/settings_screen.gd b/Archipelago/settings_screen.gd index 7f50f51..deb0003 100644 --- a/Archipelago/settings_screen.gd +++ b/Archipelago/settings_screen.gd @@ -59,6 +59,7 @@ func _ready(): self.get_node("Panel/password_box").text = apclient.ap_pass self.get_node("Panel/confusing_box").pressed = apclient.confusify_world self.get_node("Panel/multiplayer_box").pressed = apclient.enable_multiplayer + self.get_node("Panel/position_box").pressed = apclient.track_player # Show client version. self.get_node("Panel/title").text = "ARCHIPELAGO (%s)" % apclient.my_version -- cgit 1.4.1