Skip to content

Migrate UI editors#1520

Merged
Azgaar merged 36 commits into
masterfrom
migrate-ui-editors
Jul 14, 2026
Merged

Migrate UI editors#1520
Azgaar merged 36 commits into
masterfrom
migrate-ui-editors

Conversation

@Azgaar

@Azgaar Azgaar commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Description

Azgaar and others added 15 commits July 1, 2026 03:32
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port public/modules/ui/ice-editor.js to src/controllers/ice-editor.ts
following the migration guide (strict d3 v7). The controller owns its
dialog HTML (injected on open, cleared on close), registers via the
Controllers registry, and drops the legacy global editIce().

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port public/modules/ui/notes-editor.js to src/controllers/notes-editor.ts
following the migration guide (strict d3 v7). The controller owns its
dialog HTML (injected on open, cleared on close via removeEditor).

Replace the legacy global editNotes() with Controllers.NotesEditor.open()
at every call site (river/route/regiment/burg controllers plus the classic
labels/lakes/markers/tools/hotkeys modules) and drop the editNotes global.
Add typed globals for generateWithAi and tinymce.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port public/modules/ui/lakes-editor.js to src/controllers/lakes-editor.ts
following the migration guide (strict d3 v7: select/drag/polygon* named
imports, event-arg drag handlers). The controller owns its dialog HTML
(injected on open, cleared on close), registers as Controllers.LakesEditor,
and replaces the global editLake() at the editors.js call site. Add
drawBiomes to global.ts.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port public/modules/ui/markers-editor.js to src/controllers/markers-editor.ts
following the migration guide (strict d3 v7 drag; module-scoped selected
marker/element instead of closures). The controller owns its dialog HTML
(injected on open, cleared on close) so listeners drop with the markup,
registers as Controllers.MarkersEditor, and replaces editMarker() at the
editors.js and markers-overview.js call sites. Extend the Marker interface
with the size/pin/fill/stroke/hidden fields the editor manages.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port public/modules/ui/units-editor.js to src/controllers/units-editor.ts
following the migration guide (strict d3 v7: select/drag, event-arg ruler
gestures). The #unitsEditor markup stays in index.html because its inputs
(distanceUnitInput, heightUnit, temperatureScale, …) are app-wide settings
cached as globals at load; listeners are wired once behind an initialized
flag. Register as Controllers.UnitsEditor and replace editUnits() at the
main.js, load.ts, tools.js and hotkeys.js call sites; drop the editUnits
global. Add toggleRulers, calculateFriendlyGridSize, RouteOpisometer globals.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port public/modules/ui/relief-editor.js to src/controllers/relief-editor.ts
following the migration guide (strict d3 v7: select/drag/quadtree/range/
pointer named imports, event-arg drag/brush handlers). The large static
#reliefEditor icon palette stays in index.html (queried, not created);
listeners wire once behind an initialized flag. Register as
Controllers.ReliefEditor, replace editReliefIcon() at the editors.js call
site. Add toggleRelief global.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port public/modules/ui/labels-editor.js to src/controllers/labels-editor.ts
following the migration guide (strict d3 v7: select/drag/pointer/line/
curveNatural named imports, event-arg drag and control-point handlers,
module-local line generator). The static #labelEditor toggle sections stay
in index.html; listeners wire once behind an initialized flag. Register as
Controllers.LabelsEditor and replace editLabel() at the editors.js call site.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port public/modules/ui/biomes-editor.js to src/controllers/biomes-editor.ts
following the migration guide (strict d3 v7: select/drag/pointer/sum/
transition/easeSinIn named imports, event-arg brush handlers). The static
#biomesEditor chrome stays in index.html (rows generated at runtime);
listeners wire once behind an initialized flag. Register as
Controllers.BiomesEditor and replace editBiomes() at the tools.js and
hotkeys.js call sites. Add recalculatePopulation/findAll globals and the
runtime stat fields (cells/area/rural/urban) to biomesData.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port public/modules/ui/zones-editor.js to src/controllers/zones-editor.ts
following the migration guide (strict d3 v7: select/drag/pointer/sum named
imports, event-arg brush handlers, typed data-join datum). The static
#zonesEditor chrome stays in index.html (rows generated at runtime);
listeners wire once behind an initialized flag. Register as
Controllers.ZonesEditor and replace editZones() at the tools.js and
hotkeys.js call sites. Add toggleZones global and hidden? to the Zone type.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port public/modules/ui/diplomacy-editor.js to src/controllers/diplomacy-editor.ts
following the migration guide (strict d3 v7: select/pointer/interpolateString/
color named imports, event-arg map-click handler). The static #diplomacyEditor
chrome stays in index.html (rows generated at runtime); listeners wire once
behind an initialized flag. State 0's diplomacy field (the chronicle) is
cast to string[][] at the boundary. Register as Controllers.DiplomacyEditor
and replace editDiplomacy() at the tools.js and hotkeys.js call sites.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port public/modules/ui/emblems-editor.js to src/controllers/emblems-editor.ts
following the migration guide (strict d3 v7: select/drag named imports,
event-arg drag handler; module-scoped selected type/id/el instead of
closures). The static #emblemEditor markup stays in index.html; onX handlers
are idempotent so they wire on every open. Register as Controllers.EmblemsEditor
and replace editEmblem() everywhere (states/burg controllers, tools/editors/
provinces classic modules); drop the editEmblem global, add highlightEmblemElement.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port public/modules/ui/provinces-editor.js (1372 lines) to
src/controllers/provinces-editor.ts following the migration guide (strict
d3 v7: select/drag/pointer/stratify/treemap/transition/color/interpolate
named imports, event-arg brush and treemap handlers). The static
#provincesEditor chrome stays in index.html (rows generated at runtime);
listeners wire once behind initialized flags. Register as
Controllers.ProvincesEditor and replace editProvinces() at the tools.js and
hotkeys.js call sites. Extend the Province interface with the editor's
computed stat fields (area/rural/urban/burgs).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port public/modules/ui/heightmap-editor.js (1713 lines) to
src/controllers/heightmap-editor.ts following the migration guide (strict
d3 v7: select/drag/pointer/range/hsl/lab/leastIndex/interpolateRound named
imports, event-arg brush handlers, d3.scan→leastIndex). Covers all tools:
mode selection, brush painting, fill/line brushes, template editor DSL,
image converter, preview, and the erase/keep/risk finalize-and-regenerate
paths. The static #customizationMenu markup stays in index.html; panel
listeners wire once behind init flags. Register as Controllers.HeightmapEditor
and replace editHeightmap() at the heightmap-selection/tools/hotkeys call
sites; drop the editHeightmap global. Add color/edits/undraw/rankCells/
generatePrecipitation/changeViewMode/resetZoom/RgbQuant globals and Culture
x/y transient fields.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…oller

Port the editCoastline() vertex/group editor from
public/modules/ui/coastline-editor.js to
src/controllers/coastline-vertex-editor.ts following the migration guide
(strict d3 v7: select/drag/polygonArea, event-arg vertex drag). Named
CoastlineVertexEditor to avoid collision with the existing Coastline
Settings CoastlineEditor. Owns its dialog HTML (injected on open, cleared
on close), registered in the Controllers registry, replaces editCoastline()
at the editors.js call site. This was the last remaining *-editor.js in
public/modules/ui.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Azgaar Azgaar self-assigned this Jul 1, 2026
Copilot AI review requested due to automatic review settings July 1, 2026 03:12
@netlify

netlify Bot commented Jul 1, 2026

Copy link
Copy Markdown

Deploy Preview for afmg ready!

Name Link
🔨 Latest commit 45c5c36
🔍 Latest deploy log https://app.netlify.com/projects/afmg/deploys/6a566a1c1b17af000823055f
😎 Deploy Preview https://deploy-preview-1520--afmg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR continues the UI migration from legacy public/modules/ui/* editor modules to lazy‑loaded TypeScript controllers under src/controllers, and rewires the remaining legacy entrypoints (tools menu, hotkeys, click routing, scale bar) to open the new controllers via window.Controllers.

Changes:

  • Migrated multiple editors (Units, Notes, Markers, Labels, Lakes, Ice, Relief, Coastline vertex) into src/controllers/* and registered them in the controller registry for lazy loading.
  • Removed legacy editor scripts and large chunks of static dialog markup from src/index.html, leaving placeholder dialog containers for controller-owned DOM.
  • Extended global typings and several generator interfaces to include editor-computed/transient fields used by the migrated editors.

Reviewed changes

Copilot reviewed 48 out of 48 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
src/types/global.ts Updates global typings for new controller-driven editor globals and utilities
src/services/io/load.ts Rewires scale bar click to open the Units controller
src/index.html Removes legacy dialog markup and legacy editor script tags; keeps dialog placeholders
src/generators/zones-generator.ts Adds hidden? to zones data model for editor usage
src/generators/provinces-generator.ts Adds editor-computed statistics fields to provinces
src/generators/markers-generator.ts Adds marker presentation fields used by the marker editor
src/generators/cultures-generator.ts Adds transient x/y fields used by heightmap editor workflows
src/controllers/units-editor.ts New lazy-loadable Units editor controller
src/controllers/states-editor.ts Uses Controllers.EmblemsEditor instead of legacy emblem editor function
src/controllers/route-editor.ts Uses Controllers.NotesEditor instead of legacy notes editor function
src/controllers/river-editor.ts Uses Controllers.NotesEditor instead of legacy notes editor function
src/controllers/relief-editor.ts New lazy-loadable Relief editor controller
src/controllers/regiment-editor.ts Uses Controllers.NotesEditor instead of legacy notes editor function
src/controllers/notes-editor.ts New lazy-loadable Notes editor controller (TinyMCE integration)
src/controllers/markers-editor.ts New lazy-loadable Markers editor controller
src/controllers/lakes-editor.ts New lazy-loadable Lakes editor controller
src/controllers/labels-editor.ts New lazy-loadable Labels editor controller
src/controllers/index.ts Registers new editors in the lazy controller registry
src/controllers/ice-editor.ts New lazy-loadable Ice editor controller
src/controllers/heightmap-selection.ts Rewires to Controllers.HeightmapEditor
src/controllers/coastline-vertex-editor.ts New controller for coastline vertex/group editing dialog
src/controllers/burg-editor.ts Uses Controllers.EmblemsEditor / Controllers.NotesEditor
public/modules/ui/zones-editor.js Deletes legacy Zones editor implementation
public/modules/ui/units-editor.js Deletes legacy Units editor implementation
public/modules/ui/tools.js Rewires tool buttons to open controllers instead of legacy functions
public/modules/ui/relief-editor.js Deletes legacy Relief editor implementation
public/modules/ui/notes-editor.js Deletes legacy Notes editor implementation
public/modules/ui/markers-overview.js Rewires marker overview to open Controllers.MarkersEditor
public/modules/ui/markers-editor.js Deletes legacy Markers editor implementation
public/modules/ui/lakes-editor.js Deletes legacy Lakes editor implementation
public/modules/ui/labels-editor.js Deletes legacy Labels editor implementation
public/modules/ui/ice-editor.js Deletes legacy Ice editor implementation
public/modules/ui/hotkeys.js Rewires hotkeys to open controllers instead of legacy functions
public/modules/ui/emblems-editor.js Deletes legacy Emblems editor implementation
public/modules/ui/editors.js Rewires map click routing to open controllers instead of legacy functions
public/modules/ui/diplomacy-editor.js Deletes legacy Diplomacy editor implementation
public/modules/ui/coastline-editor.js Deletes legacy Coastline editor implementation
public/modules/ui/biomes-editor.js Deletes legacy Biomes editor implementation
public/main.js Rewires scale bar click to open the Units controller
docs/architecture/migration_guide.md Strengthens migration guidance for controller-owned DOM lifecycle

Comment thread src/controllers/notes-editor.ts Outdated
Comment thread src/controllers/notes-editor.ts
Comment thread src/controllers/markers-editor.ts
Comment thread src/controllers/markers-editor.ts
Comment thread src/controllers/markers-editor.ts
Comment thread public/main.js
Comment thread public/modules/ui/tools.js
Comment thread public/modules/ui/hotkeys.js
Comment thread public/modules/ui/editors.js
Comment thread docs/architecture/migration_guide.md
Azgaar added 10 commits July 1, 2026 15:37
… event handling

- Removed redundant body element references and replaced them with direct element queries.
- Consolidated dialog rendering logic into dedicated functions for better readability.
- Updated event listeners to target specific sections instead of the entire body.
- Enhanced state and religion management by ensuring proper handling of extinct and selected states/religions.
- Improved percentage mode toggling and CSV download functionality for states and religions.
- Moved dialog HTML templates to render functions in rivers-overview, route-creator, route-editor, route-groups-editor, routes-overview, and trade-animation-editor.
- Replaced direct innerHTML assignments with dynamic rendering and destruction of dialogs to improve maintainability and prevent memory leaks.
- Updated event listener assignments to occur after dialog rendering.
- Removed unused dialog elements from index.html to clean up the codebase.
Azgaar added 7 commits July 3, 2026 17:52
…lectors

- Updated selections in ice-editor, labels-editor, lakes-editor, provinces-editor, relief-editor, units-editor, and zones-editor to use specific IDs instead of relying on node()! for better clarity and maintainability.
- Introduced randomness parameters in heightmap-generator for more flexible terrain generation.
- Adjusted save functionality to ensure proper SVG element selection when saving map data.
@StempunkDev StempunkDev mentioned this pull request Jul 6, 2026
4 tasks
@Azgaar
Azgaar merged commit c25bad1 into master Jul 14, 2026
1 check passed
@Azgaar
Azgaar deleted the migrate-ui-editors branch July 14, 2026 16:56
@Azgaar
Azgaar restored the migrate-ui-editors branch July 14, 2026 17:44
barrulus added a commit to barrulus/Fantasy-Map-Generator that referenced this pull request Jul 21, 2026
Syncs the fork onto Azgaar upstream master (tip 73e43d2), pulling in three
large refactors — UI-editor migration (Azgaar#1520), pointer/d3.v5 selection
replacement (Azgaar#1537), and module migration (Azgaar#1538) — plus market relocation,
temperature-unit and dropbox fixes, and the Europe North preset restore.

16 conflicts resolved. Key decisions:
- Editor pagination (fork) reconciled with upstream's renderDialog() migration
  across rivers/routes/cultures/religions/burgs/states overviews; page state
  kept module-scoped, reset on open/search/sort.
- WebGL burg icon/label guards preserved over upstream's select("#id") switch.
- Fork CSV exports kept (read pack.* not the DOM) to avoid paginated truncation.
- States editor: fork dropdown/demote-picker brush kept over upstream's
  div.selected mechanism; dropped upstream's in-loop footer accumulators to
  avoid double-counting the visible page.
- Seam-wrapping getWrappedLength kept in routes-generator.
- Legacy heightmap/provinces editor JS deleted upstream; fork's Uint32Array
  burg-array widening and GPU-label capital-zoom fallback ported to the new
  TS controllers.
- Burg-editor trade-role/flying/skyport/altitude and burgs-overview
  pagination/skyburg markup re-homed from index.html into controller templates.

tsc clean, 308 tests pass (1 skipped), production build succeeds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants