117 lines
3.8 KiB
GDScript3
117 lines
3.8 KiB
GDScript3
|
|
extends SceneTree
|
||
|
|
|
||
|
|
# Headless gameplay test: run with
|
||
|
|
# godot --headless -s res://tests/test_cargo_readout.gd
|
||
|
|
# Forgejo #15 (part 2 of #12): what the fleet is carrying has to be visible
|
||
|
|
# separately from what is banked.
|
||
|
|
#
|
||
|
|
# Since #14, ore is cargo until the fleet delivers it to the mothership. The
|
||
|
|
# banked readout does not move on pickup, so without a second readout mining
|
||
|
|
# looks broken - you gather ore and no number on screen changes.
|
||
|
|
#
|
||
|
|
# --headless has no GPU and draws no pixels, so this asserts on the two
|
||
|
|
# readouts' state, not on their appearance. tests/screenshot.sh covers
|
||
|
|
# whether they are legible.
|
||
|
|
#
|
||
|
|
# Verifies:
|
||
|
|
# 1. the banked readout keeps showing the BANK, not the total
|
||
|
|
# 2. the cargo readout shows the hold, and appears only while carrying
|
||
|
|
# 3. an empty hold hides it rather than parking a permanent 0 beside the
|
||
|
|
# real total
|
||
|
|
# 4. delivering moves the number from one readout to the other
|
||
|
|
# 5. the two are actually told apart on screen, rather than being the same
|
||
|
|
# number twice in the same colour at the same place
|
||
|
|
|
||
|
|
var game_state: Node
|
||
|
|
var scene: Node
|
||
|
|
var banked: Control
|
||
|
|
var cargo: Control
|
||
|
|
var stage: int = 0
|
||
|
|
var elapsed: float = 0.0
|
||
|
|
|
||
|
|
|
||
|
|
func _initialize() -> void:
|
||
|
|
game_state = root.get_node("GameState")
|
||
|
|
game_state.buildings.clear()
|
||
|
|
game_state.extractors.clear()
|
||
|
|
game_state.rocks = 42
|
||
|
|
game_state.fleet_cargo = 0
|
||
|
|
scene = load("res://Main.tscn").instantiate()
|
||
|
|
root.add_child(scene)
|
||
|
|
banked = scene.get_node("UI/ResourceCounter")
|
||
|
|
cargo = scene.get_node("UI/CargoCounter")
|
||
|
|
|
||
|
|
|
||
|
|
func _process(delta: float) -> bool:
|
||
|
|
elapsed += delta
|
||
|
|
match stage:
|
||
|
|
0:
|
||
|
|
if elapsed < 0.2:
|
||
|
|
return false
|
||
|
|
# --- 3. nothing carried -> no cargo readout -----------------
|
||
|
|
if cargo.visible:
|
||
|
|
print("TEST_CARGO_READOUT: FAIL (cargo readout showing with an empty hold)")
|
||
|
|
quit(1)
|
||
|
|
return true
|
||
|
|
if banked.amount != 42:
|
||
|
|
print("TEST_CARGO_READOUT: FAIL (banked readout shows %d, bank is 42)" % banked.amount)
|
||
|
|
quit(1)
|
||
|
|
return true
|
||
|
|
print("empty hold -> cargo readout hidden, banked shows %d" % banked.amount)
|
||
|
|
|
||
|
|
game_state.collect_cargo(7)
|
||
|
|
elapsed = 0.0
|
||
|
|
stage = 1
|
||
|
|
return false
|
||
|
|
1:
|
||
|
|
if elapsed < 0.2:
|
||
|
|
return false
|
||
|
|
# --- 1 + 2. carried and banked are separate numbers ---------
|
||
|
|
if not cargo.visible:
|
||
|
|
print("TEST_CARGO_READOUT: FAIL (carrying 7 and the cargo readout is hidden)")
|
||
|
|
quit(1)
|
||
|
|
return true
|
||
|
|
if cargo.amount != 7:
|
||
|
|
print("TEST_CARGO_READOUT: FAIL (cargo readout shows %d, hold is 7)" % cargo.amount)
|
||
|
|
quit(1)
|
||
|
|
return true
|
||
|
|
if banked.amount != 42:
|
||
|
|
print("TEST_CARGO_READOUT: FAIL (banked readout moved to %d on a pickup - it is showing the total, not the bank)" % banked.amount)
|
||
|
|
quit(1)
|
||
|
|
return true
|
||
|
|
print("carrying 7 -> cargo=%d banked=%d" % [cargo.amount, banked.amount])
|
||
|
|
|
||
|
|
# --- 5. genuinely distinguishable ---------------------------
|
||
|
|
if cargo.glow_color == banked.glow_color:
|
||
|
|
print("TEST_CARGO_READOUT: FAIL (both readouts drawn in the same colour)")
|
||
|
|
quit(1)
|
||
|
|
return true
|
||
|
|
if cargo.position == banked.position:
|
||
|
|
print("TEST_CARGO_READOUT: FAIL (both readouts in the same place)")
|
||
|
|
quit(1)
|
||
|
|
return true
|
||
|
|
print("distinct: colours %s vs %s, at %s vs %s" % [
|
||
|
|
cargo.glow_color, banked.glow_color, cargo.position, banked.position
|
||
|
|
])
|
||
|
|
|
||
|
|
# --- 4. delivery moves it across ----------------------------
|
||
|
|
game_state.deliver_cargo()
|
||
|
|
elapsed = 0.0
|
||
|
|
stage = 2
|
||
|
|
return false
|
||
|
|
2:
|
||
|
|
if elapsed < 0.2:
|
||
|
|
return false
|
||
|
|
if cargo.visible:
|
||
|
|
print("TEST_CARGO_READOUT: FAIL (cargo readout still showing after delivery)")
|
||
|
|
quit(1)
|
||
|
|
return true
|
||
|
|
if banked.amount != 49:
|
||
|
|
print("TEST_CARGO_READOUT: FAIL (banked shows %d after delivering 7 into 42)" % banked.amount)
|
||
|
|
quit(1)
|
||
|
|
return true
|
||
|
|
print("delivered -> cargo hidden, banked shows %d" % banked.amount)
|
||
|
|
print("TEST_CARGO_READOUT: PASS")
|
||
|
|
quit(0)
|
||
|
|
return true
|
||
|
|
return false
|