feat(items): add OutfitItem, tap-to-undress, and outfit refs on Character
- Add OutfitItem (extends HoldableItem): applies outfit on drop within 80px of character body, falls back to hand slot attach if no character in range - Add apply_outfit_item / remove_outfit / _handle_outfit_tap to Character - Track item node refs in _outfit_item_refs for restoring visibility - Fix animation state: reset to idle before tap handling in _on_drag_released - Extract _ITEM_DROP_OFFSET constant (replaces magic Vector2(0,60)) - Add 5 tests in test_outfit_item.gd, 14 new tests in test_character_v2.gd
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
## 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:
|
||||
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
|
||||
Reference in New Issue
Block a user