96ec053331
- 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
102 lines
3.6 KiB
GDScript
102 lines
3.6 KiB
GDScript
## Tests for HoldableItem — hand slot attachment on drag release.
|
|
extends GutTest
|
|
|
|
|
|
func test_holdable_item_id_default_empty() -> void:
|
|
var item: HoldableItem = HoldableItem.new()
|
|
add_child_autofree(item)
|
|
assert_eq(item.item_id, "")
|
|
|
|
|
|
func test_holdable_item_is_not_in_hand_initially() -> void:
|
|
var item: HoldableItem = HoldableItem.new()
|
|
add_child_autofree(item)
|
|
assert_false(item.is_in_hand_slot())
|
|
|
|
|
|
func test_holdable_item_attaches_to_nearest_free_hand() -> void:
|
|
var character: Character = preload("res://scenes/characters/Character.tscn").instantiate() as Character
|
|
add_child_autofree(character)
|
|
var item: HoldableItem = HoldableItem.new()
|
|
add_child_autofree(item)
|
|
item.item_id = "test_item"
|
|
item.global_position = character.get_node("HandLeft").global_position
|
|
item._on_drag_released(item.global_position)
|
|
assert_true(item.is_in_hand_slot())
|
|
|
|
|
|
func test_holdable_item_does_not_attach_if_no_character_in_range() -> void:
|
|
var item: HoldableItem = HoldableItem.new()
|
|
add_child_autofree(item)
|
|
item.global_position = Vector2(9999.0, 9999.0)
|
|
item._on_drag_released(item.global_position)
|
|
assert_false(item.is_in_hand_slot())
|
|
|
|
|
|
func test_holdable_item_does_not_attach_to_occupied_hand() -> void:
|
|
var character: Character = preload("res://scenes/characters/Character.tscn").instantiate() as Character
|
|
add_child_autofree(character)
|
|
var item1: Node2D = Node2D.new()
|
|
var item2: HoldableItem = HoldableItem.new()
|
|
add_child_autofree(item1)
|
|
add_child_autofree(item2)
|
|
character.attach_item("left", item1)
|
|
var item_filler: Node2D = Node2D.new()
|
|
add_child_autofree(item_filler)
|
|
character.attach_item("right", item_filler)
|
|
item2.global_position = character.global_position
|
|
item2._on_drag_released(item2.global_position)
|
|
assert_false(item2.is_in_hand_slot())
|
|
|
|
|
|
func test_holdable_item_detaches_on_pickup_when_in_slot() -> void:
|
|
var character: Character = preload("res://scenes/characters/Character.tscn").instantiate() as Character
|
|
add_child_autofree(character)
|
|
var item: HoldableItem = HoldableItem.new()
|
|
add_child_autofree(item)
|
|
character.attach_item("left", item)
|
|
assert_true(item.is_in_hand_slot())
|
|
item._on_drag_picked_up(item.global_position)
|
|
assert_false(item.is_in_hand_slot())
|
|
|
|
|
|
func test_holdable_item_detach_preserves_global_position() -> void:
|
|
var character: Character = preload("res://scenes/characters/Character.tscn").instantiate() as Character
|
|
add_child_autofree(character)
|
|
var item: HoldableItem = HoldableItem.new()
|
|
add_child_autofree(item)
|
|
character.attach_item("left", item)
|
|
var hand_pos: Vector2 = character.get_node("HandLeft").global_position
|
|
item._on_drag_picked_up(hand_pos)
|
|
assert_eq(item.global_position, hand_pos)
|
|
|
|
|
|
func test_try_return_to_chest_false_when_no_home_chest() -> void:
|
|
var item: HoldableItem = HoldableItem.new()
|
|
add_child_autofree(item)
|
|
assert_false(item._try_return_to_chest())
|
|
|
|
|
|
func test_try_return_to_chest_false_when_beyond_radius() -> void:
|
|
var chest: RoomChest = RoomChest.new()
|
|
chest.chest_id = "reception_desk"
|
|
add_child_autofree(chest)
|
|
chest.global_position = Vector2.ZERO
|
|
var item: HoldableItem = HoldableItem.new()
|
|
add_child_autofree(item)
|
|
item.home_chest = chest
|
|
item.global_position = Vector2(200.0, 0.0)
|
|
assert_false(item._try_return_to_chest())
|
|
|
|
|
|
func test_try_return_to_chest_true_when_within_radius() -> void:
|
|
var chest: RoomChest = RoomChest.new()
|
|
chest.chest_id = "reception_desk"
|
|
add_child_autofree(chest)
|
|
chest.global_position = Vector2.ZERO
|
|
var item: HoldableItem = HoldableItem.new()
|
|
add_child_autofree(item)
|
|
item.home_chest = chest
|
|
item.global_position = Vector2(40.0, 0.0)
|
|
assert_true(item._try_return_to_chest())
|