Share one backdrop between game and editor, and fix three input/economy bugs

The setup editor and the landed surface drew different backgrounds for the
same planet. Each scene carried its own hand-written ShaderMaterial, and only
the game side ever swapped in a profile's shader, so a gas giant authored in
the editor showed recoloured craters while the game showed cloud bands. Both
now instance one SurfaceBackground.tscn and configure it through one method,
and every profile names its own shader - the old "null means keep whatever
the scene already had" convention was the drift, since each scene "already
had" something different. The shared material is resource_local_to_scene, or
two live surfaces would repaint each other.

The gas giant's bands broke into disjoint segments once per cell: the second
turbulence octave doubled only the INTEGER half of a lattice coordinate,
which is a different point in every cell rather than the same point at twice
the frequency. Measured, the old form steps 0.153 at a cell boundary against
0.0002 now. A second discontinuity went with it - the camera cell index
arrives pre-wrapped, so hashing it raw rearranged the whole sky every 32
cells; hashes are now wrapped per octave and the field is exactly periodic.
Bands also gained low-frequency octaves and per-row differential drift.

WorldMap swallowed every touch in _input(), which runs before the GUI system,
so CloseButton never saw one: the map could be opened and not closed. Android
and desktop hid it behind Godot's emulated mouse event, which this never
swallowed; a phone browser gives no such second chance. Its test had been
closing the map by calling the method the button was failing to reach.

Construction now draws on the fleet hold as well as the bank. With an empty
starting bank and ore bankable only at a mothership, charging construction to
the bank alone made the first mothership cost ore that could not yet exist.

Also: a conquered planet no longer re-spawns its garrison (guarded on having
capture points, since a setup with none registers as vacuously conquered);
planets keep the map they drew, with the candidate list sorted rather than
left in filesystem order and assignments pruned rather than cleared on
rescan; and the map editor lists setups at a tappable size and can delete
one, as an explicit armed mode rather than a tap away from destroying work.

Full suite 106/106.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Loïc Wisniewski 2026-08-19 11:16:38 +02:00
commit f5a16a7b95
35 changed files with 1783 additions and 152 deletions

View file

@ -60,6 +60,8 @@ const PALETTE_STEP: float = 92.0
@onready var load_panel: Control = $UI/LoadPanel
@onready var load_list: ItemList = $UI/LoadPanel/List
@onready var load_close_button: IconButton = $UI/LoadPanel/CloseButton
@onready var load_title_label: Label = $UI/LoadPanel/TitleLabel
@onready var delete_map_button: IconButton = $UI/LoadPanel/DeleteMapButton
var current_setup: Resource
var selected_palette: String = "capture_point"
@ -71,6 +73,11 @@ var _profile_cursor: int = 0
# kept only as the id list _load_list_setup_ids indexes into when the
# panel's own selection fires.
var _load_list_setup_ids: PackedStringArray = PackedStringArray()
# While armed, tapping a row in the load panel DELETES that setup instead of
# loading it. One button and one meaning per tap, rather than a second list
# or a per-row delete affordance that would be easy to hit by accident on a
# phone - and the panel says plainly which mode it is in.
var _delete_map_armed: bool = false
var _palette_buttons: Array = []
var _origin_marker: NeonPiece
@ -95,7 +102,8 @@ func _ready() -> void:
load_button.pressed.connect(_on_load_pressed)
delete_button.pressed.connect(_on_delete_pressed)
name_input.text_changed.connect(_on_name_changed)
load_close_button.pressed.connect(func(): load_panel.visible = false)
load_close_button.pressed.connect(_on_load_close_pressed)
delete_map_button.pressed.connect(_on_delete_map_pressed)
load_list.item_selected.connect(_on_load_list_item_selected)
_origin_marker = NeonPiece.create(item_host, Vector2.ZERO, ORIGIN_COLOR)
@ -164,6 +172,33 @@ func save_setup() -> Dictionary:
return {"ok": true, "message": "Saved '%s'." % current_setup.setup_id}
func delete_setup(setup_id: String) -> Dictionary:
# Deliberately mirrors save_setup(): same editor-only guard, same
# {ok, message} shape, and the same rescan afterwards so the in-memory
# registry stops offering a file that is no longer there.
if setup_id.strip_edges() == "":
return {"ok": false, "message": "No setup to delete."}
if not OS.has_feature("editor"):
return {"ok": false, "message": "Setups can only be deleted when running from the project."}
var path: String = "res://PlanetSetups/%s.tres" % setup_id
if not ResourceLoader.exists(path):
return {"ok": false, "message": "No setup file for '%s'." % setup_id}
var err: int = DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
if err != OK:
return {"ok": false, "message": "Delete failed (error %d)." % err}
# Godot writes a .uid sidecar next to a saved resource; leaving it behind
# makes the next import complain about a uid with no file.
var uid_path: String = ProjectSettings.globalize_path(path + ".uid")
if FileAccess.file_exists(uid_path):
DirAccess.remove_absolute(uid_path)
PlanetSetups.rescan()
# The deleted setup may be the one on screen. Leaving it loaded would let
# the next save silently recreate the file the player just removed.
if current_setup != null and String(current_setup.setup_id) == setup_id:
new_setup("untitled", "Untitled", _profile_ids[_profile_cursor])
return {"ok": true, "message": "Deleted '%s'." % setup_id}
# --- model: capture points ---------------------------------------------
func add_capture_point(at: Vector2) -> int:
@ -224,11 +259,13 @@ func remove_enemy(index: int) -> void:
func _refresh_background() -> void:
if current_setup == null or background == null:
return
# The exact call PlanetSurfaceController makes when landing, on the exact
# same instanced scene. Setting the colours here by hand is what let the
# editor and the game drift: this side never swapped in the profile's own
# SHADER, so a gas giant authored here was drawn as recoloured craters
# while the game drew cloud bands. See the header of SurfaceBackground.gd.
var profile: Resource = PlanetSurfaceProfiles.get_profile(current_setup.surface_profile_id)
var material: ShaderMaterial = background.material
material.set_shader_parameter("base_color", profile.base_color)
material.set_shader_parameter("crater_color", profile.crater_color)
material.set_shader_parameter("highlight_color", profile.highlight_color)
background.apply_profile(profile)
if profile_value_label != null:
profile_value_label.text = current_setup.surface_profile_id.to_upper()
_refresh_reward_label()
@ -351,22 +388,58 @@ func _on_save_pressed() -> void:
func _on_load_pressed() -> void:
if not _refresh_load_list():
return
_delete_map_armed = false
_refresh_load_panel_mode()
load_panel.visible = true
func _refresh_load_list() -> bool:
var setups: Array = PlanetSetups.all()
if setups.is_empty():
_set_status("No saved setups yet.")
return
load_panel.visible = false
return false
load_list.clear()
_load_list_setup_ids = PackedStringArray()
for setup in setups:
load_list.add_item("%s (%s)" % [setup.display_name, setup.surface_profile_id])
_load_list_setup_ids.append(setup.setup_id)
load_panel.visible = true
return true
func _refresh_load_panel_mode() -> void:
if load_title_label != null:
load_title_label.text = "Tap a setup to DELETE" if _delete_map_armed else "Load a setup"
func _on_delete_map_pressed() -> void:
_delete_map_armed = not _delete_map_armed
_refresh_load_panel_mode()
func _on_load_close_pressed() -> void:
load_panel.visible = false
_delete_map_armed = false
_refresh_load_panel_mode()
func _on_load_list_item_selected(index: int) -> void:
if index < 0 or index >= _load_list_setup_ids.size():
return
load_setup(_load_list_setup_ids[index])
var setup_id: String = _load_list_setup_ids[index]
if _delete_map_armed:
var outcome: Dictionary = delete_setup(setup_id)
_set_status(outcome.message)
# Disarmed either way: a delete that failed should not leave the next
# tap primed to try again on a different setup.
_delete_map_armed = false
if not _refresh_load_list():
return
_refresh_load_panel_mode()
return
load_setup(setup_id)
load_panel.visible = false