Adding Kenney UI and item management
Deploy Promiscuity Auth API / deploy (push) Successful in 48s
Deploy Promiscuity Character API / deploy (push) Successful in 47s
Deploy Promiscuity Inventory API / deploy (push) Successful in 59s
Deploy Promiscuity Locations API / deploy (push) Successful in 46s
k8s smoke test / test (push) Successful in 10s

This commit is contained in:
2026-03-20 13:11:47 -05:00
parent 038981d7b1
commit 525f9442c3
2631 changed files with 58336 additions and 142 deletions
+451 -8
View File
@@ -1,8 +1,11 @@
extends Node3D
extends Node3D
const CHARACTER_API_URL := "https://pchar.ranaze.com/api/Characters"
const LOCATION_API_URL := "https://ploc.ranaze.com/api/Locations"
const INVENTORY_API_URL := "https://pinv.ranaze.com/api/inventory"
const START_SCREEN_SCENE := "res://scenes/UI/start_screen.tscn"
const SETTINGS_SCENE := "res://scenes/UI/Settings.tscn"
const CHARACTER_SLOT_COUNT := 6
@export var tile_size := 8.0
@export var block_height := 1.0
@@ -19,8 +22,16 @@ const INVENTORY_API_URL := "https://pinv.ranaze.com/api/inventory"
@onready var _player: RigidBody3D = $Player
@onready var _camera: Camera3D = $Player/Camera3D
@onready var _player_visual: Node3D = $Player/TestCharAnimated
var _center_coord := Vector2i.ZERO
@onready var _pause_menu: CanvasLayer = $PauseMenu
@onready var _inventory_menu: CanvasLayer = $InventoryMenu
@onready var _inventory_location_label: Label = $InventoryMenu/MarginContainer/Panel/VBoxContainer/CurrentLocationLabel
@onready var _character_items_list: ItemList = $InventoryMenu/MarginContainer/Panel/VBoxContainer/Columns/CharacterPanel/VBoxContainer/CharacterItems
@onready var _ground_items_list: ItemList = $InventoryMenu/MarginContainer/Panel/VBoxContainer/Columns/GroundPanel/VBoxContainer/GroundItems
@onready var _target_slot_spin_box: SpinBox = $InventoryMenu/MarginContainer/Panel/VBoxContainer/ControlsPanel/VBoxContainer/ControlsRow/TargetSlotSpinBox
@onready var _quantity_spin_box: SpinBox = $InventoryMenu/MarginContainer/Panel/VBoxContainer/ControlsPanel/VBoxContainer/ControlsRow/QuantitySpinBox
@onready var _inventory_status_label: Label = $InventoryMenu/MarginContainer/Panel/VBoxContainer/ControlsPanel/VBoxContainer/StatusLabel
var _center_coord := Vector2i.ZERO
var _tiles_root: Node3D
var _tracked_node: Node3D
var _tile_nodes: Dictionary = {}
@@ -36,6 +47,10 @@ var _queued_coord_sync: Variant = null
var _locations_refresh_in_flight := false
var _queued_locations_refresh := false
var _interact_in_flight := false
var _inventory_request_in_flight := false
var _character_inventory_items: Array = []
var _selected_character_item_id := ""
var _selected_ground_item_id := ""
func _ready() -> void:
@@ -64,10 +79,12 @@ func _ready() -> void:
_activate_player_after_load()
func _process(_delta: float) -> void:
if not _locations_loaded:
return
var target_world_pos := _get_stream_position()
func _process(_delta: float) -> void:
if not _locations_loaded:
return
if _inventory_menu.visible:
return
var target_world_pos := _get_stream_position()
var target_coord := _world_to_coord(target_world_pos)
if target_coord == _center_coord:
return
@@ -76,8 +93,26 @@ func _process(_delta: float) -> void:
_queue_locations_refresh()
func _input(event: InputEvent) -> void:
if event.is_action_pressed("player_phone"):
if get_tree().paused:
return
_toggle_inventory_menu()
get_viewport().set_input_as_handled()
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("ui_cancel") and _inventory_menu.visible:
_close_inventory_menu()
get_viewport().set_input_as_handled()
return
if event.is_action_pressed("ui_cancel"):
_toggle_pause_menu()
get_viewport().set_input_as_handled()
return
if event.is_action_pressed("interact"):
if get_tree().paused or _inventory_menu.visible:
return
_try_interact_current_tile()
@@ -126,6 +161,88 @@ func _activate_player_after_load() -> void:
_player.freeze = false
if _player_visual:
_player_visual.visible = true
func _toggle_pause_menu() -> void:
if _pause_menu == null:
return
if get_tree().paused:
_resume_game()
else:
_pause_game()
func _pause_game() -> void:
if _inventory_menu.visible:
_close_inventory_menu()
get_tree().paused = true
_pause_menu.visible = true
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
func _resume_game() -> void:
get_tree().paused = false
_pause_menu.visible = false
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED if not _inventory_menu.visible else Input.MOUSE_MODE_VISIBLE)
func _toggle_inventory_menu() -> void:
if _inventory_menu.visible:
_close_inventory_menu()
return
_open_inventory_menu()
func _open_inventory_menu() -> void:
if _character_id.is_empty():
return
_inventory_menu.visible = true
_inventory_status_label.text = "Loading inventory..."
_set_player_menu_lock(true)
_update_inventory_location_label()
_refresh_inventory_menu_data()
func _close_inventory_menu() -> void:
_inventory_menu.visible = false
_inventory_status_label.text = ""
_selected_character_item_id = ""
_selected_ground_item_id = ""
_character_items_list.deselect_all()
_ground_items_list.deselect_all()
_set_player_menu_lock(false)
func _set_player_menu_lock(locked: bool) -> void:
if _player == null:
return
if locked:
_player.freeze = true
_player.sleeping = true
_player.linear_velocity = Vector3.ZERO
_player.angular_velocity = Vector3.ZERO
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
return
_player.sleeping = false
_player.freeze = false
if not get_tree().paused:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _on_pause_continue_pressed() -> void:
_resume_game()
func _on_pause_settings_pressed() -> void:
_resume_game()
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
get_tree().change_scene_to_file(SETTINGS_SCENE)
func _on_pause_main_menu_pressed() -> void:
_resume_game()
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
get_tree().change_scene_to_file(START_SCREEN_SCENE)
func _rebuild_tiles(center: Vector2i) -> void:
@@ -361,6 +478,332 @@ func _build_floor_inventory_label(floor_items: Array) -> String:
if floor_items.size() > parts.size():
label += " ..."
return label
func _update_inventory_location_label() -> void:
if _inventory_location_label == null:
return
var location_data := _get_location_data(_center_coord)
var location_name := String(location_data.get("name", "Unknown Location")).strip_edges()
_inventory_location_label.text = "%s (%d,%d)" % [location_name, _center_coord.x, _center_coord.y]
func _refresh_inventory_menu_data() -> void:
if _inventory_request_in_flight:
return
_refresh_inventory_menu_data_async()
func _refresh_inventory_menu_data_async() -> void:
_inventory_request_in_flight = true
_update_inventory_location_label()
_character_inventory_items = await _fetch_character_inventory()
var location_id := _get_current_location_id()
if not location_id.is_empty():
await _refresh_location_inventory(location_id)
_render_inventory_menu()
_inventory_request_in_flight = false
func _render_inventory_menu() -> void:
var current_character_selection := _selected_character_item_id
var current_ground_selection := _selected_ground_item_id
_character_items_list.clear()
var slot_map := {}
for item_variant in _character_inventory_items:
if typeof(item_variant) != TYPE_DICTIONARY:
continue
var item := item_variant as Dictionary
var slot_value: Variant = item.get("slot", null)
if typeof(slot_value) == TYPE_NIL:
continue
slot_map[int(slot_value)] = item
for slot_index in range(CHARACTER_SLOT_COUNT):
var text := "Slot %d: (empty)" % slot_index
var metadata: Dictionary = {}
if slot_map.has(slot_index):
var slot_item := slot_map[slot_index] as Dictionary
text = "Slot %d: %s x%d" % [
slot_index,
String(slot_item.get("itemKey", "")).strip_edges(),
int(slot_item.get("quantity", 0))
]
metadata = slot_item
_character_items_list.add_item(text)
_character_items_list.set_item_metadata(slot_index, metadata)
if not current_character_selection.is_empty() and String(metadata.get("itemId", metadata.get("id", ""))).strip_edges() == current_character_selection:
_character_items_list.select(slot_index)
_ground_items_list.clear()
var floor_items := _get_current_floor_items()
for index in range(floor_items.size()):
var floor_item := floor_items[index] as Dictionary
var floor_text := "%s x%d" % [
String(floor_item.get("itemKey", "")).strip_edges(),
int(floor_item.get("quantity", 0))
]
_ground_items_list.add_item(floor_text)
_ground_items_list.set_item_metadata(index, floor_item)
if not current_ground_selection.is_empty() and String(floor_item.get("itemId", floor_item.get("id", ""))).strip_edges() == current_ground_selection:
_ground_items_list.select(index)
_update_inventory_controls()
func _update_inventory_controls() -> void:
var selected_item := _get_selected_inventory_item()
var max_quantity := 1
if not selected_item.is_empty():
max_quantity = max(1, int(selected_item.get("quantity", 1)))
if _selected_ground_item_id == String(selected_item.get("itemId", selected_item.get("id", ""))).strip_edges():
_target_slot_spin_box.value = float(_default_slot_for_item(selected_item))
_quantity_spin_box.max_value = float(max_quantity)
if int(_quantity_spin_box.value) > max_quantity:
_quantity_spin_box.value = float(max_quantity)
if int(_quantity_spin_box.value) < 1:
_quantity_spin_box.value = 1.0
func _get_selected_inventory_item() -> Dictionary:
if not _selected_character_item_id.is_empty():
return _find_item_by_id(_character_inventory_items, _selected_character_item_id)
if not _selected_ground_item_id.is_empty():
return _find_item_by_id(_get_current_floor_items(), _selected_ground_item_id)
return {}
func _find_item_by_id(items: Array, item_id: String) -> Dictionary:
for item_variant in items:
if typeof(item_variant) != TYPE_DICTIONARY:
continue
var item := item_variant as Dictionary
if String(item.get("itemId", item.get("id", ""))).strip_edges() == item_id:
return item
return {}
func _get_current_location_id() -> String:
var location_data := _get_location_data(_center_coord)
return String(location_data.get("id", "")).strip_edges()
func _get_current_floor_items() -> Array:
var location_data := _get_location_data(_center_coord)
return location_data.get("floorItems", [])
func _default_slot_for_item(item: Dictionary) -> int:
var item_key := String(item.get("itemKey", "")).strip_edges()
for existing_variant in _character_inventory_items:
if typeof(existing_variant) != TYPE_DICTIONARY:
continue
var existing := existing_variant as Dictionary
if String(existing.get("itemKey", "")).strip_edges() != item_key:
continue
return int(existing.get("slot", 0))
return _first_open_character_slot()
func _first_open_character_slot() -> int:
var used_slots := {}
for item_variant in _character_inventory_items:
if typeof(item_variant) != TYPE_DICTIONARY:
continue
var item := item_variant as Dictionary
var slot_value: Variant = item.get("slot", null)
if typeof(slot_value) == TYPE_NIL:
continue
used_slots[int(slot_value)] = true
for slot_index in range(CHARACTER_SLOT_COUNT):
if not used_slots.has(slot_index):
return slot_index
return 0
func _on_character_items_selected(index: int) -> void:
var metadata: Variant = _character_items_list.get_item_metadata(index)
_selected_ground_item_id = ""
_ground_items_list.deselect_all()
if typeof(metadata) != TYPE_DICTIONARY or (metadata as Dictionary).is_empty():
_selected_character_item_id = ""
else:
var item := metadata as Dictionary
_selected_character_item_id = String(item.get("itemId", item.get("id", ""))).strip_edges()
_target_slot_spin_box.value = float(int(item.get("slot", 0)))
_update_inventory_controls()
func _on_ground_items_selected(index: int) -> void:
var metadata: Variant = _ground_items_list.get_item_metadata(index)
_selected_character_item_id = ""
_character_items_list.deselect_all()
if typeof(metadata) != TYPE_DICTIONARY or (metadata as Dictionary).is_empty():
_selected_ground_item_id = ""
else:
var item := metadata as Dictionary
_selected_ground_item_id = String(item.get("itemId", item.get("id", ""))).strip_edges()
_target_slot_spin_box.value = float(_default_slot_for_item(item))
_update_inventory_controls()
func _on_inventory_move_pressed() -> void:
if _selected_character_item_id.is_empty():
_inventory_status_label.text = "Select a character item first."
return
var to_slot := int(_target_slot_spin_box.value)
var quantity := int(_quantity_spin_box.value)
_move_character_item_async(_selected_character_item_id, to_slot, quantity)
func _on_inventory_drop_pressed() -> void:
if _selected_character_item_id.is_empty():
_inventory_status_label.text = "Select a character item to drop."
return
var location_id := _get_current_location_id()
if location_id.is_empty():
_inventory_status_label.text = "Current location is missing an id."
return
var quantity := int(_quantity_spin_box.value)
_transfer_item_async(_selected_character_item_id, "character", _character_id, "location", location_id, null, quantity, "Dropped item.")
func _on_inventory_pickup_pressed() -> void:
if _selected_ground_item_id.is_empty():
_inventory_status_label.text = "Select a ground item to pick up."
return
var location_id := _get_current_location_id()
if location_id.is_empty():
_inventory_status_label.text = "Current location is missing an id."
return
var quantity := int(_quantity_spin_box.value)
var to_slot := int(_target_slot_spin_box.value)
_transfer_item_async(_selected_ground_item_id, "location", location_id, "character", _character_id, to_slot, quantity, "Picked up item.")
func _on_inventory_refresh_pressed() -> void:
_inventory_status_label.text = "Refreshing..."
_refresh_inventory_menu_data()
func _on_inventory_close_pressed() -> void:
_close_inventory_menu()
func _move_character_item_async(item_id: String, to_slot: int, quantity: int) -> void:
if _inventory_request_in_flight:
return
_inventory_request_in_flight = true
_inventory_status_label.text = "Moving item..."
var request := HTTPRequest.new()
add_child(request)
var headers := PackedStringArray()
if not AuthState.access_token.is_empty():
headers.append("Authorization: Bearer %s" % AuthState.access_token)
headers.append("Content-Type: application/json")
var body := JSON.stringify({
"itemId": item_id,
"toSlot": to_slot,
"quantity": quantity
})
var err := request.request("%s/by-owner/character/%s/move" % [INVENTORY_API_URL, _character_id], headers, HTTPClient.METHOD_POST, body)
if err != OK:
request.queue_free()
_inventory_status_label.text = "Move request failed."
_inventory_request_in_flight = false
return
var result: Array = await request.request_completed
request.queue_free()
_inventory_request_in_flight = false
_handle_inventory_mutation_response(result, "Item moved.")
func _transfer_item_async(item_id: String, from_owner_type: String, from_owner_id: String, to_owner_type: String, to_owner_id: String, to_slot: Variant, quantity: int, success_message: String) -> void:
if _inventory_request_in_flight:
return
_inventory_request_in_flight = true
_inventory_status_label.text = "Transferring item..."
var request := HTTPRequest.new()
add_child(request)
var headers := PackedStringArray()
if not AuthState.access_token.is_empty():
headers.append("Authorization: Bearer %s" % AuthState.access_token)
headers.append("Content-Type: application/json")
var payload := {
"itemId": item_id,
"fromOwnerType": from_owner_type,
"fromOwnerId": from_owner_id,
"toOwnerType": to_owner_type,
"toOwnerId": to_owner_id,
"quantity": quantity
}
if typeof(to_slot) != TYPE_NIL:
payload["toSlot"] = int(to_slot)
var err := request.request("%s/transfer" % INVENTORY_API_URL, headers, HTTPClient.METHOD_POST, JSON.stringify(payload))
if err != OK:
request.queue_free()
_inventory_status_label.text = "Transfer request failed."
_inventory_request_in_flight = false
return
var result: Array = await request.request_completed
request.queue_free()
_inventory_request_in_flight = false
_handle_inventory_mutation_response(result, success_message)
func _handle_inventory_mutation_response(result: Array, success_message: String) -> void:
var result_code: int = result[0]
var response_code: int = result[1]
var response_body: String = result[3].get_string_from_utf8()
if result_code != HTTPRequest.RESULT_SUCCESS or response_code < 200 or response_code >= 300:
_inventory_status_label.text = "Inventory action failed."
push_warning("Inventory action failed (%s/%s): %s" % [result_code, response_code, response_body])
return
_inventory_status_label.text = success_message
_refresh_inventory_menu_data()
func _fetch_character_inventory() -> Array:
var request := HTTPRequest.new()
add_child(request)
var headers := PackedStringArray()
if not AuthState.access_token.is_empty():
headers.append("Authorization: Bearer %s" % AuthState.access_token)
var err := request.request("%s/by-owner/character/%s" % [INVENTORY_API_URL, _character_id], headers, HTTPClient.METHOD_GET)
if err != OK:
request.queue_free()
push_warning("Failed to request character inventory: %s" % err)
return []
var result: Array = await request.request_completed
request.queue_free()
var result_code: int = result[0]
var response_code: int = result[1]
var response_body: String = result[3].get_string_from_utf8()
if result_code != HTTPRequest.RESULT_SUCCESS or response_code < 200 or response_code >= 300:
push_warning("Failed to load character inventory (%s/%s): %s" % [result_code, response_code, response_body])
return []
var parsed: Variant = JSON.parse_string(response_body)
if typeof(parsed) != TYPE_DICTIONARY:
return []
var payload := parsed as Dictionary
return _parse_floor_inventory_items(payload.get("items", []))
func _ensure_selected_location_exists(coord: Vector2i) -> void: