spaceship/ui/NeonNumber.gd

92 lines
3.4 KiB
GDScript3
Raw Permalink Normal View History

class_name NeonNumber
extends Control
# An ore amount drawn in the game's own hand-stroked style: the resource
# hexagon followed by segment-drawn digits. Godot's default Label font has
# no place in this look, which is why the digits are strokes rather than
# text.
#
Generalize the resource HUD readouts (#49) Replaces ResourceCounter/GasCounter/CargoCounter/GasCargoCounter - one hardcoded node plus one script per resource, times two scenes - with a single ResourceReadout.gd that builds one banked + one fleet-hold row per GameState.resource_types() entry at _ready(). A new resource added to ResourceDefinitions gets a HUD row with no scene edit and no new script, matching how ResourceBar and ResourceTransferList already generalize over resources. Preserves the existing visual layout (BANKED left, FLEET HOLD right), the ore-on-bright-surface contrast (via a bright_background flag replacing PlanetSurface's per-node color overrides), and the amber fleet-in-transit color convention. Reuses the already-generic ResourceGlyph for icons instead of NeonNumber's hardcoded ore hexagon. Uncovered and fixed a second bug along the way: test_cargo_readout.gd looked up its NeonNumber nodes immediately after add_child() in _initialize(), but ResourceReadout builds its rows in _ready(), which for a -s entry-point script does not fire synchronously during that add_child() - it's deferred to the first frame. Moved the lookup to after the existing elapsed wait in _process(), which is also what tests/test_resource_readout.gd's setup does from the start. Repo notes for the next agent, confirmed empirically this session: - A -s entry-point script can only reach an autoload's CONSTANTS via the bare identifier (GameState.RESOURCE_ORE works everywhere). Calling any of its METHODS that way (GameState.resource_types()) fails to compile with "Identifier not found: GameState", even from _initialize(). Route method calls through the actual instance (root.get_node("GameState")) instead, as the rest of the suite already does. - `git status --short | awk '{print $2}' | xargs touch` recreates deleted files as empty stubs, since touch on a missing path creates it. Filter out D-status paths before touching, or touch only the paths you know still exist. 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-16 08:30:10 +02:00
# Used both for the live resource readout (see ResourceReadout, which feeds
# it from GameState) and for the fixed prices under each build option.
@export var amount: int = 0: set = set_amount
@export var show_icon: bool = true
@export var glow_color: Color = Color(0.0, 0.62, 0.7)
@export var core_color: Color = Color(0.0, 0.12, 0.15)
@export var digit_height: float = 30.0
@export var digit_gap: float = 9.0
Skill tree, node-based building animation, bigger UI, and a 19x faster test suite Gameplay and UI - Research tree at the mothership gates which structures can be built and grants permanent fleet-capacity upgrades (GameState.SKILL_TREE, SkillTreeView). Node depth is derived from prerequisites, so the layout cannot drift out of step with the dependencies. - Building info popup before committing to a build, with per-building cost and description. - Ship crafter redrawn as a space factory with an assembly animation; mothership redrawn as a radial flagship; command centre as a plotting hub. - Keyboard and mouse support (WASD, Q/E pivot, wheel zoom) for the web build. - UI and font scaled up for phone use, via a custom Theme resource - gui/theme/default_font_size does not reach the default theme. - Asteroids no longer spawn on top of the fleet's start position. - Fleet formation origin derived from the layout's own offsets rather than the centroid, fixing the lurch when a lopsided formation started moving. - Fleet.stop() brakes from the ship's TRUE motion (velocity + fleet_velocity). Ship zeroes its velocity when seated in its slot even while the anchor drags that slot forward, so braking from velocity alone stopped the fleet dead instead of coasting - and whether it did depended on the frame rate. Animation architecture (issue #10) - Buildings, projectiles and explosion VFX no longer animate by redrawing. Static geometry is rasterised once in _draw(); moving parts are NeonPiece children animated through node properties, which reuse the cached geometry. Every NeonDraw call expands into four antialiased polylines, so redrawing to move something re-tessellated all of it. Test suite (issue #8): 1075s -> ~55s - Runs from a copy on Termux's own filesystem. The project lives on Android's FUSE bridge, read through proot, where load("res://Main.tscn") alone cost 8.5s per test against ~2s natively - and nearly every test loads it. - Runs 6 tests at a time, in a single proot-distro login, with output buffered per test and printed only on failure. - --fixed-fps 60 pins delta instead of measuring the wall clock, so a test's result no longer depends on how busy the machine is. Without it, parallelism made two tests fail on 2 of 3 runs. - A test passes only if it both exits 0 and prints ": PASS". - 38 tests, green on three consecutive runs. Bundles Carrois Gothic SC (Apache 2.0) with its licence text. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 15:00:41 +02:00
# Segment weight as a fraction of digit height, so the strokes keep the same
# visual heft at any size. This used to be a fixed width regardless of the
# digit height, which left large readouts looking hairline next to the solid
# ore hexagon beside them.
const STROKE_RATIO: float = 0.014
const HEX_STROKE_RATIO: float = 0.030
# Which of the seven segments each digit lights, in the usual order:
# top, top-right, bottom-right, bottom, bottom-left, top-left, middle.
const DIGIT_SEGMENTS: Array = [
[true, true, true, true, true, true, false], # 0
[false, true, true, false, false, false, false], # 1
[true, true, false, true, true, false, true], # 2
[true, true, true, true, false, false, true], # 3
[false, true, true, false, false, true, true], # 4
[true, false, true, true, false, true, true], # 5
[true, false, true, true, true, true, true], # 6
[true, true, true, false, false, false, false], # 7
[true, true, true, true, true, true, true], # 8
[true, true, true, true, false, true, true], # 9
]
func set_amount(value: int) -> void:
if amount == value:
return
amount = value
queue_redraw()
func _draw() -> void:
var h: float = digit_height
var w: float = h * 0.56
var x: float = 0.0
if show_icon:
_draw_hexagon(Vector2(h * 0.42, h * 0.5), h * 0.62)
x = h * 1.15
for ch in str(maxi(amount, 0)):
_draw_digit(int(ch), Vector2(x, 0.0), w, h)
x += w + digit_gap
func _draw_hexagon(centre: Vector2, radius: float) -> void:
# Same silhouette as the ore pickup itself, so a price and the thing it
# is priced in are unmistakably the same resource.
var pts: PackedVector2Array = PackedVector2Array()
for i in range(6):
var a: float = (float(i) / 6.0) * TAU - PI / 2.0
pts.append(centre + Vector2(cos(a), sin(a)) * radius)
Skill tree, node-based building animation, bigger UI, and a 19x faster test suite Gameplay and UI - Research tree at the mothership gates which structures can be built and grants permanent fleet-capacity upgrades (GameState.SKILL_TREE, SkillTreeView). Node depth is derived from prerequisites, so the layout cannot drift out of step with the dependencies. - Building info popup before committing to a build, with per-building cost and description. - Ship crafter redrawn as a space factory with an assembly animation; mothership redrawn as a radial flagship; command centre as a plotting hub. - Keyboard and mouse support (WASD, Q/E pivot, wheel zoom) for the web build. - UI and font scaled up for phone use, via a custom Theme resource - gui/theme/default_font_size does not reach the default theme. - Asteroids no longer spawn on top of the fleet's start position. - Fleet formation origin derived from the layout's own offsets rather than the centroid, fixing the lurch when a lopsided formation started moving. - Fleet.stop() brakes from the ship's TRUE motion (velocity + fleet_velocity). Ship zeroes its velocity when seated in its slot even while the anchor drags that slot forward, so braking from velocity alone stopped the fleet dead instead of coasting - and whether it did depended on the frame rate. Animation architecture (issue #10) - Buildings, projectiles and explosion VFX no longer animate by redrawing. Static geometry is rasterised once in _draw(); moving parts are NeonPiece children animated through node properties, which reuse the cached geometry. Every NeonDraw call expands into four antialiased polylines, so redrawing to move something re-tessellated all of it. Test suite (issue #8): 1075s -> ~55s - Runs from a copy on Termux's own filesystem. The project lives on Android's FUSE bridge, read through proot, where load("res://Main.tscn") alone cost 8.5s per test against ~2s natively - and nearly every test loads it. - Runs 6 tests at a time, in a single proot-distro login, with output buffered per test and printed only on failure. - --fixed-fps 60 pins delta instead of measuring the wall clock, so a test's result no longer depends on how busy the machine is. Without it, parallelism made two tests fail on 2 of 3 runs. - A test passes only if it both exits 0 and prints ": PASS". - 38 tests, green on three consecutive runs. Bundles Carrois Gothic SC (Apache 2.0) with its licence text. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 15:00:41 +02:00
NeonDraw.draw_glowing_polygon(self, pts, glow_color, 1.0, core_color, radius * HEX_STROKE_RATIO)
NeonDraw.draw_glowing_line(self, pts[5], pts[2], glow_color, 0.6, radius * HEX_STROKE_RATIO * 0.8, core_color)
func _draw_digit(value: int, at: Vector2, w: float, h: float) -> void:
if value < 0 or value > 9:
return
var on: Array = DIGIT_SEGMENTS[value]
var mid: float = h * 0.5
var seg: Array = [
[Vector2(0.0, 0.0), Vector2(w, 0.0)], # top
[Vector2(w, 0.0), Vector2(w, mid)], # top-right
[Vector2(w, mid), Vector2(w, h)], # bottom-right
[Vector2(0.0, h), Vector2(w, h)], # bottom
[Vector2(0.0, mid), Vector2(0.0, h)], # bottom-left
[Vector2(0.0, 0.0), Vector2(0.0, mid)], # top-left
[Vector2(0.0, mid), Vector2(w, mid)], # middle
]
Skill tree, node-based building animation, bigger UI, and a 19x faster test suite Gameplay and UI - Research tree at the mothership gates which structures can be built and grants permanent fleet-capacity upgrades (GameState.SKILL_TREE, SkillTreeView). Node depth is derived from prerequisites, so the layout cannot drift out of step with the dependencies. - Building info popup before committing to a build, with per-building cost and description. - Ship crafter redrawn as a space factory with an assembly animation; mothership redrawn as a radial flagship; command centre as a plotting hub. - Keyboard and mouse support (WASD, Q/E pivot, wheel zoom) for the web build. - UI and font scaled up for phone use, via a custom Theme resource - gui/theme/default_font_size does not reach the default theme. - Asteroids no longer spawn on top of the fleet's start position. - Fleet formation origin derived from the layout's own offsets rather than the centroid, fixing the lurch when a lopsided formation started moving. - Fleet.stop() brakes from the ship's TRUE motion (velocity + fleet_velocity). Ship zeroes its velocity when seated in its slot even while the anchor drags that slot forward, so braking from velocity alone stopped the fleet dead instead of coasting - and whether it did depended on the frame rate. Animation architecture (issue #10) - Buildings, projectiles and explosion VFX no longer animate by redrawing. Static geometry is rasterised once in _draw(); moving parts are NeonPiece children animated through node properties, which reuse the cached geometry. Every NeonDraw call expands into four antialiased polylines, so redrawing to move something re-tessellated all of it. Test suite (issue #8): 1075s -> ~55s - Runs from a copy on Termux's own filesystem. The project lives on Android's FUSE bridge, read through proot, where load("res://Main.tscn") alone cost 8.5s per test against ~2s natively - and nearly every test loads it. - Runs 6 tests at a time, in a single proot-distro login, with output buffered per test and printed only on failure. - --fixed-fps 60 pins delta instead of measuring the wall clock, so a test's result no longer depends on how busy the machine is. Without it, parallelism made two tests fail on 2 of 3 runs. - A test passes only if it both exits 0 and prints ": PASS". - 38 tests, green on three consecutive runs. Bundles Carrois Gothic SC (Apache 2.0) with its licence text. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 15:00:41 +02:00
var stroke: float = h * STROKE_RATIO
for i in range(seg.size()):
if not on[i]:
continue
Skill tree, node-based building animation, bigger UI, and a 19x faster test suite Gameplay and UI - Research tree at the mothership gates which structures can be built and grants permanent fleet-capacity upgrades (GameState.SKILL_TREE, SkillTreeView). Node depth is derived from prerequisites, so the layout cannot drift out of step with the dependencies. - Building info popup before committing to a build, with per-building cost and description. - Ship crafter redrawn as a space factory with an assembly animation; mothership redrawn as a radial flagship; command centre as a plotting hub. - Keyboard and mouse support (WASD, Q/E pivot, wheel zoom) for the web build. - UI and font scaled up for phone use, via a custom Theme resource - gui/theme/default_font_size does not reach the default theme. - Asteroids no longer spawn on top of the fleet's start position. - Fleet formation origin derived from the layout's own offsets rather than the centroid, fixing the lurch when a lopsided formation started moving. - Fleet.stop() brakes from the ship's TRUE motion (velocity + fleet_velocity). Ship zeroes its velocity when seated in its slot even while the anchor drags that slot forward, so braking from velocity alone stopped the fleet dead instead of coasting - and whether it did depended on the frame rate. Animation architecture (issue #10) - Buildings, projectiles and explosion VFX no longer animate by redrawing. Static geometry is rasterised once in _draw(); moving parts are NeonPiece children animated through node properties, which reuse the cached geometry. Every NeonDraw call expands into four antialiased polylines, so redrawing to move something re-tessellated all of it. Test suite (issue #8): 1075s -> ~55s - Runs from a copy on Termux's own filesystem. The project lives on Android's FUSE bridge, read through proot, where load("res://Main.tscn") alone cost 8.5s per test against ~2s natively - and nearly every test loads it. - Runs 6 tests at a time, in a single proot-distro login, with output buffered per test and printed only on failure. - --fixed-fps 60 pins delta instead of measuring the wall clock, so a test's result no longer depends on how busy the machine is. Without it, parallelism made two tests fail on 2 of 3 runs. - A test passes only if it both exits 0 and prints ": PASS". - 38 tests, green on three consecutive runs. Bundles Carrois Gothic SC (Apache 2.0) with its licence text. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 15:00:41 +02:00
NeonDraw.draw_glowing_line(self, at + seg[i][0], at + seg[i][1], glow_color, 1.0, stroke, core_color)