Add cell type filter to heightmap editor brush panel#1381
Conversation
✅ Deploy Preview for afmg ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Agent-Logs-Url: https://github.com/Azgaar/Fantasy-Map-Generator/sessions/4011258c-2dd9-45c2-bec6-bd390cb8ca73 Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com>
|
@copilot, replace two checkboxes with a select input with 'check all cells', 'check only land cells' and 'check only water cells' options. |
Azgaar
left a comment
There was a problem hiding this comment.
replace two checkboxes with a select input with 'check all cells', 'check only land cells' and 'check only water cells' options.
Agent-Logs-Url: https://github.com/Azgaar/Fantasy-Map-Generator/sessions/e456d324-554b-4ee5-98ae-3c28da95ecca Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com>
Done in 1edb1e2. The two checkboxes are replaced with a single |
There was a problem hiding this comment.
Pull request overview
This PR updates the heightmap editor brush UI to use a single cellTypeFilter dropdown, letting users restrict edits to all cells, land-only, or water-only, to reduce accidental coastline changes during height editing.
Changes:
- Replaces prior cell-type restriction checkboxes with a single
cellTypeFilter<select>in the brush panel UI - Updates heightmap brush/line editing logic to honor the selected cell-type filter (including some safety rollback and rescale behavior)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/index.html | Replaces the previous checkbox UI with a cellTypeFilter dropdown |
| public/modules/ui/heightmap-editor.js | Wires the new filter into brush/line operations, rescale, and mode switching |
| if (cellTypeFilter.value === "land" && heightmapEditMode.innerHTML === "keep") { | ||
| tip("You cannot change the coastline in 'Keep' edit mode", false, "error"); | ||
| cellTypeFilter.value = "all"; |
There was a problem hiding this comment.
cellTypeFilterChange currently blocks selecting the "land" filter in "keep" mode and resets to "all". In "keep" mode the UI copy says the coastline cannot change, which requires forcing a land-only constraint (matching enterHeightmapEditMode setting cellTypeFilter.value = "land"). Consider preventing changes away from "land" while in keep mode (e.g., revert to "land" / disable the select) rather than rejecting the land option.
| if (cellTypeFilter.value === "land" && heightmapEditMode.innerHTML === "keep") { | |
| tip("You cannot change the coastline in 'Keep' edit mode", false, "error"); | |
| cellTypeFilter.value = "all"; | |
| if (heightmapEditMode.innerHTML === "keep" && cellTypeFilter.value !== "land") { | |
| tip("You cannot change the coastline in 'Keep' edit mode", false, "error"); | |
| cellTypeFilter.value = "land"; |
| let selection = []; | ||
| for (let i = 0; i < heights.length; i++) { | ||
| if (changedHeights[i] === heights[i]) continue; | ||
| if (changeOnlyLand.checked && heights[i] < 20) continue; | ||
| if (cellTypeFilter.value === "land" && heights[i] < 20) continue; | ||
| if (cellTypeFilter.value === "water" && heights[i] >= 20) continue; | ||
| heights[i] = changedHeights[i]; | ||
| selection.push(i); |
There was a problem hiding this comment.
In placeLinearFeature, the cell-type filter checks heights[i] (the pre-operation height) to decide whether to apply changedHeights[i]. This allows coastline changes to slip through (e.g., a land cell can be lowered below 20 in land-only mode, or a water cell raised above 19 in water-only mode), and this path doesn't call updateHeightmap() so the rollback logic won't correct it. Filter/clip based on the resulting height (changedHeights[i]) and/or reuse the same limiting logic used by brush editing, or call updateHeightmap() after applying the changes.
Description
Adds a
cellTypeFilterselect input to the heightmap editor brush panel, allowing users to restrict brush operations to all cells, only land cells, or only water cells. This prevents accidental coastline changes or new landmass creation while editing ocean depths, and vice versa.src/index.htmlchangeOnlyLandandchangeOnlyOceancheckboxes with a single<select id="cellTypeFilter">dropdown offering three options:all cells(default),only land cells, andonly water cellspublic/modules/ui/heightmap-editor.jscellTypeFilter.valueon mode change:keepmode selects"land",erase/riskmodes reset to"all"updateHeightmap()— safety rollback reverts cells that crossed theh=20land/water boundary based on the active filterdragBrush()— pre-filters brush selection to land (h >= 20) or water (h < 20) cells depending on the selected filterplaceLinearFeature()— skips land or water cells based on the active filterchangeHeightForSelection()—limbounds adjusted per filter (min=20for land-only,max=19for water-only);brushRaiseskips the ocean-to-land jump in water-only mode;brushSmoothneighbor filter respects the active filterrescale()— skips out-of-filter cells and clamps output to the appropriate rangestartFromScratch()— blocked when any non-"all"filter is activecellTypeFilterChange()— new handler that prevents selecting"land"filter inkeepedit mode