spaceship/tests/test_planet_unique_identity.gd

39 lines
1.3 KiB
GDScript3
Raw Normal View History

extends SceneTree
func _initialize() -> void:
var state: Node = root.get_node("GameState")
state.extractors.clear()
var first_by_name: Dictionary = {}
var first: Dictionary = {}
var second: Dictionary = {}
for x in range(-60, 61):
for y in range(-60, 61):
var chunk := Vector2i(x, y)
if not WorldGen.has_planet_at_chunk(chunk):
continue
var data: Dictionary = WorldGen.planet_data_at_chunk(chunk)
if first_by_name.has(data.name):
first = first_by_name[data.name]
second = data
break
first_by_name[data.name] = data
if not second.is_empty():
break
if second.is_empty():
return _fail("could not find two generated planets sharing a display name")
if first.planet_id == second.planet_id:
return _fail("duplicate display names also shared a stable id")
state.add_extractor(first.name, Vector2.ZERO, "ore", first.planet_id)
if not state.has_extractor_at(first.planet_id):
return _fail("extractor was not attached to its planet id")
if state.has_extractor_at(second.planet_id):
return _fail("'%s' inherited an extractor from its namesake" % second.name)
print("same name '%s', distinct ids %s and %s" % [first.name, first.planet_id, second.planet_id])
print("TEST_PLANET_UNIQUE_IDENTITY: PASS")
quit(0)
func _fail(message: String) -> void:
print("TEST_PLANET_UNIQUE_IDENTITY: FAIL (%s)" % message)
quit(1)