extends RefCounted ## Accessibility: escalation cues that survive grayscale (shape + level, not hue ## alone) and the HUD font scale from settings. const Hud := preload("res://src/game/ui/hud.gd") const Rules := preload("res://src/core/rules.gd") func test_meter_shape_and_level() -> bool: var a := TestUtils.check_eq(Hud.escalation_meter(0), "[-----] L0/5", "calm shows an empty meter") var b := TestUtils.check_eq(Hud.escalation_meter(3), "[###--] L3/5", "three filled blocks at blocking") var c := TestUtils.check_eq(Hud.escalation_meter(5), "[#####] L5/5", "emergency fills the meter") var d := TestUtils.check_eq(Hud.escalation_meter(99), "[#####] L5/5", "levels clamp at 5") var e := TestUtils.check_eq(Hud.escalation_meter(-2), "[-----] L0/5", "levels clamp at 0") return a and b and c and d and e func test_meter_is_not_hue_only() -> bool: ## Every level must differ in shape/text, independent of colour. var seen: Array[String] = [] for level in 6: var meter: String = Hud.escalation_meter(level) if seen.has(meter): return TestUtils.fail("levels %d and %d share a meter" % [level, seen.find(meter)]) seen.append(meter) return TestUtils.check(seen.size() == 6, "all six levels have distinct meters") func test_escalation_label_includes_meter_and_name() -> bool: var hud: Node = Hud.new() hud.set_escalation(Rules.Level.FORMAL_WARNING) var text: String = hud.escalation_label.text var a := TestUtils.check(text.contains("Formal Warning"), "label names the level") var b := TestUtils.check(text.contains("[##---]"), "label shows the shape meter") var c := TestUtils.check(text.contains("L2/5"), "label shows the numeric level") hud.free() return a and b and c func test_font_scale_applies_to_core_labels() -> bool: var hud: Node = Hud.new() var base_top: int = hud.top_label.get_theme_font_size("font_size") var base_log: int = hud.log_label.get_theme_font_size("font_size") var base_esc: int = hud.escalation_label.get_theme_font_size("font_size") var base_mode: int = hud.mode_label.get_theme_font_size("font_size") hud.set_font_scale(1.4) var a := TestUtils.check(hud.top_label.get_theme_font_size("font_size") > base_top, "top label grows") var b := TestUtils.check(hud.log_label.get_theme_font_size("font_size") > base_log, "log grows") var c := TestUtils.check(hud.escalation_label.get_theme_font_size("font_size") > base_esc, "escalation label grows") var d := TestUtils.check(hud.mode_label.get_theme_font_size("font_size") > base_mode, "mode label grows") # Scaling is by font size, not Control.scale, so anchored labels keep layout. var e := TestUtils.check(is_equal_approx(hud.top_label.scale.x, 1.0), "labels are not Control-scaled") hud.set_font_scale(9.0) var capped: int = hud.top_label.get_theme_font_size("font_size") var f := TestUtils.check(capped <= int(round(float(base_top) * 1.75)) + 1, "scale clamps at 1.75") # The target chip must widen with the scaled font instead of spilling over # the world; an extreme name is capped rather than pushing off-screen. hud.set_font_scale(1.75) hud.set_target_label("Intoxicated Pedestrian") var chip = hud.get("_target_chip") var chip_width: float = float(chip.offset_right) - float(chip.offset_left) var g := TestUtils.check(chip_width > 300.0, "target chip widens at max font scale") hud.set_target_label("An Extraordinarily Long Display Name For A Visitor In A Pseudo Locale") var long_width: float = float(chip.offset_right) - float(chip.offset_left) var h := TestUtils.check(long_width <= 420.5, "target chip caps an extreme name") hud.free() return a and b and c and d and e and f and g and h func test_settings_font_scale_is_applied_after_ui_exists() -> bool: ## The HUD is created after settings load, so the manager must re-apply. var src := FileAccess.get_file_as_string("res://src/game/game_manager.gd") var a := TestUtils.check(src.contains("_apply_settings(player_settings)"), "settings are applied on boot") var build_idx := src.find("_build_ui()") var apply_idx := src.find("_apply_settings(player_settings)", build_idx) var b := TestUtils.check(apply_idx > build_idx, "the second apply happens after the HUD is built") var c := TestUtils.check(src.contains("hud.set_font_scale(float(settings.get("), "settings drive the HUD font scale") return a and b and c