class_name PlayerInventory extends Node ## Minimal per-player item-count store. ## ## docs/architecture/dynamic_object_node.gd's header notes that a dynamic ## object's runtime state ("position, health, inventory") belongs to "the ## entity system" -- but no such system exists yet (M9 Economy hasn't been ## built). This is a deliberately small, local stub scoped to make ## ScriptBehavior's `give_item` verb demonstrable now, not an attempt to ## build the real economy/inventory system. Replace it wholesale when M9 ## lands; keep the give_item/get_count surface so existing ScriptBehavior ## data keeps working against the real thing. ## ## Attach one of these as a child node named "Inventory" under a player (see ## scenes/player.tscn) -- [ScriptInterpreterNode] looks it up by that name ## when resolving `target: "player"` for the `give_item` verb. ## Emitted whenever an item's count changes, with the item's new total. signal item_changed(item_id: String, count: int) var _items: Dictionary = {} # item_id (String) -> count (int) ## Add (or, with a negative count, remove) units of an item. Counts never go ## negative. `count == 0` is a no-op. func give_item(item_id: String, count: int) -> void: if item_id.is_empty() or count == 0: return var new_count: int = maxi(0, int(_items.get(item_id, 0)) + count) _items[item_id] = new_count item_changed.emit(item_id, new_count) ## Current count for an item (0 if never granted). func get_count(item_id: String) -> int: return int(_items.get(item_id, 0)) ## A snapshot of the whole inventory (for UI/debugging/tests). func get_all() -> Dictionary: return _items.duplicate()