Skip to content

Commit

Permalink
1.0.31 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
IronMonk88 committed Jun 21, 2021
1 parent ae99c6e commit 04e1e4e
Show file tree
Hide file tree
Showing 30 changed files with 253 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#Version 1.0.31
Added option to ignore snap to grid when calculating cost

Added option to not show border

Added option to change the picture shown

#Version 1.0.30
Split terrainAt into two functions terrainFromPixel and terrainFromGrid to make it more understandable.

Expand Down
11 changes: 6 additions & 5 deletions classes/terrain.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ export class Terrain extends PlaceableObject {
this.clear();

let mult = Math.clamped(this.data.multiple, setting('minimum-cost'), setting('maximum-cost'));
this.texture = (mult != 1 ? await loadTexture(`modules/enhanced-terrain-layer/img/${mult}x.svg`) : null);
let image = setting('terrain-image');
this.texture = (mult != 1 ? await loadTexture(`modules/enhanced-terrain-layer/img/${image}${mult}x.svg`) : null);

this.updateEnvironment();

Expand Down Expand Up @@ -321,7 +322,7 @@ export class Terrain extends PlaceableObject {

/** @override */
refresh(icons) {
if (this._destroyed || this.drawing._destroyed) return;
if (this._destroyed || this.drawing?._destroyed || this.drawing == undefined) return;

this.drawing.clear();

Expand All @@ -331,15 +332,15 @@ export class Terrain extends PlaceableObject {
//const colors = CONFIG.Canvas.dispositionColors;
let sc = colorStringToHex(this.color); //this.data.hidden ? colorStringToHex("#C0C0C0") :
let lStyle = new PIXI.LineStyle();
mergeObject(lStyle, { width: s / 20, color: sc, alpha: 1, cap: PIXI.LINE_CAP.ROUND, join: PIXI.LINE_JOIN.ROUND, visible: true });
mergeObject(lStyle, { width: s / 20, color: sc, alpha: (setting('draw-border') ? 1 : 0), cap: PIXI.LINE_CAP.ROUND, join: PIXI.LINE_JOIN.ROUND, visible: true });
this.drawing.lineStyle(lStyle);

let drawAlpha = (ui.controls.activeControl == 'terrain' ? 1.0 : setting('opacity')); //this.data.hidden ? 0.5

// Fill Color or Texture
if (this.texture) {
let sW = (canvas.grid.w / (this.texture.width * 2));
let sH = (canvas.grid.h / (this.texture.height * 2));
let sW = (canvas.grid.w / (this.texture.width * (setting('terrain-image') == 'diagonal' ? 2 : 1)));
let sH = (canvas.grid.h / (this.texture.height * (setting('terrain-image') == 'diagonal' ? 2 : 1)));
this.drawing.beginTextureFill({
texture: this.texture,
color: sc,
Expand Down
28 changes: 19 additions & 9 deletions classes/terrainlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ export class TerrainLayer extends PlaceablesLayer {
let total = 0;
pts = pts instanceof Array ? pts : [pts];

const hx = (canvas.grid.type == CONST.GRID_TYPES.GRIDLESS ? 0 : canvas.grid.w / 2);
const hy = (canvas.grid.type == CONST.GRID_TYPES.GRIDLESS ? 0 : canvas.grid.h / 2);
const hx = (canvas.grid.type == CONST.GRID_TYPES.GRIDLESS || options.ignoreGrid === true ? 0 : canvas.grid.w / 2);
const hy = (canvas.grid.type == CONST.GRID_TYPES.GRIDLESS || options.ignoreGrid === true ? 0 : canvas.grid.h / 2);

let calculate = options.calculate || 'maximum';
let calculateFn;
Expand All @@ -143,15 +143,18 @@ export class TerrainLayer extends PlaceablesLayer {

for (let pt of pts) {
let cost = null;
let [gx, gy] = (canvas.grid.type == CONST.GRID_TYPES.GRIDLESS ? [pt.x, pt.y] : canvas.grid.grid.getPixelsFromGridPosition(pt.y, pt.x));
let [gx, gy] = (canvas.grid.type == CONST.GRID_TYPES.GRIDLESS || options.ignoreGrid === true ? [pt.x, pt.y] : canvas.grid.grid.getPixelsFromGridPosition(pt.y, pt.x));

let elevation = (options.elevation === false ? null : (options.elevation != undefined ? options.elevation : options?.token?.data?.elevation));
let tokenId = options.tokenId || options?.token?.id;

let tx = (gx + hx);
let ty = (gy + hy);

//get the cost for the terrain layer
for (let terrain of this.placeables) {
const testX = (gx + hx) - terrain.data.x;
const testY = (gy + hy) - terrain.data.y;
const testX = tx - terrain.data.x;
const testY = ty - terrain.data.y;
if (terrain.multiple != 1 &&
!options.ignore?.includes(terrain.data.environment) &&
!(elevation < terrain.data.min || elevation > terrain.data.max) &&
Expand Down Expand Up @@ -180,8 +183,8 @@ export class TerrainLayer extends PlaceablesLayer {

//get the cost for any measured templates, ie spells
for (let measure of canvas.templates.placeables) {
const testX = (gx + hx) - measure.data.x;
const testY = (gy + hy) - measure.data.y;
const testX = tx - measure.data.x;
const testY = ty - measure.data.y;
let terrainFlag = measure.data.flags['enhanced-terrain-layer'];
if (terrainFlag) {
let terraincost = terrainFlag.multiple || 2;
Expand Down Expand Up @@ -217,8 +220,8 @@ export class TerrainLayer extends PlaceablesLayer {
for (let token of canvas.tokens.placeables) {
let dead = token.actor?.effects.find(e => e.getFlag("core", "statusId") === CONFIG.Combat.defeatedStatusId);
if (token.id != tokenId && !token.data.hidden && (elevation == undefined || token.data.elevation == elevation) && (!dead || setting("dead-cause-difficult"))) {
const testX = (gx + hx);
const testY = (gy + hy);
const testX = tx;
const testY = ty;
if (!(testX < token.data.x || testX > token.data.x + (token.data.width * canvas.grid.w) || testY < token.data.y || testY > token.data.y + (token.data.height * canvas.grid.h))) {
let terraincost = 2;
let detail = { object: token, cost: terraincost };
Expand Down Expand Up @@ -831,4 +834,11 @@ export class TerrainLayer extends PlaceablesLayer {
terrain.refresh(icons);
}
}

//refresh all the terrain on this layer
redraw() {
for (let terrain of this.placeables) {
terrain.draw();
}
}
}
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
15 changes: 15 additions & 0 deletions img/horizontal0.5x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions img/horizontal2x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions img/horizontal3x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions img/horizontal4x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions img/oldschool0.5x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions img/oldschool2x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions img/oldschool3x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions img/oldschool4x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions img/solid0.5x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions img/solid2x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions img/solid3x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions img/solid4x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions img/triangle0.5x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions img/triangle2x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions img/triangle3x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions img/triangle4x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions img/vertical0.5x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions img/vertical2x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions img/vertical3x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions img/vertical4x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import { TerrainColor } from "../classes/terraincolor.js";
export const registerSettings = function () {
let modulename = "enhanced-terrain-layer";

let imageoptions = {
'solid': 'Solid',
'diagonal': 'Diagonal',
'oldschool': 'Old School',
'triangle': 'Triangle',
'horizontal': 'Horizontal',
'vertical': 'Vertical'
};

game.settings.registerMenu(modulename, 'edit-colors', {
name: 'Edit Colors',
label: 'Edit Colors',
Expand Down Expand Up @@ -31,6 +40,29 @@ export const registerSettings = function () {
canvas.terrain.refresh();
}
});
game.settings.register(modulename, 'draw-border', {
name: "EnhancedTerrainLayer.draw-border.name",
hint: "EnhancedTerrainLayer.draw-border.hint",
scope: "world",
config: true,
default: true,
type: Boolean,
onChange: () => {
canvas.terrain.refresh();
}
});
game.settings.register(modulename, 'terrain-image', {
name: "EnhancedTerrainLayer.terrain-image.name",
hint: "EnhancedTerrainLayer.terrain-image.hint",
scope: "world",
config: true,
default: 'diagonal',
type: String,
choices: imageoptions,
onChange: () => {
canvas.terrain.redraw();
}
});
game.settings.register(modulename, 'show-text', {
name: "EnhancedTerrainLayer.show-text.name",
hint: "EnhancedTerrainLayer.show-text.hint",
Expand Down
4 changes: 4 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
"EnhancedTerrainLayer.maximum-cost.hint": "Maximum cost you can set difficult terrain to",
"EnhancedTerrainLayer.dead-cause-difficult.name": "Dead cause difficult terrain",
"EnhancedTerrainLayer.dead-cause-difficult.hint": "Dead tokens cause difficult terrain",
"EnhancedTerrainLayer.draw-border.name": "Draw Border",
"EnhancedTerrainLayer.draw-border.hint": "Set if the border is drawn or not",
"EnhancedTerrainLayer.terrain-image.name": "Terrain Image",
"EnhancedTerrainLayer.terrain-image.hint": "Change the backgraound texture for terrain",

"EnhancedTerrainLayer.environment.arctic": "Arctic",
"EnhancedTerrainLayer.environment.coast": "Coast",
Expand Down
Loading

0 comments on commit 04e1e4e

Please sign in to comment.