2026-08-14 22:12:57 +02:00
|
|
|
extends SceneTree
|
|
|
|
|
|
|
|
|
|
const VESSEL_DEFINITIONS = preload("res://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://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()
|
|
|
|
|
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")
|
2026-08-14 22:46:30 +02:00
|
|
|
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")
|
2026-08-14 22:12:57 +02:00
|
|
|
if ships[2].has_capability("weapon") or not ships[2].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
|