Skip to content

Commit

Permalink
1.0.18 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
IronMonk88 committed Apr 5, 2021
1 parent 3d1bbb9 commit f3cda85
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 35 deletions.
53 changes: 24 additions & 29 deletions classes/terrainlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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] });
}
});
});
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions js/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Hooks.on('getSceneControlButtons', (controls) => {
visible: isGM,
layer: 'TerrainLayer',
activeTool: 'select',
flags: {
'enhanced-terrain-layer': { valid: true }
},
tools: [
{
name: 'select',
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
17 changes: 13 additions & 4 deletions terrain-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,35 @@ 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;
Token.prototype._onDragLeftCancel = function (event) {
//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])
}
Expand Down

0 comments on commit f3cda85

Please sign in to comment.