Files
gen1recomp/tools/save-editor/State.lua
T
bryanthaboi af47e19e1a Rebuild the launcher and save editor on a small immediate-mode UI kit
The launcher spent ~9ms per frame building and drawing, and the Find Mods
tab could hang the window for minutes. Both had the same root cause: a
retained UI tree rebuilt every frame, and blocking curl calls made from the
draw path.

Replace the vendored FlexLove engine (28.5k lines) with src/ui/kit/ (Kit,
Theme, Layout, Loader). The kit caches Text objects and all measurement,
allocates nothing in the steady state, and draws flat. Build+draw is now
under 1ms at every window size and on every tab (POKEPORT_LAUNCHER_PROF).

Move every network call off the render thread onto a love.thread pool
(src/net/Fetch.lua): mod index fetches, per-mod release checks, find-tab
stats, thumbnails and mod installs. Mod indexes prewarm at boot so the
Find Mods tab is populated before it is opened.

Paginate every list -- mods, find, save slots, settings, release notes,
versions -- with the page size derived from the real viewport height, so a
500-mod index costs what a 10-mod one does. Scrolling is gone.

Anything that waits now raises a non-dismissable loader; per-row background
work shows an inline spinner instead. The in-app updater moves to the top
right beside the settings gear and pulses when an update is waiting.

Theme is black with white outlines, no gradients or glows, and solid
colour-coded embossed buttons with bold labels. The game tabs keep their
cartridge colours. Everything is 1.3x larger. The save editor shares the
theme, and adding an item there is now a searchable pop-up like adding a
Pokemon.

Also:
- Reset rebinds, in Settings and under Touch Controls. Rebinds are additive
  (Input:applyBindings layers them over the defaults), so there was no
  in-game way to undo one.
- Launch options: --game red [--slot N] / POKEPORT_GAME boots straight into
  a game for shortcuts and frontends, falling back to that game's tab when
  its ROM is not imported.

Fixes found while porting:
- Ellipsis and letterspacing truncated bytes, not codepoints, so a
  multi-byte mod name crashed the first frame on a Japanese index.
  Measurement no longer throws on malformed input either.
- The new font set missed UiFont's kana fallback, rendering translated
  builds as tofu.
- Fetch workers idle in Channel:demand() and LOVE waits for live threads at
  exit, so the process outlived the window; quitting mid-download also
  waited on curl's 300s ceiling. Shut the pool down in love.quit and bound
  its transfer timeouts.
- In one column the save-slot card drew below the fold, over the footer,
  with no scrollbar left to reach it.

The two FlexLove engine tests guarded a scroll manager and an auto-height
propagation bug that no longer exist; replace them with a kit suite covering
page bounds, viewport sizing and UTF-8 truncation, and retarget the NX test
to assert the dependency is gone rather than that its perf guards are set.
2026-08-04 15:17:09 -04:00

98 lines
3.1 KiB
Lua

-- The save editor's whole mutable world. Ops.lua is the only module allowed
-- to change the `save` sub-tree (and it always sets dirty + status together);
-- everything else here is view state -- which tab, which row, which page.
local State = {}
function State.new()
return {
-- loaded content
data = nil,
cat = nil, -- sorted species / items / moves id lists (Catalog)
events = nil, -- scraped EVENT_* / MOD_* flag names (Catalog)
save = nil,
path = nil,
validation = nil, -- what the running game would quarantine, on a copy
-- file state
dirty = false,
loadError = false, -- true when the save file exists but failed to decode
allowSave = true, -- false while loadError, until a successful Reload
_quitArmed = false,
_openArmed = false,
-- Which game this save belongs to, so the title bar can show the RED /
-- BLUE chip and the launcher can hand the editor the right slot. Set by
-- App.load's opts; nil in a bare `love . --editor` run.
version = nil,
slotId = nil,
-- Hosted inside the launcher process (Edit on a save row) rather than a
-- standalone `--editor` window: Close returns to the launcher instead of
-- quitting, and App calls onClose() to do it.
embedded = false,
onClose = nil,
-- chrome
tab = "party", -- party|boxes|items|events|map|dex
status = "",
armed = nil, -- id of the destructive button awaiting confirmation
armedAt = nil, -- when it was armed (Ops.ARM_SECONDS to commit)
-- party / inspector
selectedParty = 1,
partyOffset = 0, -- roster scroll position (#715)
inspectorScroll = 0, -- MonEditor body pixel scroll (#715)
editingMon = nil, -- reference into party or a box
-- species picker overlay: nil when closed, otherwise { query, offset }
-- plus mode = "box-add" when it is adding to a box instead of changing a
-- species (Ops.openBoxAddPicker). Modal in the literal sense -- App
-- shields every widget under it for the frame -- because Kit hit-tests
-- without a z-order (#541).
speciesPicker = nil,
-- item picker overlay: nil when closed, otherwise
-- { query, offset, dest = "bag"|"pc" }. Same modal contract as
-- speciesPicker above -- adding an item is now a full-screen picker
-- rather than a card competing for height inside the Items tab.
itemPicker = nil,
-- boxes
selectedBox = 1,
selectedBoxSlot = 1,
dockOffset = 0, -- party dock scroll position (#715)
-- items
itemQuery = "",
selectedItemId = nil,
selectedBagId = nil,
selectedPcId = nil,
itemPickOffset = 0, -- scroll position in the ADD ITEM list (#595)
bagOffset = 0,
pcOffset = 0,
itemsScroll = 0, -- stacked-layout pixel scroll (#715)
-- events
eventsTab = "flags",
eventFilter = "",
eventsOffset = 0,
-- dex
dexOffset = 0,
-- map
mapId = nil,
mapQuery = "",
mapListOffset = 0,
mapCamX = 0,
mapCamY = 0,
mapZoom = 2,
mapClickCell = nil,
}
end
function State.markDirty(s)
s.dirty = true
end
return State