From 1bdfb112b659a6e4447ae8ed02c452bf12d8700a Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 17 Dec 2024 16:01:19 -0500 Subject: Add position tracking via IPC --- Archipelago/player.gd | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'Archipelago/player.gd') diff --git a/Archipelago/player.gd b/Archipelago/player.gd index 52d743a..6638329 100644 --- a/Archipelago/player.gd +++ b/Archipelago/player.gd @@ -2,12 +2,16 @@ extends "res://scripts/player.gd" var _oldpos = Vector3(0, -200, 0) +var _oldpos_fine = Vector3(0, -200, 0) func _ready(): _oldpos = translation _oldpos.y = 0 + _oldpos_fine = translation + _oldpos_fine.y = 0 + var apclient = global.get_node("Archipelago") if apclient.track_player: var tracking_timer = Timer.new() @@ -17,8 +21,19 @@ func _ready(): tracking_timer.connect("timeout", self, "_tick_tracking") tracking_timer.start() + var tracking_timer_fine = Timer.new() + tracking_timer_fine.name = "TrackingTimerFine" + tracking_timer_fine.wait_time = 0.5 + add_child(tracking_timer_fine) + tracking_timer_fine.connect("timeout", self, "_tick_tracking_fine") + tracking_timer_fine.start() + func _tick_tracking(): + var tracker = get_tree().get_root().get_node("Spatial/AP_Tracker") + if tracker.has_connection(): + return + var newpos = translation newpos.y = 0 @@ -29,6 +44,20 @@ func _tick_tracking(): apclient.setValue("PlayerPos", {"x": int(_oldpos.x), "z": int(_oldpos.z)}) +func _tick_tracking_fine(): + var tracker = get_tree().get_root().get_node("Spatial/AP_Tracker") + if !tracker.has_connection(): + return + + var newpos = translation + newpos.y = 0 + + if newpos != _oldpos_fine && newpos.distance_to(_oldpos_fine) > 0.5: + _oldpos_fine = newpos + + tracker.update_position(int(_oldpos_fine.x), int(_oldpos_fine.z)) + + func _solving(): ._solving() -- cgit 1.4.1