MobilePort: ui_scale() (clampf(4.3 / the screen's shorter side in inches, 1, 1.8) times the
Interface size; 1 on desktop), a size-class fallback (below 500 pt = phone, 1.6) when the
density is 0 or implausible, safe_rect(ci) (the display's safe area mapped into ci's canvas
through the final transform), minimum_target() (44 pt in canvas pixels), and the `forced`
override for tests. The desktop preview (-- --mobile) plays the phone in the window:
--safe-area=l,t,r,b insets it, --dpi=N sets its density, and without --dpi a 16:9-or-wider
window is a 2.7 in phone (about 1.6x) and a squarer one a 6 in iPad (1x).
GameSettings: interface_size (0.8-1.3, saved under [touch]) and apply_scale(), which sets the
window's content_scale_factor (always 1 on desktop). PerfTest shows the screen, density, safe
area, and resulting scale, to check the density on a device.
Test kit: test_mobile (last in SUITES) runs game/tests/mobile/*_test.gd in name order and puts
the root window back between files; mobile/touch.gd sends touches through
Input.parse_input_event; scale_test covers phones, iPads, desktop, the safe rect, and the target;
sticks_test is the 8c81d81 driver's 24 checks. game/tools/capture_mobile.gd takes the phone
screenshots.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
128 lines
4.1 KiB
GDScript
128 lines
4.1 KiB
GDScript
class_name GameTestRunner
|
|
extends SceneTree
|
|
## Headless test runner for the game (same pattern as prototype/tests/run_tests.gd). Run:
|
|
## godot --headless --path . --script res://game/tests/run_tests.gd
|
|
## Optional: -- --suite=test_campaign (run one suite)
|
|
## Exit code = number of failures.
|
|
|
|
const SUITES := [
|
|
"res://game/tests/test_farm_state.gd",
|
|
"res://game/tests/test_save.gd",
|
|
"res://game/tests/test_outcome.gd",
|
|
"res://game/tests/test_campaign.gd",
|
|
"res://game/tests/test_farm_layout.gd",
|
|
"res://game/tests/test_theft.gd",
|
|
"res://game/tests/test_scarecrow.gd",
|
|
"res://game/tests/test_weapons.gd",
|
|
"res://game/tests/test_economy.gd",
|
|
"res://game/tests/test_structures.gd",
|
|
"res://game/tests/test_targets.gd",
|
|
"res://game/tests/test_radar.gd",
|
|
"res://game/tests/test_roster.gd",
|
|
"res://game/tests/test_nights.gd",
|
|
"res://game/tests/test_cycle.gd",
|
|
"res://game/tests/test_flow.gd",
|
|
"res://game/tests/test_coop.gd",
|
|
"res://game/tests/test_look.gd",
|
|
"res://game/tests/test_dialogue.gd",
|
|
"res://game/tests/test_loading.gd",
|
|
"res://game/tests/test_intro.gd",
|
|
"res://game/tests/test_mobile.gd",
|
|
]
|
|
const TICK := 1.0 / 60.0
|
|
## Points on the farm's edge (FarmZones.edge) for tests that send an enemy in from a known side:
|
|
## on foot GameConfig.spawn_margin (3 m) outside the map, where the perimeter gaps used to be (#20:
|
|
## the south ones moved with the map's south edge, now z 35)...
|
|
const EDGE := {
|
|
"north": Vector2(12.0, -48.0), "driveway": Vector2(50.0, -39.5), "east": Vector2(50.0, -18.5),
|
|
"south-east": Vector2(31.0, 38.0), "south-west": Vector2(-4.0, 38.0), "west": Vector2(-16.0, -6.0),
|
|
}
|
|
## ...and flying flyer_spawn_margin (8 m) out, where the crow approaches were.
|
|
const SKY := {
|
|
"north": Vector2(17.0, -53.0), "east": Vector2(55.0, -5.0), "south": Vector2(17.0, 43.0), "west": Vector2(-21.0, -15.0),
|
|
}
|
|
|
|
var passes: int = 0
|
|
var failures: int = 0
|
|
var current: String = ""
|
|
|
|
|
|
func _initialize() -> void:
|
|
_main.call_deferred()
|
|
|
|
|
|
func _main() -> void:
|
|
await process_frame
|
|
var only := ""
|
|
for a in OS.get_cmdline_user_args():
|
|
if String(a).begins_with("--suite="):
|
|
only = String(a).trim_prefix("--suite=")
|
|
var t0 := Time.get_ticks_msec()
|
|
for path: String in SUITES:
|
|
if only != "" and path.get_file().get_basename() != only:
|
|
continue
|
|
current = path.get_file().get_basename()
|
|
print("== ", current)
|
|
var suite: Object = (load(path) as GDScript).new()
|
|
await suite.call("run", self)
|
|
print("TESTS: %d checks passed, %d failed (%.1f s)" % [passes, failures, (Time.get_ticks_msec() - t0) / 1000.0])
|
|
# Free whatever suites left behind and give the audio server a mix to drop stopped sounds.
|
|
for c in root.get_children():
|
|
c.queue_free()
|
|
await process_frame
|
|
await create_timer(0.25).timeout
|
|
quit(mini(failures, 125))
|
|
|
|
|
|
func check(cond: bool, message: String) -> void:
|
|
if cond:
|
|
passes += 1
|
|
else:
|
|
failures += 1
|
|
printerr(" FAIL [%s] %s" % [current, message])
|
|
|
|
|
|
func info(message: String) -> void:
|
|
print(" ", message)
|
|
|
|
|
|
## A campaign in the tree (so it is freed at exit) driven only by explicit tick() calls.
|
|
func make_campaign(cfg: GameConfig = null) -> CampaignController:
|
|
var c := CampaignController.new()
|
|
c.config = cfg
|
|
root.add_child(c)
|
|
c.set_physics_process(false)
|
|
return c
|
|
|
|
|
|
## Marks the next n crop units that are still on the farm as lost.
|
|
static func lose_crops(s: FarmState, n: int) -> void:
|
|
var id := 1
|
|
while n > 0 and id <= s.crops_total:
|
|
if s.lose_crop(id):
|
|
n -= 1
|
|
id += 1
|
|
|
|
|
|
## Ticks at 60 Hz until the phase changes; returns the game seconds that took (INF if it
|
|
## never changed within max_seconds).
|
|
static func run_phase(c: CampaignController, max_seconds: float = 1000.0) -> float:
|
|
var start := c.state.phase
|
|
var ticks := 0
|
|
while c.state.phase == start:
|
|
if ticks * TICK > max_seconds:
|
|
return INF
|
|
c.tick(TICK)
|
|
ticks += 1
|
|
return ticks * TICK
|
|
|
|
|
|
## Ticks at 60 Hz until the given phase is reached (or the campaign ends).
|
|
static func run_until(c: CampaignController, phase: CampaignController.Phase) -> void:
|
|
var guard := 0
|
|
while c.state.phase != phase and not c.is_over() and guard < 1000000:
|
|
if c.state.phase == CampaignController.Phase.MORNING:
|
|
c.begin_day()
|
|
else:
|
|
c.tick(TICK)
|
|
guard += 1
|