Skip to content

Fix zones not recovering after heightmap edit in Risk mode#1327

Merged
Azgaar merged 6 commits into
masterfrom
copilot/fix-zones-recovery-issue
Feb 18, 2026
Merged

Fix zones not recovering after heightmap edit in Risk mode#1327
Azgaar merged 6 commits into
masterfrom
copilot/fix-zones-recovery-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 18, 2026

Description

Zones were lost after heightmap editing in Risk mode due to incorrect DOM selector. Code attempted to backup/restore zones via zones.selectAll("g"), but zones render as <path> elements, causing the logic to never execute.

Changes:

  • Replace SVG DOM manipulation with direct pack.zones array operations
  • Before reGraph(): store zone→gridCells mapping in local zoneGridCellsMap (Map) - avoids mutating zone objects
  • After reGraph(): create gridToPackMap for O(1) lookups, restore zones using flatMap
  • All temporary data stored in local variables - no pollution of zone objects
  • Remove all inline comments for cleaner code
  • Update version to 1.112.2 and cache hash for heightmap-editor.js

Result: Zones now persist correctly through significant graph changes (coastline modifications, etc.)

Performance Optimization:

  • Original implementation: O(n²) complexity with filter and includes
  • Optimized implementation: O(n) complexity using Map for constant-time lookups
  • Creates grid→pack cell mapping once, then uses flatMap for efficient zone restoration

Data Safety:

  • Original approach mutated zone objects with temporary zone.gridCells property
  • New approach uses local Map to store zone→gridCells mappings
  • Prevents accidental serialization of temporary data in saves
  • Prevents schema collisions
  • No cleanup needed - temporary Map is garbage collected automatically

Code Quality:

  • Before: 27 lines of non-functional DOM manipulation
  • After optimization & cleanup: 11 lines of efficient, safe data model operations

Screenshots

Zones displayed before heightmap edit:

Zones successfully restored after heightmap edit:

Type of change

  • Bug fix
  • New feature
  • Refactoring / style
  • Documentation update / chore
  • Other (please describe)

Versioning

  • Version is updated
  • Changed files hash is updated
Original prompt

This section details on the original issue you should resolve

<issue_title>Risk Heightmap Edit: Zones are not recovering after significant change</issue_title>
<issue_description>Heightmap Edit in Risk, with significant graph change, causes zones to be incorrect.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 18, 2026

Deploy Preview for afmg ready!

Name Link
🔨 Latest commit 8a8920a
🔍 Latest deploy log https://app.netlify.com/projects/afmg/deploys/69963ca14441af00089f7888
😎 Deploy Preview https://deploy-preview-1327--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.

Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com>
Comment thread public/modules/ui/heightmap-editor.js Outdated
Comment thread public/modules/ui/heightmap-editor.js Outdated
Copilot AI changed the title [WIP] Fix zones not recovering after heightmap edit Fix zones not recovering after heightmap edit in Risk mode Feb 18, 2026
Copilot AI requested a review from Azgaar February 18, 2026 20:16
Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com>
@Azgaar Azgaar marked this pull request as ready for review February 18, 2026 22:07
Copilot AI review requested due to automatic review settings February 18, 2026 22:07
Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Risk-mode heightmap editing so zones survive significant reGraph() changes by persisting zone membership via the data model instead of broken SVG DOM selection logic.

Changes:

  • Backup zones using pack.zones[*].cells -> grid cell ids before reGraph()
  • Restore zones by mapping saved grid cell ids back onto new pack cells after reGraph()
  • Remove prior (non-functional) SVG DOM-based backup/restore logic

Comment thread public/modules/ui/heightmap-editor.js Outdated
Comment thread public/modules/ui/heightmap-editor.js
Comment thread public/modules/ui/heightmap-editor.js
Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com>
Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com>
@Azgaar Azgaar merged commit 13ec798 into master Feb 18, 2026
8 checks passed
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.

Risk Heightmap Edit: Zones are not recovering after significant change

3 participants