45 lines
1.6 KiB
GDScript
45 lines
1.6 KiB
GDScript
extends SceneTree
|
|
|
|
const BUILDING_DEFINITIONS = preload("res://buildings/BuildingDefinitions.gd")
|
|
|
|
|
|
func _initialize() -> void:
|
|
var scene: PackedScene = load("res://buildings/Building.tscn")
|
|
for definition in BUILDING_DEFINITIONS.all():
|
|
if definition.placement_mode != "space":
|
|
continue
|
|
var building: Node2D = scene.instantiate()
|
|
building.definition_id = definition.definition_id
|
|
building._ready()
|
|
if building.definition == null \
|
|
or building.definition.definition_id != definition.definition_id \
|
|
or building.visual == null:
|
|
_fail("%s did not compose its definition and visual (resolved=%s visual=%s)" % [
|
|
definition.definition_id,
|
|
"null" if building.definition == null else building.definition.definition_id,
|
|
building.visual,
|
|
])
|
|
return
|
|
var provider: Node = building.visual.get_node_or_null("ActionProvider")
|
|
if "transport_hub" in definition.capabilities:
|
|
if provider != null or not building.available_actions().is_empty():
|
|
_fail("transport hub composed a manual action")
|
|
return
|
|
elif "planet_scanner" in definition.capabilities:
|
|
if provider == null or not provider.actions.has("scanner") \
|
|
or provider.actions.has("transfer"):
|
|
_fail("%s did not compose its scanner-only action" \
|
|
% definition.definition_id)
|
|
return
|
|
elif provider == null or not provider.actions.has("transfer"):
|
|
_fail("%s has no composed transfer action" % definition.definition_id)
|
|
return
|
|
building.free()
|
|
|
|
print("TEST_BUILDING_COMPOSITION: PASS")
|
|
quit(0)
|
|
|
|
|
|
func _fail(message: String) -> void:
|
|
print("TEST_BUILDING_COMPOSITION: FAIL (%s)" % message)
|
|
quit(1)
|