feat: complete playtest parity improvements

This commit is contained in:
goose
2026-10-08 19:06:19 -04:00
parent cce25a1908
commit eca098b4b9
139 changed files with 3001 additions and 982 deletions
@@ -0,0 +1,103 @@
extends GutTest
const GameScene = preload("res://scenes/Game.tscn")
const RunSettings = preload("res://scripts/domain/run/run_settings.gd")
const TemporaryPlaytestKit = preload("res://scripts/game/temporary_playtest_kit.gd")
const SaveRepository = preload("res://scripts/infrastructure/save/save_repository.gd")
var game: Game
func before_each() -> void:
game = GameScene.instantiate()
game.configure_new_run(RunSettings.new("TEMP-CHESTS", &"crawler"), "Chest Tester")
add_child_autofree(game)
await get_tree().process_frame
func test_new_playtest_run_has_exactly_three_accessible_fixed_gameplay_chests() -> void:
var state := game.get_game_state()
assert_eq(state.floor_state.chests.size(), 3)
var rewards: Array[Dictionary] = []
for cell: Vector2i in state.floor_state.chests:
assert_eq(state.map.get_cell(cell), GridMapState.CellKind.CHEST)
assert_lte(cell.distance_to(state.player.cell), 3.0)
rewards.append(state.floor_state.chests[cell].reward)
assert_true(_has_reward_item(rewards, &"weapon_rusty_sword"))
assert_true(_has_reward_item(rewards, &"weapon_hand_crossbow"))
assert_true(_has_reward_item(rewards, &"misc_grimoire_ombre"))
assert_true(rewards.any(func(reward: Dictionary) -> bool: return int(reward.get("ammunition", 0)) >= 10))
func test_all_three_playtest_chests_open_and_transfer_rewards_through_the_normal_ui_flow() -> void:
var state := game.get_game_state()
state.enemies.clear()
for chest_cell: Vector2i in TemporaryPlaytestKit.CHESTS:
state.player.cell = chest_cell + Vector2i.DOWN
state.update_exploration()
var results := game.submit_test_interact()
assert_eq(results[0].kind, &"chest_opened")
assert_true((game.get_node("HUD/LootPanel") as PanelContainer).visible)
await _dispatch_key(KEY_ENTER)
assert_false((game.get_node("HUD/LootPanel") as PanelContainer).visible)
var inventory_ids := game.get_run_state().inventory.items.map(func(item: ItemInstance) -> StringName: return item.definition.id)
assert_has(inventory_ids, &"weapon_rusty_sword")
assert_has(inventory_ids, &"weapon_hand_crossbow")
assert_has(inventory_ids, &"misc_grimoire_ombre")
assert_eq(state.player.ammunition, 20)
func test_temporary_rewards_grant_ammunition_and_teach_the_offensive_spell_through_normal_use() -> void:
var state := game.get_game_state()
var ranged_reward := _reward_with_item(state.floor_state.chests, &"weapon_hand_crossbow")
var spell_reward := _reward_with_item(state.floor_state.chests, &"misc_grimoire_ombre")
game.pending_loot = ranged_reward.duplicate(true)
game._take_all_loot()
assert_eq(state.player.ammunition, 20)
assert_true(game.get_run_state().inventory.items.any(func(item: ItemInstance) -> bool: return item.definition.id == &"weapon_hand_crossbow"))
game.pending_loot = spell_reward.duplicate(true)
game._take_all_loot()
var grimoire: ItemInstance = game.get_run_state().inventory.items.filter(func(item: ItemInstance) -> bool: return item.definition.id == &"misc_grimoire_ombre")[0]
var use_result := game.get_run_state().inventory.use_item(grimoire.instance_id, state.player, game.get_run_state().identification)
game._apply_item_use_effects(use_result.get("effects", []))
assert_true(game.get_spell_state().knows(&"spell_ombre_vive"))
func test_loaded_run_does_not_recreate_consumed_temporary_chests() -> void:
var state := game.get_game_state()
state.floor_state.chests.clear()
for cell: Vector2i in TemporaryPlaytestKit.CHESTS:
state.map.set_cell(cell, GridMapState.CellKind.FLOOR)
var repository := SaveRepository.new()
repository.delete_all()
assert_true(repository.save(1, game.get_run_state(), state, game.get_dialogue_player()).ok)
var loaded := repository.load(1, game.spell_catalog)
var restored := GameScene.instantiate() as Game
restored.configure_loaded_run(loaded)
add_child_autofree(restored)
await get_tree().process_frame
assert_true(restored.get_game_state().floor_state.chests.is_empty())
repository.delete_all()
func _dispatch_key(keycode: Key) -> void:
var event := InputEventKey.new()
event.keycode = keycode
event.physical_keycode = keycode
event.pressed = true
Input.parse_input_event(event)
await get_tree().process_frame
event.pressed = false
Input.parse_input_event(event)
await get_tree().process_frame
func _reward_with_item(chests: Dictionary[Vector2i, Dictionary], item_id: StringName) -> Dictionary:
for chest: Dictionary in chests.values():
if chest.reward.items.any(func(item: Dictionary) -> bool: return StringName(item.item_id) == item_id):
return chest.reward
return {}
func _has_reward_item(rewards: Array[Dictionary], item_id: StringName) -> bool:
for reward: Dictionary in rewards:
if reward.get("items", []).any(func(item: Dictionary) -> bool: return StringName(item.get("item_id", "")) == item_id):
return true
return false