diff --git a/CHANGELOG.md b/CHANGELOG.md index b55099c..4fde79f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,27 @@ +# Version 10.6 + +Fixed issue refreshing the terrain shape if the shape doesn't exist + +Added opacity as a default value when creating terrain. + +Fixed issue when treying to use the get function on the terrain layer to get terrain information + +Fixed issue with getting terrain info from measured templates + +Fixed issues with getting terrain from grid and pixels, with the missing options property + +Fixed issues with double-clicking to create a hex terrain. + +Added the option to have the measured template created from a spell template, get the colour from the default environment colour. + +Fixed the terrain config interface so that the default values are used as placeholders + +Fixed issue with Midi Qol settings being inserted between the terrain header and settings. + +Fixed issues with the terrain tab not shrinking to fit the contents when Token Magic FX is enabled. + +Add a Rules Provider API, so systems and modules can register how they want difficult terrain to be calculated. Thank you Stäbchenfisch!! + # Version 10.5 Fixed an issue with determining when a token causes difficult terrain. diff --git a/classes/terrain.js b/classes/terrain.js index 513ae61..7382ed0 100644 --- a/classes/terrain.js +++ b/classes/terrain.js @@ -301,7 +301,8 @@ export class Terrain extends PlaceableObject { const { x, y, hidden, shape } = this.document; // Refresh the primary drawing container - this.shape.refresh(); + if (this.shape) + this.shape.refresh(); //this.shape.position.set(shape.width / 2, shape.height / 2); const bounds = new PIXI.Rectangle(0, 0, shape.width, shape.height).normalize(); @@ -381,12 +382,13 @@ export class Terrain extends PlaceableObject { let sceneElev = sceneFlags?.elevation; let sceneDepth = sceneFlags?.depth; let sceneEnv = sceneFlags?.environment; + let sceneOpacity = sceneFlags?.opacity; return { //rotation:0, locked: false, hidden: false, //drawcolor: setting('environment-color')[sceneEnv] || getflag(canvas.scene, 'defaultcolor') || setting('environment-color')['_default'] || "#FFFFFF", - //opacity: getflag(canvas.scene, 'opacity') ?? setting('opacity') ?? 1, + opacity: (sceneOpacity == undefined || sceneOpacity == "" ? setting('opacity') ?? 1 : sceneOpacity), multiple: (sceneMult == undefined || sceneMult == "" ? this.layer.defaultmultiple : Math.clamped(parseInt(sceneMult), setting('minimum-cost'), setting('maximum-cost'))), elevation: (sceneElev == undefined || sceneElev == "" ? 0 : sceneElev), depth: (sceneDepth == undefined || sceneDepth == "" ? 0 : sceneDepth), diff --git a/classes/terrainlayer.js b/classes/terrainlayer.js index 9967f91..1b3afda 100644 --- a/classes/terrainlayer.js +++ b/classes/terrainlayer.js @@ -66,6 +66,10 @@ export class TerrainLayer extends PlaceablesLayer { return canvas["#scene"].terrain || null; } + get(objectId) { + return canvas["#scene"].terrain?.get(objectId)?.object || undefined; + } + get gridPrecision() { let size = canvas.dimensions.size; if (size >= 128) return 16; @@ -202,7 +206,7 @@ export class TerrainLayer extends PlaceablesLayer { const terrainInfos = options.list || []; for (const template of canvas.templates.placeables) { - const terrainFlag = getProperty(template, "flags.enhanced-terrain-layer"); + const terrainFlag = getProperty(template.document, "flags.enhanced-terrain-layer"); if (!terrainFlag) continue; const terraincost = terrainFlag.multiple ?? 1; @@ -293,12 +297,12 @@ export class TerrainLayer extends PlaceablesLayer { return this.costWithTerrain(pts, terrain, options); } - terrainFromGrid(x, y) { + terrainFromGrid(x, y, options = {}) { let [gx, gy] = canvas.grid.grid.getPixelsFromGridPosition(y, x); - return this.terrainFromPixels(gx, gy); + return this.terrainFromPixels(gx, gy, options); } - terrainFromPixels(x, y) { + terrainFromPixels(x, y, options = {}) { const hx = (x + (canvas.dimensions.size / 2)); const hy = (y + (canvas.dimensions.size / 2)); @@ -492,8 +496,8 @@ export class TerrainLayer extends PlaceablesLayer { return this._onDragLeftDrop(event); } else if (createState == 0 || createState == undefined) { //add a default square - let gW = canvas.dimensions.size; - let gH = canvas.dimensions.size; + let gW = canvas.grid.grid.w; + let gH = canvas.grid.grid.h; //let pos = canvas.grid.getSnappedPosition(event.data.origin.x, event.data.origin.y, 1); let [tX, tY] = canvas.grid.grid.getGridPositionFromPixels(event.data.origin.x, event.data.origin.y); diff --git a/js/settings.js b/js/settings.js index 1fdaad1..146040c 100644 --- a/js/settings.js +++ b/js/settings.js @@ -129,6 +129,14 @@ export const registerSettings = function () { default: false, type: Boolean }); + game.settings.register(modulename, 'transfer-color', { + name: "EnhancedTerrainLayer.transfer-color.name", + hint: "EnhancedTerrainLayer.transfer-color.hint", + scope: "world", + config: game.system.id == 'dnd5e', + default: false, + type: Boolean + }); game.settings.register(modulename, 'minimum-cost', { name: "EnhancedTerrainLayer.minimum-cost.name", hint: "EnhancedTerrainLayer.minimum-cost.hint", diff --git a/lang/en.json b/lang/en.json index 63f64d2..58c25f3 100644 --- a/lang/en.json +++ b/lang/en.json @@ -57,6 +57,9 @@ "EnhancedTerrainLayer.terrain-image.hint": "Change the background texture for terrain", "EnhancedTerrainLayer.rule-provider.name": "Rule provider", "EnhancedTerrainLayer.rule-provider.hint": "Which rule provider should Enhanced Terrain Layer pull it's terrain rules from", + "EnhancedTerrainLayer.transfer-color.name": "Transfer spell colour", + "EnhancedTerrainLayer.transfer-color.hint": "When casting a spell that causes difficult terrain, transfer the default environment colour to the measured template.", + "EnhancedTerrainLayer.rule-provider.choices.builtin": "Built-in", "EnhancedTerrainLayer.rule-provider.choices.module": "Module {name}", "EnhancedTerrainLayer.rule-provider.choices.system": "System {name}", diff --git a/module.json b/module.json index 9a7b2c7..c5c8453 100644 --- a/module.json +++ b/module.json @@ -1,7 +1,7 @@ { "title": "Enhanced Terrain Layer", "description": "A base module that adds a Terrain Layer to Foundry. Used as a library for Rulers and other modules", - "version": "10.5", + "version": "10.6", "authors": [ { "name": "IronMonk", @@ -47,7 +47,7 @@ "css/terrainlayer.css" ], "url": "https://github.com/ironmonk88/enhanced-terrain-layer", - "download": "https://github.com/ironmonk88/enhanced-terrain-layer/archive/10.5.zip", + "download": "https://github.com/ironmonk88/enhanced-terrain-layer/archive/10.6.zip", "manifest": "https://github.com/ironmonk88/enhanced-terrain-layer/releases/latest/download/module.json", "bugs": "https://github.com/ironmonk88/enhanced-terrain-layer/issues", "allowBugReporter": true, diff --git a/templates/terrain-form.html b/templates/terrain-form.html index bd4929b..193eb33 100644 --- a/templates/terrain-form.html +++ b/templates/terrain-form.html @@ -1,26 +1,24 @@ {{#if full}} +

Set the default settings when terrain is created on this scene

- - {{data.opacity}} + +
-

Set the opacity for all terrain on this scene

-
-

Set the default settings when terrain is created on this scene

{{/if}}
- +
- +
- +
@@ -50,7 +48,7 @@
- {{ colorPicker name="drawcolor" value=data.drawcolor}} + {{ colorPicker name="flags.enhanced-terrain-layer.drawcolor" value=data.drawcolor}}
{{/if}} diff --git a/terrain-main.js b/terrain-main.js index 3f5a5eb..e1c9a0d 100644 --- a/terrain-main.js +++ b/terrain-main.js @@ -276,7 +276,7 @@ function addControls(app, html, addheader) { } } -async function addControlsv9(app, dest, full) { +async function addControlsv9(app, dest, { full = false, insert = false } = {}) { //add the environment var obs = {}; var env = canvas.terrain.getEnvironments().reduce(function (map, obj) { @@ -285,8 +285,22 @@ async function addControlsv9(app, dest, full) { }, {}); let template = "modules/enhanced-terrain-layer/templates/terrain-form.html"; + let flags = duplicate(app.object.flags['enhanced-terrain-layer'] || {}); + let defaults = {}; + if (full) { + defaults = { + opacity: setting("opacity") ?? 1, + multiple: canvas.terrain.defaultmultiple, + elevation: 0, + depth: 0, + drawcolor: setting('environment-color')[flags?.environment] || setting('environment-color')['_default'] || "#FFFFFF" + } + } + let data = { - data: duplicate(app.object.flags['enhanced-terrain-layer'] || {}), + data: flags, + defaults: defaults, + rangeOpacity: flags.opacity == "" ? defaults.opacity : flags.opacity ?? defaults.opacity, environments: env, obstacles: obs, full: full @@ -294,7 +308,17 @@ async function addControlsv9(app, dest, full) { data.data.multiple = (data.data.multiple == "" || data.data.multiple == undefined ? "" : Math.clamped(parseInt(data.data.multiple), setting('minimum-cost'), setting('maximum-cost'))); let html = await renderTemplate(template, data); - dest.append(html); + if (insert) + dest.after(html); + else + dest.append(html); + $('input[name="flags.enhanced-terrain-layer.opacity"] + .range-value', dest).on("change", () => { + let newval = $('[name="flags.enhanced-terrain-layer.opacity"] + .range-value', dest).val(); + if (newval == '') + newval = -1; + $('[name="flags.enhanced-terrain-layer.opacity"]', dest).val(newval); + }); + $('input[name="flags.enhanced-terrain-layer.drawcolor"]', dest).attr("placeholder", defaults.drawcolor); } Hooks.on('canvasInit', () => { @@ -465,8 +489,19 @@ Hooks.on('init', async () => { } let etldata = item.data?.flags["enhanced-terrain-layer"]; //get all the enhanced terrain flags if (etldata) { - let data = { flags: { 'enhanced-terrain-layer': etldata } }; - template.data.update(data); + //let data = { _id: template.data.id, flags: { 'enhanced-terrain-layer': etldata } }; + if (setting("transfer-color")) { + let colour = setting('environment-color')[etldata.environment]; + if (colour) { + //data.fillColor = colour; + template.data.fillColor = colour; + template.data._source.fillColor = colour; + } + } + setProperty(template.data, "flags.enhanced-terrain-layer", etldata); + setProperty(template.data, "_source.flags.enhanced-terrain-layer", etldata); + //template.data.update(data); + } return template; } @@ -529,7 +564,7 @@ Hooks.on('renderMeasuredTemplateConfig', (app, html, data) => { ); } - addControlsv9(app, tab, false); + addControlsv9(app, tab); app.options.tabs = [{ navSelector: ".tabs", contentSelector: "form", initial: "basic" }]; app.options.height = "auto"; @@ -537,6 +572,10 @@ Hooks.on('renderMeasuredTemplateConfig', (app, html, data) => { const el = html[0]; app._tabs.forEach(t => t.bind(el)); + window.setTimeout(() => { + $(app.element).css({ "min-height": "" }); + }, 500); + app.setPosition(); } else { addControls(app, html); @@ -551,7 +590,7 @@ Hooks.on("renderSceneConfig", async (app, html, data) => { $('.sheet-tabs', html).append($('').addClass('item').attr('data-tab', "terrain").html(' Terrain')); let tab = $('
').addClass('tab').attr('data-tab', "terrain").insertAfter($('div[data-tab="ambience"]', html)); - addControlsv9(app, tab, true); + addControlsv9(app, tab, { full: true }); } else { let backgroundRow = $('input[name="backgroundColor"]', html).parent().parent(); @@ -592,8 +631,8 @@ Hooks.on("renderItemSheet", (app, html) => { if (app.object.hasAreaTarget) { if (isNewerVersion(game.version, "9")) { let details = $('.tab[data-tab="details"]', html); - details.append($('

').addClass('form-header').html('Terrain Effects')); - addControlsv9(app, details).then(() => { + let title = $('

').addClass('form-header').html('Terrain Effects').appendTo(details); + addControlsv9(app, title, { insert: true }).then(() => { const selectors = app.options.scrollY || []; const positions = app._scrollPositions || {}; app.setPosition({ height: 'auto' });