feat(items): add chest-return priority to HoldableItem and GameState v3 chest states
- HoldableItem._try_return_to_chest() snaps item back if within CHEST_RETURN_RADIUS (80px) - _on_drag_released checks chest return before hand-slot fallback - OutfitItem._on_drag_released checks chest return before outfit/hand-slot logic - GameState: _chest_states dict + get/set/clear_chest_state methods - GameState.get_save_data() bumped to version 3, includes chest_states - GameState.apply_save_data() restores chest_states from save data
This commit is contained in:
@@ -7,6 +7,7 @@ signal item_picked_up(item: HoldableItem)
|
||||
signal item_placed(item: HoldableItem)
|
||||
|
||||
const HAND_SLOT_RADIUS: float = 60.0
|
||||
const CHEST_RETURN_RADIUS: float = 80.0
|
||||
|
||||
@export var item_id: String = ""
|
||||
|
||||
@@ -27,6 +28,8 @@ func _on_drag_picked_up(_pos: Vector2) -> void:
|
||||
|
||||
|
||||
func _on_drag_released(_pos: Vector2) -> void:
|
||||
if _try_return_to_chest():
|
||||
return
|
||||
var result: Array = _find_nearest_free_hand_slot()
|
||||
if not result.is_empty():
|
||||
var character: Character = result[0] as Character
|
||||
@@ -35,6 +38,15 @@ func _on_drag_released(_pos: Vector2) -> void:
|
||||
item_placed.emit(self)
|
||||
|
||||
|
||||
func _try_return_to_chest() -> bool:
|
||||
if home_chest == null:
|
||||
return false
|
||||
if global_position.distance_to(home_chest.global_position) >= CHEST_RETURN_RADIUS:
|
||||
return false
|
||||
(home_chest as RoomChest).receive_item(self)
|
||||
return true
|
||||
|
||||
|
||||
func is_in_hand_slot() -> bool:
|
||||
var p: Node = get_parent()
|
||||
if p == null:
|
||||
|
||||
@@ -10,6 +10,8 @@ const OUTFIT_APPLY_RADIUS: float = 80.0
|
||||
|
||||
|
||||
func _on_drag_released(_pos: Vector2) -> void:
|
||||
if _try_return_to_chest():
|
||||
return
|
||||
var character: Character = _find_nearest_character()
|
||||
if character != null:
|
||||
character.apply_outfit_item(outfit_layer, item_id, outfit_sprite, self)
|
||||
|
||||
Reference in New Issue
Block a user