From f3cda85cbe0bec1dfa1a472f14cf883bcb2566db Mon Sep 17 00:00:00 2001 From: IronMonk88 Date: Mon, 5 Apr 2021 15:54:30 -0700 Subject: [PATCH] 1.0.18 changes --- classes/terrainlayer.js | 53 +++++++++++++++++++---------------------- js/controls.js | 5 ++-- js/settings.js | 8 +++++++ lang/en.json | 2 ++ terrain-main.js | 17 +++++++++---- 5 files changed, 50 insertions(+), 35 deletions(-) diff --git a/classes/terrainlayer.js b/classes/terrainlayer.js index 0e0ac9b..9bd5ab3 100644 --- a/classes/terrainlayer.js +++ b/classes/terrainlayer.js @@ -67,7 +67,7 @@ export class TerrainLayer extends PlaceablesLayer { } /* -------------------------------------------- */ - + //Remove once moved off TerrainLayer get costGrid() { console.warn('costGrid is deprecated, please use the cost function instead'); if (this._costGrid == undefined) { @@ -76,6 +76,12 @@ export class TerrainLayer extends PlaceablesLayer { return this._costGrid; } + get highlight() { + return { children: [{visible: false}] }; + } + +/* -------------------------------------------- */ + cost(pts, options = {}) { let reduceFn = function (cost, reduce) { let value = parseFloat(reduce.value); @@ -399,7 +405,7 @@ export class TerrainLayer extends PlaceablesLayer { updates[key] = null; if (game.user.isGM) - game.socket.emit('module.enhanced-terrain-layer', { action: 'deleteTerrain', arguments: [id] }); + game.socket.emit('module.enhanced-terrain-layer', { action: '_deleteTerrain', arguments: [id] }); } if (!options.isUndo) @@ -503,16 +509,8 @@ export class TerrainLayer extends PlaceablesLayer { const data = preview.data; // Adjust the final data - const createData = Terrain.normalizeShape(data); - - // Create the object + this.createTerrain(data); preview._chain = false; - preview.constructor.create(createData).then(d => { - d._creating = true; - if (game.user.isGM) { - game.socket.emit('module.enhanced-terrain-layer', { action: 'createTerrain', arguments: [createData] }); - } - }); } // Cancel the preview @@ -604,7 +602,7 @@ export class TerrainLayer extends PlaceablesLayer { return Terrain.create(data).then(d => { d._creating = true; if (game.user.isGM) { - game.socket.emit('module.enhanced-terrain-layer', { action: 'createTerrain', arguments: [data] }); + game.socket.emit('module.enhanced-terrain-layer', { action: '_createTerrain', arguments: [data] }); } }); }); @@ -644,32 +642,29 @@ export class TerrainLayer extends PlaceablesLayer { return changed; }*/ - /* - createTerrain(data, options = { }) { - if (!this.terrainExists(data.x, data.y)) { - data.multiple = data.multiple || this.defaultmultiple; - this.constructor.placeableClass.create(data, options).then((terrain) => { - if (this.originals != undefined) - this.originals.push(terrain); - }); - } - this._costGrid = null; - }*/ - /* - terrainExists(pxX, pxY) { - return canvas.scene.data.terrain.find(t => { return t.x == pxX && t.y == pxY }) != undefined; - }*/ + createTerrain(data) { + data = mergeObject(Terrain.defaults, data); + const createData = Terrain.normalizeShape(data); + + // Create the object + Terrain.create(createData).then(d => { + d._creating = true; + if (game.user.isGM) { + game.socket.emit('module.enhanced-terrain-layer', { action: '_createTerrain', arguments: [createData] }); + } + }); + } //This is used for players, to add an remove on the fly - createTerrain(data, options = {}) { + _createTerrain(data, options = {}) { let userId = game.user._id; let object = canvas.terrain.createObject(data); object._onCreate(options, userId); canvas.scene.data.terrain.push(data); } - deleteTerrain(id, options = {}) { + _deleteTerrain(id, options = {}) { const object = this.get(id); this.objects.removeChild(object); object._onDelete(options, game.user.id); diff --git a/js/controls.js b/js/controls.js index 8d6c26e..c630049 100644 --- a/js/controls.js +++ b/js/controls.js @@ -9,6 +9,9 @@ Hooks.on('getSceneControlButtons', (controls) => { visible: isGM, layer: 'TerrainLayer', activeTool: 'select', + flags: { + 'enhanced-terrain-layer': { valid: true } + }, tools: [ { name: 'select', @@ -42,8 +45,6 @@ Hooks.on('getSceneControlButtons', (controls) => { } ] }); - //show the terrain if show button is toggled, or if the current tool is the terrain tool - //canvas.terrain.highlight.children[0].visible = (canvas.terrain.showterrain || controls["terrain"].active); }); Hooks.on('renderSceneControls', (controls) => { if (canvas != null) { diff --git a/js/settings.js b/js/settings.js index ab199a3..5763712 100644 --- a/js/settings.js +++ b/js/settings.js @@ -25,6 +25,14 @@ export const registerSettings = function () { canvas.terrain.refresh(); } }); + game.settings.register(modulename, 'show-on-drag', { + name: "EnhancedTerrainLayer.show-on-drag.name", + hint: "EnhancedTerrainLayer.show-on-drag.hint", + scope: "world", + config: true, + default: true, + type: Boolean + }); game.settings.register(modulename, 'tokens-cause-difficult', { name: "EnhancedTerrainLayer.tokens-cause-difficult.name", hint: "EnhancedTerrainLayer.tokens-cause-difficult.hint", diff --git a/lang/en.json b/lang/en.json index a016ae2..ba7b56d 100644 --- a/lang/en.json +++ b/lang/en.json @@ -18,6 +18,8 @@ "EnhancedTerrainLayer.opacity.hint": "Opacity of the Icon and Number.", "EnhancedTerrainLayer.showText.name": "Show Text", "EnhancedTerrainLayer.showText.hint": "Show the text of how difficult the terrain is.", + "EnhancedTerrainLayer.show-on-drag.name": "Show on drag", + "EnhancedTerrainLayer.show-on-drag.hint": "Show the terrain highlight when a token is dragged", "EnhancedTerrainLayer.tokens-cause-difficult.name": "Tokens cause difficult Terrain", "EnhancedTerrainLayer.tokens-cause-difficult.hint": "When a token is dragged over another token, it's considered difficult terrain." } diff --git a/terrain-main.js b/terrain-main.js index ae85c72..9bb8529 100644 --- a/terrain-main.js +++ b/terrain-main.js @@ -98,17 +98,25 @@ Hooks.on('init', () => { registerSettings(); registerLayer(); + //remove old layer's controls + let oldGetControlButtons = SceneControls.prototype._getControlButtons; + SceneControls.prototype._getControlButtons = function () { + let controls = oldGetControlButtons(); + controls.findSplice(c => c.name == 'terrain' && c.flags == undefined); + return controls; + } + let oldOnDragLeftStart = Token.prototype._onDragLeftStart; Token.prototype._onDragLeftStart = function (event) { oldOnDragLeftStart.apply(this, [event]) if (canvas != null) - canvas.terrain.visible = (canvas.grid.type != 0); + canvas.terrain.visible = (canvas.terrain.showterrain || ui.controls.activeControl == 'terrain' || setting('show-on-drag')); } let oldOnDragLeftDrop = Token.prototype._onDragLeftDrop; Token.prototype._onDragLeftDrop = function (event) { if (canvas != null) - canvas.terrain.visible = (canvas.grid.type != 0 && (canvas.terrain.showterrain || ui.controls.activeControl == 'terrain')); + canvas.terrain.visible = (canvas.terrain.showterrain || ui.controls.activeControl == 'terrain' || setting('show-on-drag')); oldOnDragLeftDrop.apply(this, [event]); } let oldOnDragLeftCancel = Token.prototype._onDragLeftCancel; @@ -116,8 +124,9 @@ Hooks.on('init', () => { //event.stopPropagation(); const ruler = canvas.controls.ruler; - if (canvas != null && !(ruler.isDragRuler || ruler._state === Ruler.STATES.MEASURING)) - canvas.terrain.visible = (canvas.grid.type != 0 && (canvas.terrain.showterrain || ui.controls.activeControl == 'terrain')); + log('ruler', ruler); + if (canvas != null && ruler._state !== Ruler.STATES.MEASURING) + canvas.terrain.visible = (canvas.terrain.showterrain || ui.controls.activeControl == 'terrain'); oldOnDragLeftCancel.apply(this, [event]) }