Key extractors by stable planet identity

This commit is contained in:
Loïc Wisniewski 2026-08-14 22:16:40 +02:00
commit e2d4297ee5
11 changed files with 71 additions and 16 deletions

View file

@ -135,7 +135,7 @@ func _process(delta: float) -> bool:
return true
controller._confirm_build()
var built: bool = game_state.has_extractor_at(planet2.planet_name)
var built: bool = game_state.has_extractor_at(planet2.planet_id)
var charged: bool = game_state.rocks == rocks_before - GameState.EXTRACTOR_COST
print("over planet '%s': enabled=%s built=%s rocks %d->%d charged=%s" % [
planet2.planet_name, button.enabled, built, rocks_before, game_state.rocks, charged

View file

@ -28,6 +28,7 @@ var scene: Node
var map_content: Node2D
var planet_chunk: Vector2i
var planet_name: String = ""
var planet_id: String = ""
var stage: int = 0
var already_spawned: Node2D
@ -43,7 +44,9 @@ func _initialize() -> void:
var chunk: Vector2i = Vector2i(x, y)
if WorldGen.has_planet_at_chunk(chunk):
planet_chunk = chunk
planet_name = WorldGen.planet_data_at_chunk(chunk).name
var data: Dictionary = WorldGen.planet_data_at_chunk(chunk)
planet_name = data.name
planet_id = data.planet_id
found = true
break
if found:
@ -61,6 +64,7 @@ func _initialize() -> void:
func _spawn_planet() -> Node2D:
var planet: Node2D = load("res://Planet.tscn").instantiate()
planet.planet_name = planet_name
planet.planet_id = planet_id
planet.shape_seed = 12345
scene.add_child(planet)
return planet
@ -90,7 +94,7 @@ func _process(_delta: float) -> bool:
# having done nothing at all. Spawning a fresh planet afterwards
# (as the checks below do) cannot catch that.
already_spawned = clean
game_state.add_extractor(planet_name, WorldGen.chunk_origin(planet_chunk))
game_state.add_extractor(planet_name, WorldGen.chunk_origin(planet_chunk), "ore", planet_id)
stage = 1
return false
1:
@ -141,6 +145,7 @@ func _process(_delta: float) -> bool:
# by name, and getting that wrong would light up every planet.
var other: Node2D = load("res://Planet.tscn").instantiate()
other.planet_name = planet_name + " II"
other.planet_id = planet_id + ":other"
other.shape_seed = 999
scene.add_child(other)
if other.shows_extractor:

View file

@ -0,0 +1,39 @@
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)