#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>
This commit is contained in:
parent
baac11ae8b
commit
2f161621c3
495 changed files with 571 additions and 567 deletions
138
ui/FormationEditor.gd
Normal file
138
ui/FormationEditor.gd
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
extends Control
|
||||
|
||||
# Drag-and-drop editor for the fleet's formation, opened at a command
|
||||
# centre. Each slot is a draggable marker; dropping one writes the new
|
||||
# offset straight back into GameState.formation, so the change survives
|
||||
# scene swaps and applies to any fleet rebuilt later.
|
||||
#
|
||||
# Works in "formation space": the panel centre represents the fleet centre,
|
||||
# and one formation unit maps to `scale_factor` screen pixels.
|
||||
|
||||
signal closed
|
||||
signal formation_changed
|
||||
|
||||
@export var scale_factor: float = 1.4
|
||||
@export var min_scale: float = 0.5
|
||||
@export var max_scale: float = 4.0
|
||||
@export var marker_radius: float = 26.0
|
||||
@export var glow_color: Color = Color(0.25, 0.85, 1.0)
|
||||
|
||||
var dragging_index: int = -1
|
||||
var drag_touch_index: int = -1
|
||||
|
||||
# Second finger = pinch to zoom the layout view, so a spread-out formation
|
||||
# can be inspected close up or seen whole. Zooming only changes how the
|
||||
# formation is DISPLAYED - the stored offsets are untouched.
|
||||
var touches: Dictionary = {}
|
||||
var pinch_active: bool = false
|
||||
var pinch_start_distance: float = 0.0
|
||||
var pinch_start_scale: float = 1.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _centre() -> Vector2:
|
||||
return size / 2.0
|
||||
|
||||
|
||||
func _slot_screen_pos(i: int) -> Vector2:
|
||||
return _centre() + GameState.formation[i] * scale_factor
|
||||
|
||||
|
||||
func _screen_to_formation(p: Vector2) -> Vector2:
|
||||
return (p - _centre()) / scale_factor
|
||||
|
||||
|
||||
# Returns true when the event was consumed. Called from BuildController,
|
||||
# which forwards input while the editor is open.
|
||||
func handle_touch(event: InputEventScreenTouch) -> bool:
|
||||
if not visible:
|
||||
return false
|
||||
var local: Vector2 = event.position - global_position
|
||||
|
||||
if event.pressed:
|
||||
touches[event.index] = event.position
|
||||
if touches.size() == 2:
|
||||
# A second finger turns the gesture into a pinch: drop any slot
|
||||
# being dragged so it isn't yanked around while zooming.
|
||||
dragging_index = -1
|
||||
drag_touch_index = -1
|
||||
var positions: Array = touches.values()
|
||||
pinch_start_distance = positions[0].distance_to(positions[1])
|
||||
pinch_start_scale = scale_factor
|
||||
pinch_active = true
|
||||
queue_redraw()
|
||||
return true
|
||||
if dragging_index != -1:
|
||||
return false
|
||||
for i in range(GameState.max_fleet_size()):
|
||||
if local.distance_to(_slot_screen_pos(i)) <= marker_radius * 1.4:
|
||||
dragging_index = i
|
||||
drag_touch_index = event.index
|
||||
queue_redraw()
|
||||
return true
|
||||
return false
|
||||
|
||||
touches.erase(event.index)
|
||||
if touches.size() < 2:
|
||||
pinch_active = false
|
||||
if event.index != drag_touch_index:
|
||||
return false
|
||||
dragging_index = -1
|
||||
drag_touch_index = -1
|
||||
queue_redraw()
|
||||
return true
|
||||
|
||||
|
||||
func handle_drag(event: InputEventScreenDrag) -> bool:
|
||||
if not visible:
|
||||
return false
|
||||
|
||||
if touches.has(event.index):
|
||||
touches[event.index] = event.position
|
||||
if pinch_active and touches.size() == 2 and pinch_start_distance > 0.0:
|
||||
var positions: Array = touches.values()
|
||||
var current: float = positions[0].distance_to(positions[1])
|
||||
# Spreading apart zooms in, matching the world pinch.
|
||||
scale_factor = clamp(
|
||||
pinch_start_scale * (current / max(pinch_start_distance, 1.0)),
|
||||
min_scale, max_scale
|
||||
)
|
||||
queue_redraw()
|
||||
return true
|
||||
|
||||
if event.index != drag_touch_index or dragging_index == -1:
|
||||
return false
|
||||
var local: Vector2 = event.position - global_position
|
||||
# Clamped so a slot can't be dragged off the panel and become
|
||||
# unreachable (and so the fleet can't be spread absurdly far apart).
|
||||
var f: Vector2 = _screen_to_formation(local)
|
||||
var limit: float = min(size.x, size.y) / (2.0 * scale_factor) - marker_radius / scale_factor
|
||||
GameState.formation[dragging_index] = Vector2(
|
||||
clamp(f.x, -limit, limit), clamp(f.y, -limit, limit)
|
||||
)
|
||||
queue_redraw()
|
||||
formation_changed.emit()
|
||||
return true
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
var centre: Vector2 = _centre()
|
||||
|
||||
# Reference cross for the fleet centre.
|
||||
var tick: float = 14.0
|
||||
NeonDraw.draw_glowing_line(self, centre + Vector2(-tick, 0), centre + Vector2(tick, 0), Color(0.4, 0.45, 0.5), 0.5, 0.3)
|
||||
NeonDraw.draw_glowing_line(self, centre + Vector2(0, -tick), centre + Vector2(0, tick), Color(0.4, 0.45, 0.5), 0.5, 0.3)
|
||||
|
||||
for i in range(GameState.max_fleet_size()):
|
||||
var p: Vector2 = _slot_screen_pos(i)
|
||||
var held: bool = i == dragging_index
|
||||
# Ship glyph, so the layout reads the way it will look in flight.
|
||||
var points: PackedVector2Array = PackedVector2Array([
|
||||
p + Vector2(0, -marker_radius),
|
||||
p + Vector2(-marker_radius * 0.66, marker_radius * 0.72),
|
||||
p + Vector2(marker_radius * 0.66, marker_radius * 0.72),
|
||||
])
|
||||
NeonDraw.draw_glowing_polygon(self, points, glow_color, 1.0 if held else 0.7)
|
||||
Loading…
Reference in a new issue