Skip to content

Commit

Permalink
Fix terrain shapes always being rendered behind tiles, regardless of …
Browse files Browse the repository at this point in the history
…configuration
  • Loading branch information
Wibble199 committed Feb 22, 2025
1 parent 8086208 commit 20fe5e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"ShowTerrainStackViewerOnTokenLayer.Name": "Show Terrain Viewer on Token Layer",
"ShowTerrainStackViewerOnTokenLayer.Hint": "If turned on, when hovering over terrain while on the token layer, you will see a display showing you what terrain is under your mouse. Alternatively, you can bind this to a key (see 'Configure Controls').",
"TerrainHeightLayerRenderAboveTiles.Name": "Terrain Height Map Above Tiles",
"TerrainHeightLayerRenderAboveTiles.Hint": "Whether or not the terrain height map will be drawn above non-overhead tiles on the scene. This can be also be set per-scene.",
"TerrainHeightLayerRenderAboveTiles.Hint": "Whether or not the terrain height map will be drawn above tiles with an elevation of 0 on the scene. Note that the height map will ALWAYS be rendered below tiles with an elevation greater than zero. This setting can be also be configured per-scene.",
"TerrainHeightLayerSmartLabelPlacement.Name": "Smart Label Placement",
"TerrainHeightLayerSmartLabelPlacement.Hint": "If enabled, will attempt to be smarter about where labels are placed on complex shapes. If disabled, labels will simply appear at the center of the shape, though for concave shapes or shapes with holes this may fall outside the painted area.",
"TerrainHeightLayerVisibilityRadius.Name": "Terrain Height Map Visibility Radius",
Expand Down
17 changes: 7 additions & 10 deletions module/layers/terrain-height-graphics.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,19 @@ export class TerrainHeightGraphics extends PIXI.Container {
];
}

// Sorting within the PrimaryCanvasGroup works by the `elevation`, then by whether it is a token, then by whether it
// is a Drawing, then finally by the `sort`.
// Using an elevation of 0 puts it at the same level as tokens, tiles (except overhead tiles, which are 4), drawings
// etc.
// If the layer is to be drawn on top of tiles, use a very a high number (because the PCG explicitly checks for
// DrawingShape and TokenMesh it will never be drawn over these regardless of the sort)
// If the layer is to be drawn below tiles, use a very low number (but higher than -9999999999 which is for some other
// sprite mesh) so that it is always below the tiles.
// Sorting within the PrimaryCanvasGroup works by the `elevation`, then by `sortLayer` (500 for tiles, 700 for
// tokens) then finally by the `sort`.
// We will always use an elevation of 0, so that overhead tokens always render above.
// A higher number means that it will be rendered below.
// A future enhancement could be to render the shapes at their respective elevation, but for now that's not the case
get elevation() { return 0; }

get sort() {
get sortLayer() {
/** @type {boolean} */
const renderAboveTiles = canvas.scene?.getFlag(moduleName, flags.terrainLayerAboveTiles)
?? game.settings.get(moduleName, settings.terrainLayerAboveTilesDefault);

return renderAboveTiles ? 9999999999 : -9999999998;
return renderAboveTiles ? 490 : 510;
}

/**
Expand Down

0 comments on commit 20fe5e5

Please sign in to comment.