Crafting v2

This commit is contained in:
dingo
2025-12-23 13:41:30 -05:00
parent 6a4a64e39e
commit 2a5f4b9b78
10 changed files with 1091 additions and 17 deletions
+43 -16
View File
@@ -46,6 +46,18 @@ func _ready():
func _connect_gamestate():
if GameState:
GameState.inventory_updated.connect(_refresh_inventory)
if UpdateManager:
UpdateManager.file_downloaded.connect(_on_file_downloaded)
UpdateManager.update_completed.connect(_on_updates_completed)
func _on_file_downloaded(file_path: String):
# If an item texture was downloaded, refresh inventory to show it
if file_path.begins_with("textures/items/"):
_refresh_inventory()
func _on_updates_completed(_count: int):
# Refresh inventory after all updates complete
_refresh_inventory()
func _setup_equipment_slots():
if not equipment_grid:
@@ -242,23 +254,38 @@ func _get_item_emoji(item: Dictionary) -> String:
_: return "❓"
func _on_inventory_gui_input(event: InputEvent, slot_index: int):
if event is InputEventMouseButton and event.pressed:
var item = GameState.inventory[slot_index] if slot_index < GameState.inventory.size() else null
if not event is InputEventMouseButton:
return
var item = GameState.inventory[slot_index] if slot_index < GameState.inventory.size() else null
if event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
# Start drag if has item
if item and not item.is_empty() and DragManager:
DragManager.start_drag(item, "inventory", slot_index)
else:
# End drag on release (if still dragging)
if DragManager and DragManager.is_dragging:
# Check if we should equip or use
var drag_item = DragManager.get_drag_item()
var item_type = drag_item.get("type", drag_item.get("Type", ""))
# If released over same slot or no target, treat as click
# For now, just end the drag
DragManager.end_drag()
elif event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:
if item == null:
return
if event.button_index == MOUSE_BUTTON_LEFT:
# Left click: use/equip
var item_type = item.get("type", item.get("Type", ""))
if item_type == "Consumable":
GameState.send_use_item(slot_index)
elif item_type in ["Weapon", "Armor", "Accessory"]:
GameState.send_equip_item(slot_index)
elif event.button_index == MOUSE_BUTTON_RIGHT:
# Right click: assign to hotbar (for consumables)
var item_type = item.get("type", item.get("Type", ""))
if item_type == "Consumable":
_show_hotbar_menu(slot_index)
# Right click: context action
var item_type = item.get("type", item.get("Type", ""))
if item_type == "Consumable":
# Use consumable on right click
GameState.send_use_item(slot_index)
elif item_type in ["Weapon", "Armor", "Accessory"]:
# Equip on right click
GameState.send_equip_item(slot_index)
func _on_equipment_gui_input(event: InputEvent, slot_name: String):
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
@@ -267,7 +294,7 @@ func _on_equipment_gui_input(event: InputEvent, slot_name: String):
GameState.send_unequip_item(slot_name)
func _show_hotbar_menu(inv_slot: int):
# Simple approach: assign to next empty hotbar slot or show popup
# Simple approach: assign to next empty hotbar slot or use slot 0
# For now, find first empty slot or use slot 0
var target_slot = 0
for i in range(8):