Updating character location based on occupied tile
Deploy Promiscuity Auth API / deploy (push) Successful in 45s
Deploy Promiscuity Character API / deploy (push) Successful in 57s
Deploy Promiscuity Locations API / deploy (push) Successful in 44s
k8s smoke test / test (push) Successful in 7s

This commit is contained in:
2026-03-13 21:34:59 -05:00
parent 6ca0f306bb
commit e79f473ce4
8 changed files with 122 additions and 14 deletions
+48 -5
View File
@@ -25,6 +25,10 @@ var _camera_start_offset := Vector3(0.0, 6.0, 10.0)
var _border_material: StandardMaterial3D
var _known_locations: Dictionary = {}
var _locations_loaded := false
var _character_id := ""
var _persisted_coord := Vector2i.ZERO
var _coord_sync_in_flight := false
var _queued_coord_sync: Variant = null
func _ready() -> void:
@@ -41,6 +45,8 @@ func _ready() -> void:
var start_coord := SelectedCharacter.get_coord()
_center_coord = Vector2i(roundi(start_coord.x), roundi(start_coord.y))
_persisted_coord = _center_coord
_character_id = String(SelectedCharacter.character.get("id", SelectedCharacter.character.get("Id", ""))).strip_edges()
_block.visible = false
await _load_existing_locations()
@@ -58,6 +64,7 @@ func _process(_delta: float) -> void:
return
_center_coord = target_coord
_rebuild_tiles(_center_coord)
_queue_coord_sync(_center_coord)
func _get_stream_position() -> Vector3:
@@ -204,8 +211,7 @@ func _load_existing_locations() -> void:
_locations_loaded = false
_known_locations.clear()
var character_id := String(SelectedCharacter.character.get("id", SelectedCharacter.character.get("Id", ""))).strip_edges()
if character_id.is_empty():
if _character_id.is_empty():
push_warning("Selected character is missing an id; cannot load visible locations.")
_locations_loaded = true
return
@@ -217,7 +223,7 @@ func _load_existing_locations() -> void:
if not AuthState.access_token.is_empty():
headers.append("Authorization: Bearer %s" % AuthState.access_token)
var err := request.request("%s/%s/visible-locations" % [CHARACTER_API_URL, character_id], headers, HTTPClient.METHOD_GET)
var err := request.request("%s/%s/visible-locations" % [CHARACTER_API_URL, _character_id], headers, HTTPClient.METHOD_GET)
if err != OK:
push_warning("Failed to request visible locations: %s" % err)
request.queue_free()
@@ -257,8 +263,45 @@ func _load_existing_locations() -> void:
_known_locations[coord] = location_name
loaded_count += 1
print("LocationLevel loaded %d visible locations for character %s." % [loaded_count, character_id])
print("LocationLevel loaded %d visible locations for character %s." % [loaded_count, _character_id])
if loaded_count == 0:
push_warning("Visible locations request succeeded but returned 0 locations for character %s." % character_id)
push_warning("Visible locations request succeeded but returned 0 locations for character %s." % _character_id)
_locations_loaded = true
func _queue_coord_sync(coord: Vector2i) -> void:
if coord == _persisted_coord:
return
if _coord_sync_in_flight:
_queued_coord_sync = coord
return
_sync_character_coord(coord)
func _sync_character_coord(coord: Vector2i) -> void:
if _character_id.is_empty():
return
_coord_sync_in_flight = true
_queued_coord_sync = null
_sync_character_coord_async(coord)
func _sync_character_coord_async(coord: Vector2i) -> void:
var response := await CharacterService.update_character_coord(_character_id, coord)
if response.get("ok", false):
_persisted_coord = coord
SelectedCharacter.set_coord(coord)
else:
push_warning("Failed to persist character coord to %s,%s: status=%s error=%s body=%s" % [
coord.x,
coord.y,
response.get("status", "n/a"),
response.get("error", ""),
response.get("body", "")
])
_coord_sync_in_flight = false
if _queued_coord_sync != null and _queued_coord_sync is Vector2i and _queued_coord_sync != _persisted_coord:
var queued_coord: Vector2i = _queued_coord_sync
_sync_character_coord(queued_coord)
+13 -3
View File
@@ -11,9 +11,19 @@ func create_character(character_name: String) -> Dictionary:
})
return await _request(HTTPClient.METHOD_POST, CHARACTER_API_URL, payload)
func delete_character(character_id: String) -> Dictionary:
var url := "%s/%s" % [CHARACTER_API_URL, character_id]
return await _request(HTTPClient.METHOD_DELETE, url)
func delete_character(character_id: String) -> Dictionary:
var url := "%s/%s" % [CHARACTER_API_URL, character_id]
return await _request(HTTPClient.METHOD_DELETE, url)
func update_character_coord(character_id: String, coord: Vector2i) -> Dictionary:
var url := "%s/%s/coord" % [CHARACTER_API_URL, character_id]
var payload := JSON.stringify({
"coord": {
"x": coord.x,
"y": coord.y
}
})
return await _request(HTTPClient.METHOD_PUT, url, payload)
func _request(method: int, url: String, body: String = "") -> Dictionary:
var request := HTTPRequest.new()
+6
View File
@@ -14,3 +14,9 @@ func get_coord() -> Vector2:
float(coord.get("x", 0)),
float(coord.get("y", 0))
)
func set_coord(coord: Vector2i) -> void:
character["coord"] = {
"x": coord.x,
"y": coord.y
}