Files
Cozypaw-Hospital/scripts/objects/outfit_item.gd
T
Steven Wroblewski 96ec053331 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
2026-05-09 01:09:47 +02:00

34 lines
1.0 KiB
GDScript

## OutfitItem — HoldableItem that applies an outfit layer to a Character when dropped
## within OUTFIT_APPLY_RADIUS of the character's center. Falls back to hand slot
## attachment if no character body is in range.
class_name OutfitItem extends HoldableItem
const OUTFIT_APPLY_RADIUS: float = 80.0
@export var outfit_layer: int = 1
@export var outfit_sprite: Texture2D
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)
return
super._on_drag_released(_pos)
func _find_nearest_character() -> Character:
var best_dist: float = OUTFIT_APPLY_RADIUS
var best: Character = null
for node: Node in get_tree().get_nodes_in_group("characters"):
var character: Character = node as Character
if character == null:
continue
var dist: float = global_position.distance_to(character.global_position)
if dist < best_dist:
best_dist = dist
best = character
return best