From 380a2b49eb2c2687a6fda1099d8b9d1be92c0e32 Mon Sep 17 00:00:00 2001
From: Star Rauchenberger <fefferburbia@gmail.com>
Date: Thu, 13 Apr 2023 21:23:41 -0400
Subject: Location checks are held while the map is loading

The map load sends out a lot of checks at once if a file is being loaded, so we hold them until the map finishes loading and then send them out together.
---
 Archipelago/client.gd | 18 +++++++++++++++---
 Archipelago/load.gd   |  7 ++++---
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/Archipelago/client.gd b/Archipelago/client.gd
index cbddf89..0f121a1 100644
--- a/Archipelago/client.gd
+++ b/Archipelago/client.gd
@@ -31,6 +31,7 @@ var _panel_ids_by_location = {}
 
 var _map_loaded = false
 var _held_items = []
+var _held_locations = []
 
 signal client_connected
 
@@ -130,6 +131,8 @@ func _on_data():
 			if _slot_data.has("panel_ids_by_location_id"):
 				_panel_ids_by_location = _slot_data["panel_ids_by_location_id"]
 
+			requestSync()
+
 			emit_signal("client_connected")
 
 		elif cmd == "ConnectionRefused":
@@ -205,18 +208,27 @@ func connectToRoom():
 	)
 
 
+func requestSync():
+	sendMessage([{"cmd": "Sync"}])
+
+
 func sendLocation(loc_id):
-	sendMessage([{"cmd": "LocationChecks", "locations": [loc_id]}])
+	if _map_loaded:
+		sendMessage([{"cmd": "LocationChecks", "locations": [loc_id]}])
+	else:
+		_held_locations.append(loc_id)
 
 
 func mapFinishedLoading():
 	if !_map_loaded:
-		_map_loaded = true
-
 		for item in _held_items:
 			processItem(item)
 
+		sendMessage([{"cmd": "LocationChecks", "locations": _held_locations}])
+
+		_map_loaded = true
 		_held_items = []
+		_held_locations = []
 
 
 func processItem(item):
diff --git a/Archipelago/load.gd b/Archipelago/load.gd
index b0ccafc..cb592ff 100644
--- a/Archipelago/load.gd
+++ b/Archipelago/load.gd
@@ -28,9 +28,10 @@ func _load():
 				"answer_correct", location, "handle_correct"
 			)
 
-	# Process any items received while the map was loading.
-	apclient.mapFinishedLoading()
-
 	# Proceed with the rest of the load.
 	global._print("Hooked Load End")
 	._load()
+
+	# Process any items received while the map was loading, and send the checks
+	# from the save load.
+	apclient.mapFinishedLoading()
-- 
cgit 1.4.1