fix: select visible targets and bound active effects

This commit is contained in:
goose
2026-10-09 17:51:04 -04:00
parent 70aa27d232
commit 069537e737
2 changed files with 118 additions and 21 deletions
+61 -5
View File
@@ -411,6 +411,43 @@ func test_status_section_formats_active_player_effects_in_french() -> void:
assert_eq(effects.text, "Effets : Empoisonnement (3 tours), Renforcé (2 tours)")
assert_eq(effects.text.findn("prêt à explorer"), -1)
func test_generated_visible_target_uses_catalog_name_and_never_reveals_hidden_enemies() -> void:
var hud := game.get_node_or_null("HUD") as GameHud
assert_not_null(hud, "Game scene requires HUD")
if hud == null:
return
var state := game.get_game_state()
state.enemies.clear()
state.visible_cells.clear()
var nearest_visible := ActorState.new(&"enemy_scavenger_07", state.player.cell + Vector2i.RIGHT, 22, 5, &"enemy_scavenger")
var farther_visible := ActorState.new(&"enemy_scavenger_08", state.player.cell + Vector2i(3, 0), 22, 5, &"enemy_scavenger")
farther_visible.take_damage(5)
var nearer_hidden := ActorState.new(&"enemy_scavenger_hidden", state.player.cell + Vector2i.DOWN, 22, 5, &"enemy_scavenger")
state.enemies[nearest_visible.id] = nearest_visible
state.enemies[farther_visible.id] = farther_visible
state.enemies[nearer_hidden.id] = nearer_hidden
state.visible_cells[nearest_visible.cell] = true
state.visible_cells[farther_visible.cell] = true
hud.refresh(state, [], game.get_run_state())
var target_label := hud.get_node_or_null("EnemyHealthLabel") as Label
assert_not_null(target_label)
if target_label == null:
return
assert_true(target_label.visible)
assert_eq(target_label.text, "Pillard efflanque — PV : 22/22")
assert_eq(target_label.text.find("enemy_scavenger_07"), -1, "HUD must never expose a technical actor id")
state.visible_cells.erase(nearest_visible.cell)
hud.refresh(state, [], game.get_run_state())
assert_true(target_label.visible)
assert_eq(target_label.text, "Pillard efflanque — PV : 17/22", "The next nearest visible living target must be selected")
farther_visible.take_damage(farther_visible.hit_points)
hud.refresh(state, [], game.get_run_state())
assert_false(target_label.visible, "A living enemy outside FOV must not be revealed")
assert_eq(target_label.text, "")
assert_eq(hud.combat_summary, "")
func test_visible_status_labels_are_contained_separated_and_non_overlapping_at_reference_and_compact_sizes() -> void:
var hud := game.get_node_or_null("HUD") as GameHud
assert_not_null(hud, "Game scene requires HUD")
@@ -419,8 +456,12 @@ func test_visible_status_labels_are_contained_separated_and_non_overlapping_at_r
var state := game.get_game_state()
var run := game.get_run_state()
state.enemies.clear()
state.enemies[&"goblin"] = ActorState.new(&"goblin", state.player.cell + Vector2i.RIGHT, 6, 2)
state.player.apply_status(StatusEffectType.new(&"poison", 3))
state.visible_cells.clear()
var target := ActorState.new(&"enemy_scavenger_07", state.player.cell + Vector2i.RIGHT, 22, 5, &"enemy_scavenger")
state.enemies[target.id] = target
state.visible_cells[target.cell] = true
for effect_key: StringName in StatusEffectType.DEFINITIONS.keys():
state.player.apply_status(StatusEffectType.new(effect_key))
run.current_floor = 1
run.ensure_floor_deadline(1).turns_remaining = 15 * FloorDeadline.TURNS_PER_DAY
for viewport_size: Vector2 in [Vector2(1920, 1080), Vector2(1280, 720)]:
@@ -428,11 +469,26 @@ func test_visible_status_labels_are_contained_separated_and_non_overlapping_at_r
hud.refresh(state, [], run)
await get_tree().process_frame
var status := hud.get_node_or_null("ResponsiveLayout/StatusSection") as Control
var effects := hud.get_node_or_null("CharacterStatusLabel") as Label
var target_label := hud.get_node_or_null("EnemyHealthLabel") as Label
var deadline := hud.get_node_or_null("DeadlineLabel") as Label
assert_not_null(status)
if status == null:
assert_not_null(effects)
assert_not_null(target_label)
assert_not_null(deadline)
if status == null or effects == null or target_label == null or deadline == null:
continue
assert_true(effects.visible)
assert_true(target_label.visible)
assert_true(deadline.visible)
assert_string_contains(effects.text, "Empoisonnement")
assert_string_contains(effects.text, "Régénération")
for effect: StatusEffect in state.player.status_effects:
assert_string_contains(effects.text, str(effect.duration), "Every active effect duration must remain represented")
assert_lte(effects.get_minimum_size().x, effects.size.x, "Effects text must fit its assigned width at %s" % viewport_size)
assert_lte(effects.get_minimum_size().y, effects.size.y, "Effects text must fit its assigned height at %s" % viewport_size)
var visible_labels := _visible_status_labels(hud)
assert_gte(visible_labels.size(), 3, "The configured actionable state must expose effects, target, and deadline")
assert_eq(visible_labels.size(), 3, "The configured state must expose exactly effects, target, and deadline")
for label: Label in visible_labels:
assert_true(status.get_global_rect().encloses(label.get_global_rect()), "%s must stay inside StatusSection at %s" % [label.name, viewport_size])
for index in visible_labels.size():
@@ -442,7 +498,7 @@ func test_visible_status_labels_are_contained_separated_and_non_overlapping_at_r
assert_false(first.intersects(second), "%s must not overlap %s at %s" % [visible_labels[index].name, visible_labels[other_index].name, viewport_size])
var upper := first if first.position.y <= second.position.y else second
var lower := second if upper == first else first
assert_gte(lower.position.y - upper.end.y, 8.0, "Visible status labels need at least 8px vertical separation at %s" % viewport_size)
assert_gte(lower.position.y - upper.end.y, 12.0, "Visible status labels need at least 12px vertical separation at %s" % viewport_size)
func test_deadline_label_is_hidden_on_floor_zero_and_uses_only_the_live_collapse_countdown_afterward() -> void:
var hud := game.get_node_or_null("HUD") as GameHud