spaceship/tests/test_vessel_composition.gd
Loïc Wisniewski 2f161621c3 #84: move 215 root files into a folder hierarchy
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>
2026-08-21 19:44:14 +02:00

63 lines
2.7 KiB
GDScript

extends SceneTree
const VESSEL_DEFINITIONS = preload("res://vessels/VesselDefinitions.gd")
var ships: Array = []
var elapsed: float = 0.0
var game_state: Node
func _initialize() -> void:
game_state = root.get_node("GameState")
var scene: PackedScene = load("res://vessels/Ship.tscn")
for definition in VESSEL_DEFINITIONS.all():
var ship: Area2D = scene.instantiate()
ship.vessel_type = definition.definition_id
root.add_child(ship)
ships.append(ship)
func _process(delta: float) -> bool:
elapsed += delta
if elapsed < 0.1:
return false
var definitions: Array = VESSEL_DEFINITIONS.all()
var fleet_definitions: Array = VESSEL_DEFINITIONS.fleet()
if fleet_definitions.any(func(definition): return definition.has_capability("transport")):
return _fail("logistics transporters leaked into the combat-fleet catalog")
if ships.size() != definitions.size():
return _fail("catalog and composed fleet differ in size")
for i in range(definitions.size()):
var definition: Resource = definitions[i]
var ship: Node = ships[i]
if ship.definition == null or ship.definition.definition_id != definition.definition_id:
return _fail("%s did not resolve its definition" % definition.definition_id)
for capability in definition.capabilities:
if not ship.has_capability(capability):
return _fail("%s did not compose %s" % [definition.definition_id, capability])
if game_state.product_cost(definition.definition_id) != definition.build_cost \
or game_state.vessel_name(definition.definition_id) != definition.display_name:
return _fail("%s metadata did not come from its definition" % definition.definition_id)
if ships[0].has_capability("shield") or not ships[1].has_capability("shield"):
return _fail("shield behavior is not controlled by component presence")
if (ships[1].has_capability("weapon")
or definitions[1].hull_points.size() != 6
or definitions[1].icon != IconButton.Icon.SHIELD_VESSEL):
return _fail("shield vessel is not an unarmed hexagon")
var gas_index: int = VESSEL_DEFINITIONS.ORDER.find(GameState.VESSEL_GAS_BOMBER)
if gas_index < 0 or ships[gas_index].has_capability("weapon") \
or not ships[gas_index].definition.has_capability("gas_bomber"):
return _fail("gas bomber is not an unarmed skill vessel")
var transporter_index: int = VESSEL_DEFINITIONS.ORDER.find(GameState.VESSEL_TRANSPORTER)
if ships[transporter_index].has_capability("weapon") \
or not ships[transporter_index].has_capability("transport"):
return _fail("transporter capabilities were composed incorrectly")
print("TEST_VESSEL_COMPOSITION: PASS")
quit(0)
return true
func _fail(message: String) -> bool:
print("TEST_VESSEL_COMPOSITION: FAIL (%s)" % message)
quit(1)
return true