Everything lived in one flat directory, so a diff gave no clue what area it touched and finding the file you wanted meant knowing its exact name. Twelve folders now, grouped by what a thing IS rather than what type it is - a vessel's definition, its component scenes and its upgrade resources sit together, because that is the set you read when you change one of them. buildings core controllers enemies logistics planets resources shaders surface ui vessels vfx world 332 files moved and every res:// reference rewritten - 306 files touched, including the autoload and main-scene paths in project.godot. Nothing renamed: this is purely where files sit, so the diff is a pile of pure moves and no behaviour is buried in it. ui_theme.tres, icon.svg and web_shell.html stay at the root, where Godot and the export preset expect them. Verified three ways, because a suite alone would not have caught all of it: the full 117 pass, the web export builds clean, and the game renders. The export is why that matters. The FIRST export after the move failed with "Attempt to open script 'res://GameState.gd'" - the old path - while project.godot on disk plainly said res://core/GameState.gd. That is this project's documented Android FUSE mtime trap: Godot served a cached copy of a file whose content had changed. A `touch` fixed it. Nothing in the test suite would have found that, because the suite runs from a copy on a native filesystem - the one place the bug cannot happen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
149 lines
5.9 KiB
GDScript
149 lines
5.9 KiB
GDScript
extends SceneTree
|
|
|
|
# Headless gameplay test: run with
|
|
# godot --headless -s res://tests/test_laser_ammo.gd
|
|
# Forgejo #61: laser shots draw ammunition from the FLEET HOLD
|
|
# (GameState.fleet_inventory), the same way gas bomb shots do (#60) - the
|
|
# fleet has to be carrying its own energy.
|
|
#
|
|
# Covers:
|
|
# A. banked energy does not enable firing - only the fleet hold counts
|
|
# B. with insufficient fleet energy the button is disabled, pressing it
|
|
# explains why, and no beam is fired / no cooldown consumed
|
|
# C. firing drains exactly ENERGY_PER_SHOT from the fleet hold and
|
|
# nothing from the bank
|
|
|
|
var game_state: Node
|
|
var main: Node
|
|
var fleet: Node
|
|
var skill: Node
|
|
var laser_component: Node
|
|
var stage: int = 0
|
|
var elapsed: float = 0.0
|
|
|
|
# Mirrors LaserController.ENERGY_PER_SHOT's value rather than referencing
|
|
# the class constant directly - a bare ClassName.CONST reference elsewhere
|
|
# in a test script has been observed to corrupt method resolution for the
|
|
# WHOLE script (an unrelated skill._process() call earlier in the same
|
|
# file then fails with "Nonexistent function '_process' in base 'Nil'"),
|
|
# root cause unconfirmed. See tests/test_gas_bomber_cooldowns.gd's
|
|
# identical fix (#60).
|
|
const ENERGY_PER_SHOT: int = 8
|
|
|
|
|
|
func _initialize() -> void:
|
|
game_state = root.get_node("GameState")
|
|
game_state.buildings.clear()
|
|
game_state.extractors.clear()
|
|
game_state.transporters.clear()
|
|
game_state.stored_vessels.clear()
|
|
game_state.reset_progression()
|
|
game_state.vessel_levels["unlock_laser"] = 1
|
|
game_state.rocks = 0
|
|
game_state.gas = 0
|
|
game_state.fleet_gas_cargo = 0
|
|
main = load("res://world/Main.tscn").instantiate()
|
|
root.add_child(main)
|
|
fleet = main.get_node("Fleet")
|
|
skill = main.get_node("LaserController")
|
|
|
|
|
|
func _process(delta: float) -> bool:
|
|
elapsed += delta
|
|
match stage:
|
|
0:
|
|
if elapsed < 0.2:
|
|
return false
|
|
main.get_node("EnemySpawner").set_process(false)
|
|
main.get_node("AsteroidField").set_process(false)
|
|
# Asteroids are shootable now, and the laser and the bomb both
|
|
# sweep them alongside enemies - so whatever the field already
|
|
# spawned would be counted as a hit. Silencing the spawner is not
|
|
# enough; what it placed before that has to go too. Same
|
|
# clean-slate idiom as test_ship_lab.gd.
|
|
for hazard in get_nodes_in_group("asteroids"):
|
|
if is_instance_valid(hazard):
|
|
hazard.free()
|
|
# An interceptor rides along purely for its "cargo" capability
|
|
# (#56): a fleet made only of a laser ship has zero cargo
|
|
# capacity, which would silently clamp every fleet energy
|
|
# deposit below to 0.
|
|
fleet.spawn_ships(2, Vector2.ZERO, PackedStringArray([
|
|
GameState.VESSEL_INTERCEPTOR, GameState.VESSEL_LASER]))
|
|
laser_component = fleet.ships[1].get_component("laser")
|
|
skill._process(0.0)
|
|
|
|
# --- A. bank energy does not count ----------------------------
|
|
game_state.deposit_bank_resource(GameState.RESOURCE_ENERGY, 500)
|
|
skill._process(0.0)
|
|
if skill.button.enabled:
|
|
return _fail_now("500 banked energy (0 in the fleet hold) left the control enabled")
|
|
print("500 banked energy, 0 fleet energy: control correctly disabled")
|
|
|
|
# --- B. insufficient fleet energy -------------------------------
|
|
game_state.deposit_fleet_resource(GameState.RESOURCE_ENERGY, ENERGY_PER_SHOT - 1)
|
|
skill._process(0.0)
|
|
if skill.button.enabled:
|
|
return _fail_now("fleet energy one short of ENERGY_PER_SHOT left the control enabled")
|
|
|
|
var press := InputEventScreenTouch.new()
|
|
press.index = 3
|
|
press.position = skill.button.global_position + skill.button.size * 0.5
|
|
press.pressed = true
|
|
main._handle_touch(press)
|
|
if skill.aiming:
|
|
return _fail_now("aiming began despite insufficient fleet energy")
|
|
if skill.status.text == "":
|
|
return _fail_now("an unaffordable press did not explain itself")
|
|
print("insufficient fleet energy: disabled, press explains itself, no aiming began")
|
|
if not laser_component.is_ready():
|
|
return _fail_now("a refused press consumed the laser ship's cooldown")
|
|
if game_state.fleet_resource(GameState.RESOURCE_ENERGY) != ENERGY_PER_SHOT - 1:
|
|
return _fail_now("a refused press spent fleet energy anyway")
|
|
print("no cooldown consumed, no energy spent on a refused press")
|
|
|
|
# --- C. exact ammo cost on a real shot -----------------------------
|
|
game_state.deposit_fleet_resource(GameState.RESOURCE_ENERGY, 8)
|
|
skill._process(0.0)
|
|
if not skill.button.enabled:
|
|
return _fail_now("enough fleet energy still left the control disabled")
|
|
var fleet_energy_before: int = game_state.fleet_resource(GameState.RESOURCE_ENERGY)
|
|
|
|
var press2 := InputEventScreenTouch.new()
|
|
press2.index = 4
|
|
press2.position = skill.button.global_position + skill.button.size * 0.5
|
|
press2.pressed = true
|
|
main._handle_touch(press2)
|
|
if not skill.aiming:
|
|
return _fail_now("an affordable press did not begin aiming")
|
|
var drag := InputEventScreenDrag.new()
|
|
drag.index = 4
|
|
drag.position = press2.position + Vector2(-300.0, 0.0)
|
|
main._handle_drag(drag)
|
|
var release := InputEventScreenTouch.new()
|
|
release.index = 4
|
|
release.position = drag.position
|
|
release.pressed = false
|
|
main._handle_touch(release)
|
|
|
|
if laser_component.is_ready():
|
|
return _fail_now("firing did not consume the laser ship's cooldown")
|
|
var fleet_energy_after: int = game_state.fleet_resource(GameState.RESOURCE_ENERGY)
|
|
if fleet_energy_before - fleet_energy_after != ENERGY_PER_SHOT:
|
|
return _fail_now("firing spent %d fleet energy, expected exactly %d" \
|
|
% [fleet_energy_before - fleet_energy_after, ENERGY_PER_SHOT])
|
|
if game_state.banked_resource(GameState.RESOURCE_ENERGY) != 500:
|
|
return _fail_now("firing touched the bank (%d), expected it untouched at 500" \
|
|
% game_state.banked_resource(GameState.RESOURCE_ENERGY))
|
|
print("firing drained exactly %d from the fleet hold, bank untouched" % ENERGY_PER_SHOT)
|
|
|
|
print("TEST_LASER_AMMO: PASS")
|
|
quit(0)
|
|
return true
|
|
return false
|
|
|
|
|
|
func _fail_now(message: String) -> bool:
|
|
print("TEST_LASER_AMMO: FAIL (%s)" % message)
|
|
quit(1)
|
|
return true
|