2026-08-12 23:08:43 +02:00
|
|
|
extends SceneTree
|
|
|
|
|
|
|
|
|
|
# Forgejo #23 + #25: the mothership hangar presents vessels by type, tapping
|
|
|
|
|
# an available type crews one, tapping a fleet type stores one, and contextual
|
|
|
|
|
# world buttons each get their own touch berth.
|
|
|
|
|
|
|
|
|
|
var game_state: Node
|
|
|
|
|
var scene: Node
|
|
|
|
|
var fleet: Node
|
|
|
|
|
var controller: Node
|
|
|
|
|
var stage: int = 0
|
|
|
|
|
var elapsed: float = 0.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _initialize() -> void:
|
|
|
|
|
game_state = root.get_node("GameState")
|
|
|
|
|
game_state.buildings.clear()
|
|
|
|
|
game_state.extractors.clear()
|
|
|
|
|
game_state.transporters.clear()
|
|
|
|
|
game_state.stored_vessels.clear()
|
|
|
|
|
game_state.rocks = 100
|
2026-09-05 17:09:27 +02:00
|
|
|
# #219: fleet capacity is built now - one berth free, one per Fleet
|
|
|
|
|
# Office. This test flies more than one vessel, so it needs the offices
|
|
|
|
|
# standing before the fleet spawns into them.
|
|
|
|
|
load("res://tests/_berths.gd").grant(root.get_node("GameState"), 6)
|
#84: move 215 root files into a folder hierarchy
Everything lived in one flat directory, so a diff gave no clue what area it
touched and finding the file you wanted meant knowing its exact name. Twelve
folders now, grouped by what a thing IS rather than what type it is - a
vessel's definition, its component scenes and its upgrade resources sit
together, because that is the set you read when you change one of them.
buildings core controllers enemies logistics planets
resources shaders surface ui vessels vfx world
332 files moved and every res:// reference rewritten - 306 files touched,
including the autoload and main-scene paths in project.godot. Nothing renamed:
this is purely where files sit, so the diff is a pile of pure moves and no
behaviour is buried in it. ui_theme.tres, icon.svg and web_shell.html stay at
the root, where Godot and the export preset expect them.
Verified three ways, because a suite alone would not have caught all of it:
the full 117 pass, the web export builds clean, and the game renders.
The export is why that matters. The FIRST export after the move failed with
"Attempt to open script 'res://GameState.gd'" - the old path - while
project.godot on disk plainly said res://core/GameState.gd. That is this
project's documented Android FUSE mtime trap: Godot served a cached copy of a
file whose content had changed. A `touch` fixed it. Nothing in the test suite
would have found that, because the suite runs from a copy on a native
filesystem - the one place the bug cannot happen.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 19:44:14 +02:00
|
|
|
scene = load("res://world/Main.tscn").instantiate()
|
2026-08-12 23:08:43 +02:00
|
|
|
root.add_child(scene)
|
|
|
|
|
fleet = scene.get_node("Fleet")
|
|
|
|
|
controller = scene.get_node("BuildController")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _process(delta: float) -> bool:
|
|
|
|
|
elapsed += delta
|
|
|
|
|
if stage == 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()
|
|
|
|
|
fleet.spawn_ships(1, Vector2.ZERO)
|
|
|
|
|
fleet.add_ship(GameState.VESSEL_SHIELD)
|
2026-08-15 00:09:10 +02:00
|
|
|
game_state.stored_vessels = [GameState.VESSEL_INTERCEPTOR, GameState.VESSEL_SHIELD,
|
|
|
|
|
GameState.VESSEL_TRANSPORTER]
|
2026-08-12 23:08:43 +02:00
|
|
|
controller._on_hangar_pressed()
|
|
|
|
|
elapsed = 0.0
|
|
|
|
|
stage = 1
|
|
|
|
|
return false
|
|
|
|
|
if stage == 1:
|
|
|
|
|
if elapsed < 0.2:
|
|
|
|
|
return false
|
|
|
|
|
# Available cards name the vessel and count what can be crewed.
|
2026-08-31 02:18:08 +02:00
|
|
|
var available_label: Label = controller.hangar_menu.available_labels[0]
|
2026-08-12 23:08:43 +02:00
|
|
|
if "Interceptor" not in available_label.text or "1 available" not in available_label.text:
|
|
|
|
|
_fail("available interceptor card says '%s'" % available_label.text)
|
|
|
|
|
return true
|
2026-08-15 00:09:10 +02:00
|
|
|
if controller._hangar_types().has(GameState.VESSEL_TRANSPORTER) \
|
|
|
|
|
or fleet.add_ship(GameState.VESSEL_TRANSPORTER):
|
|
|
|
|
_fail("a logistics transporter was exposed as a fleet vessel")
|
|
|
|
|
return true
|
2026-08-12 23:08:43 +02:00
|
|
|
controller._on_hangar_crew_type(0)
|
|
|
|
|
if fleet.ships.size() != 3 or game_state.stored_vessels.has(GameState.VESSEL_INTERCEPTOR):
|
|
|
|
|
_fail("tapping an available interceptor did not crew it")
|
|
|
|
|
return true
|
|
|
|
|
controller._on_hangar_store_type(1)
|
|
|
|
|
if fleet.ships.size() != 2 or not game_state.stored_vessels.has(GameState.VESSEL_SHIELD):
|
|
|
|
|
_fail("tapping the shield fleet card did not store it")
|
|
|
|
|
return true
|
|
|
|
|
# The safety rule prevents an empty deployed fleet.
|
|
|
|
|
controller._on_hangar_store_type(0)
|
|
|
|
|
controller._on_hangar_store_type(0)
|
|
|
|
|
if fleet.ships.size() != 1:
|
|
|
|
|
_fail("hangar allowed the last deployed ship to be stored")
|
|
|
|
|
return true
|
|
|
|
|
|
2026-08-14 23:15:12 +02:00
|
|
|
# Context actions are compact until expanded. A mothership unfolds
|
|
|
|
|
# research and hangar; transfer stays as a persistent shortcut beside
|
|
|
|
|
# Build and is not duplicated in the foldout.
|
#84: move 215 root files into a folder hierarchy
Everything lived in one flat directory, so a diff gave no clue what area it
touched and finding the file you wanted meant knowing its exact name. Twelve
folders now, grouped by what a thing IS rather than what type it is - a
vessel's definition, its component scenes and its upgrade resources sit
together, because that is the set you read when you change one of them.
buildings core controllers enemies logistics planets
resources shaders surface ui vessels vfx world
332 files moved and every res:// reference rewritten - 306 files touched,
including the autoload and main-scene paths in project.godot. Nothing renamed:
this is purely where files sit, so the diff is a pile of pure moves and no
behaviour is buried in it. ui_theme.tres, icon.svg and web_shell.html stay at
the root, where Godot and the export preset expect them.
Verified three ways, because a suite alone would not have caught all of it:
the full 117 pass, the web export builds clean, and the game renders.
The export is why that matters. The FIRST export after the move failed with
"Attempt to open script 'res://GameState.gd'" - the old path - while
project.godot on disk plainly said res://core/GameState.gd. That is this
project's documented Android FUSE mtime trap: Godot served a cached copy of a
file whose content had changed. A `touch` fixed it. Nothing in the test suite
would have found that, because the suite runs from a copy on a native
filesystem - the one place the bug cannot happen.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 19:44:14 +02:00
|
|
|
var mothership: Node2D = load("res://buildings/Building.tscn").instantiate()
|
2026-08-13 20:49:15 +02:00
|
|
|
mothership.set("building_type", GameState.BUILDING_MOTHERSHIP)
|
2026-08-14 22:12:57 +02:00
|
|
|
mothership._ready()
|
2026-08-13 20:49:15 +02:00
|
|
|
controller.current_building = mothership
|
|
|
|
|
controller.context_actions_expanded = true
|
2026-08-14 23:15:12 +02:00
|
|
|
controller.transfer_button.visible = controller._has_transfer_context()
|
2026-08-12 23:08:43 +02:00
|
|
|
controller._layout_context_buttons()
|
2026-08-14 23:15:12 +02:00
|
|
|
var buttons: Array = [controller.building_action_button, controller.hangar_button]
|
#228: shrink the HUD on a screen the canvas is short on
The layout is authored in CANVAS units. With stretch "canvas_items" and
aspect "expand" over a 1920x1080 base, a 720x1280 phone scales by 0.375 and
gets 1920x3413 canvas units - while ANY 16:9-or-wider screen lands on
1920x1080 units however many pixels it really has. The canvas is three times
shorter, so a 148-unit button went from 4.3% of the screen's height to
13.7%. Measured at 3.16x, and confirmed twice: once by hand off the scene
file, once by the test failing with the rule disabled.
Nothing collided. That was checked pair by pair on both canvases and the
same six pairs overlap on each, all of them same-slot alternatives. The
fault was only that everything was enormous.
HudScale captures each HUD control's authored offsets once, then moves it
toward the edge it hangs off and scales the NODE. Scaling the rect alone was
tried first and was wrong: half the HUD draws its own contents at fixed
sizes - ResourceReadout lays its rows out in code, Labels carry their own
font size - so shrunken boxes kept full-size content and the build button
slid up underneath the resource list. Scaling the node takes content and
children with it.
The cost is that position (parent space) and size (local space) now differ
by that scale, and a lot of code here assumed they did not. Five places:
ResourceReadout.content_bottom() added a scaled position to an unscaled
height, overstating itself by more than a button - so _seat_hud_columns
pushed the whole column down to clear space nothing occupied. A live bug,
not just a bad measurement.
HUD_COLUMN_MARGIN would have been the one gap still phone-sized.
_layout_context_buttons wrote its stride and pitch unscaled, landing the
action row on the building-action row - which is the second of the two
regressions test_hud_layout was written for, in a new disguise.
test_hud_layout and test_hangar_management compared authored rects.
And HudScale reapplies on resize, which wiped the two layouts BuildController
writes at runtime - so dragging a desktop window left the context row where
it was. Both re-run on size_changed now, deferred, because which of two
siblings connected first is not a thing to depend on.
test_hud_layout ran at one window shape, which happened to be the desktop
canvas. It now runs every check at both, so this cannot hide at whichever
shape was not being exercised.
Rejected: scaling the UI CanvasLayer does not work at all - Control anchors
resolve against the viewport rect, so bottom-anchored elements land
mid-screen. A single scaled wrapper Control with the HUD reparented under it
is the genuinely clean shape and would need no scale-aware arithmetic
anywhere, but it changes every node path and would break every get_node in
the controllers and tests.
MIN_SCALE floors the shrink at 0.45 rather than the proportional 0.316: a
landscape phone gets the same short canvas as a desktop, and there the
sticks are still thumb targets. That leaves the HUD at 1.42x its phone share
on a PC rather than 1.0x.
177/177 at JOBS=3.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019AJMdB7iuHuLFZM1aBu3GD
2026-09-12 18:04:00 +02:00
|
|
|
# Rendered width, not the authored rect: #228 shrinks the HUD on a
|
|
|
|
|
# short canvas by scaling the node and leaving its rect alone, so
|
|
|
|
|
# offset_right overstates where a button actually ends.
|
2026-08-12 23:08:43 +02:00
|
|
|
for i in range(buttons.size() - 1):
|
#228: shrink the HUD on a screen the canvas is short on
The layout is authored in CANVAS units. With stretch "canvas_items" and
aspect "expand" over a 1920x1080 base, a 720x1280 phone scales by 0.375 and
gets 1920x3413 canvas units - while ANY 16:9-or-wider screen lands on
1920x1080 units however many pixels it really has. The canvas is three times
shorter, so a 148-unit button went from 4.3% of the screen's height to
13.7%. Measured at 3.16x, and confirmed twice: once by hand off the scene
file, once by the test failing with the rule disabled.
Nothing collided. That was checked pair by pair on both canvases and the
same six pairs overlap on each, all of them same-slot alternatives. The
fault was only that everything was enormous.
HudScale captures each HUD control's authored offsets once, then moves it
toward the edge it hangs off and scales the NODE. Scaling the rect alone was
tried first and was wrong: half the HUD draws its own contents at fixed
sizes - ResourceReadout lays its rows out in code, Labels carry their own
font size - so shrunken boxes kept full-size content and the build button
slid up underneath the resource list. Scaling the node takes content and
children with it.
The cost is that position (parent space) and size (local space) now differ
by that scale, and a lot of code here assumed they did not. Five places:
ResourceReadout.content_bottom() added a scaled position to an unscaled
height, overstating itself by more than a button - so _seat_hud_columns
pushed the whole column down to clear space nothing occupied. A live bug,
not just a bad measurement.
HUD_COLUMN_MARGIN would have been the one gap still phone-sized.
_layout_context_buttons wrote its stride and pitch unscaled, landing the
action row on the building-action row - which is the second of the two
regressions test_hud_layout was written for, in a new disguise.
test_hud_layout and test_hangar_management compared authored rects.
And HudScale reapplies on resize, which wiped the two layouts BuildController
writes at runtime - so dragging a desktop window left the context row where
it was. Both re-run on size_changed now, deferred, because which of two
siblings connected first is not a thing to depend on.
test_hud_layout ran at one window shape, which happened to be the desktop
canvas. It now runs every check at both, so this cannot hide at whichever
shape was not being exercised.
Rejected: scaling the UI CanvasLayer does not work at all - Control anchors
resolve against the viewport rect, so bottom-anchored elements land
mid-screen. A single scaled wrapper Control with the HUD reparented under it
is the genuinely clean shape and would need no scale-aware arithmetic
anywhere, but it changes every node path and would break every get_node in
the controllers and tests.
MIN_SCALE floors the shrink at 0.45 rather than the proportional 0.316: a
landscape phone gets the same short canvas as a desktop, and there the
sticks are still thumb targets. That leaves the HUD at 1.42x its phone share
on a PC rather than 1.0x.
177/177 at JOBS=3.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019AJMdB7iuHuLFZM1aBu3GD
2026-09-12 18:04:00 +02:00
|
|
|
var ends: float = buttons[i].offset_left + buttons[i].size.x * buttons[i].scale.x
|
|
|
|
|
if ends > buttons[i + 1].offset_left:
|
2026-08-12 23:08:43 +02:00
|
|
|
_fail("context buttons %d and %d overlap" % [i, i + 1])
|
|
|
|
|
return true
|
2026-08-13 20:49:15 +02:00
|
|
|
controller._collapse_context_actions()
|
2026-08-14 23:15:12 +02:00
|
|
|
if controller.building_action_button.visible or controller.hangar_button.visible:
|
2026-08-13 20:49:15 +02:00
|
|
|
_fail("collapsing the context button left an action visible")
|
|
|
|
|
return true
|
2026-08-14 23:15:12 +02:00
|
|
|
if not controller.transfer_button.visible \
|
|
|
|
|
or controller.transfer_button.offset_top != controller.build_button.offset_top \
|
|
|
|
|
or controller.transfer_button.offset_left <= controller.build_button.offset_left:
|
|
|
|
|
_fail("transfer shortcut is not beside Build")
|
|
|
|
|
return true
|
2026-08-13 20:49:15 +02:00
|
|
|
mothership.free()
|
|
|
|
|
print("hangar crews and stores typed vessels; contextual actions expand and collapse")
|
2026-08-12 23:08:43 +02:00
|
|
|
print("TEST_HANGAR_MANAGEMENT: PASS")
|
|
|
|
|
quit(0)
|
|
|
|
|
return true
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _fail(message: String) -> void:
|
|
|
|
|
print("TEST_HANGAR_MANAGEMENT: FAIL (%s)" % message)
|
|
|
|
|
quit(1)
|