2026-09-20 20:56:15 +03:00
|
|
|
extends SceneTree
|
|
|
|
|
const Clock = preload("res://world/owniverse/simulation_time.gd")
|
|
|
|
|
var checks: int = 0
|
|
|
|
|
var failures: int = 0
|
|
|
|
|
|
|
|
|
|
func _initialize() -> void:
|
|
|
|
|
call_deferred("run")
|
|
|
|
|
|
|
|
|
|
func check(condition: bool, message: String) -> void:
|
|
|
|
|
checks += 1
|
|
|
|
|
if not condition:
|
|
|
|
|
failures += 1
|
|
|
|
|
push_error(message)
|
|
|
|
|
|
|
|
|
|
func fixture():
|
|
|
|
|
var world = load("res://world/owniverse/owniverse.gd").new()
|
|
|
|
|
var global: Node = root.get_node("Global")
|
|
|
|
|
for id in global.OwniverseEntities:
|
|
|
|
|
var entity = load("res://world/owniverse/owniverse_entity.gd").new(global.OwniverseEntities[id])
|
2026-09-29 20:23:20 +03:00
|
|
|
world.catalog.entities[id] = entity
|
2026-09-20 20:56:15 +03:00
|
|
|
world.state.amount[id] = 0.0
|
|
|
|
|
world.state.stats.total_amount[id] = 0.0
|
|
|
|
|
if entity.group_as != "":
|
|
|
|
|
world.state.amount[entity.group_as] = 0.0
|
|
|
|
|
world.state.stats.total_amount[entity.group_as] = 0.0
|
2026-09-29 20:23:20 +03:00
|
|
|
world.catalog.entities["N"].life_product = {}
|
|
|
|
|
world.catalog.entities["N"].product_per_year_type = "H"
|
|
|
|
|
world.catalog.entities["N"].product_per_year_amount = 10.0
|
|
|
|
|
world.catalog.entities["N"].auto = 0.0
|
2026-09-20 20:56:15 +03:00
|
|
|
world.state.amount.N = 1.0
|
|
|
|
|
return world
|
|
|
|
|
|
|
|
|
|
func dispose(world) -> void:
|
2026-09-29 20:23:20 +03:00
|
|
|
for entity in world.catalog.entities.values():
|
2026-09-20 20:56:15 +03:00
|
|
|
entity.free()
|
|
|
|
|
world.free()
|
|
|
|
|
|
|
|
|
|
func run() -> void:
|
|
|
|
|
var world = fixture()
|
2026-09-29 20:23:20 +03:00
|
|
|
for id in world.catalog.entities:
|
2026-09-20 20:56:15 +03:00
|
|
|
var expected: Array = []
|
2026-09-29 20:23:20 +03:00
|
|
|
for key in world.catalog.entities:
|
|
|
|
|
if world.catalog.entities[key].group_as == id:
|
2026-09-20 20:56:15 +03:00
|
|
|
expected.append(key)
|
2026-09-29 20:23:20 +03:00
|
|
|
check(world.catalog.is_group(id) == (not expected.is_empty()), "Group classification: " + id)
|
|
|
|
|
check(world.catalog.members(id) == (expected if not expected.is_empty() else [id]), "Group members: " + id)
|
|
|
|
|
var members: Array = world.catalog.members("Star")
|
2026-09-20 20:56:15 +03:00
|
|
|
members.clear()
|
2026-09-29 20:23:20 +03:00
|
|
|
check(not world.catalog.members("Star").is_empty(), "Returned members are independent")
|
|
|
|
|
world.catalog.entities.N.group_as = "TestGroup"
|
|
|
|
|
world.catalog.rebuild_group_index()
|
|
|
|
|
check(world.catalog.members("TestGroup") == ["N"], "Explicit definition reload")
|
|
|
|
|
world.catalog.entities.N.free()
|
|
|
|
|
world.catalog.entities.erase("N")
|
|
|
|
|
check(not world.catalog.is_group("TestGroup"), "Removed definition invalidates index")
|
2026-09-20 20:56:15 +03:00
|
|
|
print("Group index: %d checks, %d failures" % [checks, failures])
|
|
|
|
|
dispose(world)
|
|
|
|
|
quit(1 if failures else 0)
|