fix: make run event journal authoritative
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
extends GutTest
|
||||
|
||||
const GameScene = preload("res://scenes/Game.tscn")
|
||||
|
||||
const CURRENT_RESULT_KINDS: Array[StringName] = [
|
||||
&"moved",
|
||||
&"blocked",
|
||||
&"melee",
|
||||
&"enemy_melee",
|
||||
&"enemy_moved",
|
||||
&"enemy_defeated",
|
||||
&"door_opened",
|
||||
&"chest_opened",
|
||||
&"stairs_used",
|
||||
&"nothing_to_interact",
|
||||
]
|
||||
|
||||
func test_all_current_turn_result_kinds_map_to_complete_game_events_for_one_action_turn() -> void:
|
||||
var game := GameScene.instantiate() as Game
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
var results: Array[TurnResult] = []
|
||||
for index in range(CURRENT_RESULT_KINDS.size()):
|
||||
results.append(TurnResult.new(
|
||||
&"player" if index % 2 == 0 else &"goblin",
|
||||
CURRENT_RESULT_KINDS[index],
|
||||
Vector2i(index, 1),
|
||||
Vector2i(index, 2),
|
||||
&"goblin" if index % 2 == 0 else &"player",
|
||||
index,
|
||||
"event %d" % index
|
||||
))
|
||||
|
||||
game._record_events(results)
|
||||
var events := game.get_run_state().recent_events(CURRENT_RESULT_KINDS.size())
|
||||
|
||||
assert_eq(events.map(func(event: GameEvent) -> StringName: return event.kind), CURRENT_RESULT_KINDS)
|
||||
assert_eq(events.map(func(event: GameEvent) -> int: return event.turn), [1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
|
||||
for index in range(CURRENT_RESULT_KINDS.size()):
|
||||
assert_eq(events[index].floor, 0)
|
||||
assert_eq(events[index].payload, {
|
||||
"from_cell": Vector2i(index, 1),
|
||||
"to_cell": Vector2i(index, 2),
|
||||
"damage": index,
|
||||
})
|
||||
assert_eq(events[index].message, "event %d" % index)
|
||||
assert_eq(events[index].actor_id, &"player" if index % 2 == 0 else &"goblin")
|
||||
assert_eq(events[index].target_id, &"goblin" if index % 2 == 0 else &"player")
|
||||
assert_eq(events[index].cell, Vector2i(index, 2))
|
||||
|
||||
func test_a_second_resolved_action_gets_one_new_action_turn() -> void:
|
||||
var game := GameScene.instantiate() as Game
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
|
||||
game._record_events([TurnResult.new(&"player", &"blocked", Vector2i.ZERO, Vector2i.UP, &"", 0, "first")])
|
||||
game._record_events([TurnResult.new(&"player", &"blocked", Vector2i.ZERO, Vector2i.LEFT, &"", 0, "second")])
|
||||
|
||||
var events := game.get_run_state().recent_events(2)
|
||||
assert_eq(events.map(func(event: GameEvent) -> int: return event.turn), [1, 2])
|
||||
Reference in New Issue
Block a user