feat: let the player live as a citizen with needs and carried inventory

This commit is contained in:
Rijad Zuzo
2026-08-11 00:18:39 +02:00
parent f72aa659d2
commit 37f262fb84
20 changed files with 746 additions and 90 deletions
+46
View File
@@ -0,0 +1,46 @@
class_name PlayerStatusHud
extends Control
@export var simulation_manager: Node
@onready var status_label: Label = $StatusLabel
var cached_text := ""
func _ready() -> void:
visible = true
_refresh(true)
func _process(_delta: float) -> void:
_refresh(false)
func _refresh(force: bool = false) -> void:
if simulation_manager == null or not simulation_manager.has_method("get_player_state"):
return
var player_state: PlayerStateRecord = simulation_manager.get_player_state()
var carried := _carried_text(player_state)
var next_text := (
"Hunger %.0f · Energy %.0f · Carrying %s"
% [player_state.get_hunger(), player_state.get_energy(), carried]
)
if not force and next_text == cached_text:
return
cached_text = next_text
status_label.text = next_text
func _carried_text(player_state: PlayerStateRecord) -> String:
var entries: Array[String] = []
for raw_item_id in player_state.data["inventory"]:
var item_id := String(raw_item_id)
var amount := player_state.get_inventory_amount(StringName(item_id))
if amount <= 0.0:
continue
entries.append("%.0f %s" % [amount, StringName(item_id).to_lower()])
if entries.is_empty():
return "nothing"
entries.sort()
return " · ".join(entries)