Restore the crafter binding lost in an over-wide edit

This is the actual cause of "the build a ship menu buttons do nothing",
reported four times. Opening the crafter panel stopped recording WHICH
crafter: when the auto-unload was replaced with an explicit store button,
the replaced block reached one line further up than intended and took
`craft_building_id = current_building.building_id` with it. Every handler
in the panel then bailed out at its `if craft_building_id == 0` guard,
while the panel itself still opened and Close still worked - because
Close is the only button that does not need the binding.

The silent `return` on that guard is what let it pass unnoticed, so it
now says so instead.

The test was complicit: it set craft_building_id by hand, which skipped
the exact step that was broken. It now parks the fleet on the crafter,
waits for the action button to debounce in, and presses it - the way the
game does. Verified against the broken code: it fails with
"opening the panel did not record which crafter".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Loïc Wisniewski 2026-08-11 23:55:12 +02:00
commit fe1c721d64
2 changed files with 52 additions and 4 deletions

View file

@ -20,11 +20,20 @@ extends SceneTree
# overwritten on the very next frame, which is what made a working
# button look dead
# 5. the message is the FIRST line, not buried under the standing state
# 6. the panel is opened the way the GAME opens it - park the fleet on the
# crafter and press the action button - and every button then works
#
# Point 6 exists because this test used to set craft_building_id by hand.
# That skipped the one step that was actually broken: opening the panel
# stopped recording WHICH crafter, so every handler bailed out at its `== 0`
# guard while the panel still opened. Reported four times as "the buttons do
# nothing", and invisible to every test that set the id itself.
var game_state: Node
var scene: Node
var controller: Node
var crafter_id: int = 0
var fleet: Node
var stage: int = 0
var elapsed: float = 0.0
@ -42,6 +51,15 @@ func _initialize() -> void:
scene = load("res://Main.tscn").instantiate()
root.add_child(scene)
controller = scene.get_node("BuildController")
fleet = scene.get_node("Fleet")
func _tap(button: Control) -> void:
for pressed in [true, false]:
var ev: InputEventScreenTouch = InputEventScreenTouch.new()
ev.pressed = pressed
ev.position = button.size / 2.0
button._gui_input(ev)
func _first_line() -> String:
@ -54,17 +72,37 @@ func _process(delta: float) -> bool:
0:
scene.get_node("AsteroidField").set_process(false)
scene.get_node("EnemySpawner").set_process(false)
for a in get_nodes_in_group("asteroids"):
if is_instance_valid(a):
a.queue_free()
scene.get_node("BuildingField").place(GameState.BUILDING_SHIP_CRAFTER, Vector2(500.0, 0.0))
crafter_id = int(game_state.buildings[-1].id)
# Park the fleet ON it and let the action button debounce in.
for ship in fleet.ships:
ship.position = Vector2(500.0, 0.0)
fleet.move_to(Vector2(500.0, 0.0))
elapsed = 0.0
stage = 1
return false
1:
if elapsed < 0.3:
if elapsed < 1.2:
return false
controller.craft_building_id = crafter_id
controller.craft_menu.visible = true
controller._refresh_craft_status()
# --- 6. open it the way the game does ------------------------
if controller.current_building == null:
print("TEST_CRAFTER_FEEDBACK: FAIL (fleet parked on the crafter never registered)")
quit(1)
return true
_tap(controller.action_button)
if not controller.craft_menu.visible:
print("TEST_CRAFTER_FEEDBACK: FAIL (the action button did not open the crafter panel)")
quit(1)
return true
if controller.craft_building_id != crafter_id:
print("craft_building_id=%d, crafter is %d" % [controller.craft_building_id, crafter_id])
print("TEST_CRAFTER_FEEDBACK: FAIL (opening the panel did not record which crafter - every button will bail out)")
quit(1)
return true
print("panel opened from the building, bound to crafter %d" % controller.craft_building_id)
# --- 1. store with an empty hold ----------------------------
controller._on_store_ore()