Skip to content

Commit

Permalink
1.0.23 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
IronMonk88 committed Apr 28, 2021
1 parent 97bb398 commit e24e394
Show file tree
Hide file tree
Showing 14 changed files with 367 additions and 120 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Version 1.0.22
# Version 1.0.23
Fixing an issue with changing environment back to blank affecting the icon.

Merging environment and obstacles so that it's just one list. But added the option to set an item in the environment list as being an obstacle, so they can still be shown in separate lists. This fixes issues when using the option to use obstacles with environment. Setting an obstacle without an environment caused issues.

Adding a side menu to change the environment type from the terrain HUD.

Added integration with spells, so you can set the difficulty, environment, and terrain type of the spell and it will translate to the measured template produced. Only works for DnD5e right now, but if it gets added to more systems then I'll update it.

Fixed the image path names so that it wasn't hard coded to the enhanced terrain layer folder. And overriding the environment will now let you override the image used.

# Version 1.0.21
Added icons for the different environments

Expand Down
18 changes: 14 additions & 4 deletions classes/terrain.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ export class Terrain extends PlaceableObject {
let mult = Math.clamped(this.data.multiple, 0.5, 4);
this.texture = (mult != 1 ? await loadTexture(`modules/enhanced-terrain-layer/img/${mult}x.svg`) : null);

this.environment = canvas.terrain.getEnvironments().find(e => e.id == this.data.environment);
if (this.environment == undefined && !setting('use-obstacles'))
this.environment = canvas.terrain.getObstacles().find(e => e.id == this.data.environment);
this.updateEnvironment();

// Create the inner Terrain container
this._createTerrain();
Expand Down Expand Up @@ -268,7 +266,7 @@ export class Terrain extends PlaceableObject {
this.icon.border = this.icon.addChild(new PIXI.Graphics());
this.icon.border.clear().lineStyle(3, 0x000000).drawRoundedRect(0, 0, size, size, 4).beginFill(0x000000, 0.5).lineStyle(2, sc).drawRoundedRect(0, 0, size, size, 4).endFill();

this.icon.background = this.icon.addChild(new PIXI.Sprite.from("modules/enhanced-terrain-layer/img/environment/" + this.environment?.icon));
this.icon.background = this.icon.addChild(new PIXI.Sprite.from(this.environment?.icon));
this.icon.background.x = this.icon.background.y = 1;
this.icon.background.width = this.icon.background.height = size - 2;
}
Expand Down Expand Up @@ -507,6 +505,9 @@ export class Terrain extends PlaceableObject {
this.zIndex = parseInt(data.z) || 0;
}

if (data.environment != undefined)
this.updateEnvironment();

// Full re-draw or partial refresh
if (changed.has("multiple") || changed.has("environment"))
this.draw().then(() => super._onUpdate(data));
Expand Down Expand Up @@ -852,6 +853,9 @@ export class Terrain extends PlaceableObject {
await canvas.scene.update({ [key]: objectdata }, { diff: false });
canvas.terrain._costGrid = null;
}

if (data.environment != undefined)
this.updateEnvironment();
//await canvas.scene.setFlag("enhanced-terrain-layer", "terrain" + this.data._id, objectdata, {diff: false});
//if the multiple has changed then update the image
if (data.multiple != undefined || data.environment != undefined) {
Expand All @@ -868,4 +872,10 @@ export class Terrain extends PlaceableObject {
await this.scene.setFlag("enhanced-terrain-layer", "data", layerdata);
return this;
}

updateEnvironment() {
this.environment = canvas.terrain.getEnvironments().find(e => e.id == this.data.environment);
//if (this.environment == undefined && !setting('use-obstacles'))
// this.environment = canvas.terrain.getObstacles().find(e => e.id == this.data.environment);
}
}
26 changes: 13 additions & 13 deletions classes/terraincolor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ export class TerrainColor extends FormApplication {
getData(options) {
let colors = setting('environment-color');

let environmentColor = canvas.terrain.getEnvironments().map(c => {
if (colors[c.id] != undefined)
c.color = colors[c.id];
return c;
});

let obstacleColor = canvas.terrain.getObstacles().map(c => {
if (colors[c.id] != undefined)
c.color = colors[c.id];
return c;
});
var obstacleColor = [];
var environmentColor = canvas.terrain.getEnvironments().reduce(function (map, obj) {
if (colors[obj.id] != undefined)
obj.color = colors[obj.id];

if (obj.obstacle === true) {
obstacleColor.push(obj);
} else
map.push(obj);
return map;
}, []);

return {
main: colors['_default'] || { id:'_default', color:'#FFFFFF'},
Expand All @@ -55,10 +55,10 @@ export class TerrainColor extends FormApplication {
for (let env of canvas.terrain.getEnvironments()) {
updateColor(env.id, $('#' + env.id, this.element).val());
}

/*
for (let obs of canvas.terrain.getObstacles()) {
updateColor(obs.id, $('#' + obs.id, this.element).val());
}
}*/

game.settings.set('enhanced-terrain-layer', 'environment-color', colors).then(() => {
canvas.terrain.refresh(true);
Expand Down
30 changes: 27 additions & 3 deletions classes/terrainconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@ export class TerrainConfig extends FormApplication {
return map;
}, {});

var _obstacles = {};
var _environments = canvas.terrain.getEnvironments().reduce(function (map, obj) {
map[obj.id] = i18n(obj.text);

if (obj.obstacle === true) {
_obstacles[obj.id] = i18n(obj.text);
}else
map[obj.id] = i18n(obj.text);
return map;
}, {});

var _obstacles = canvas.terrain.getObstacles().reduce(function (map, obj) {
/*var _obstacles = canvas.terrain.getObstacles().reduce(function (map, obj) {
map[obj.id] = i18n(obj.text);
return map;
}, {});
}, {});*/

return {
object: duplicate(this.object.data),
Expand Down Expand Up @@ -71,5 +76,24 @@ export class TerrainConfig extends FormApplication {

activateListeners(html) {
super.activateListeners(html);


if (setting('use-obstacles')) {
$('select[name="environment"], select[name="obstacle"]', html).on('change', function () {
//make sure that the environment is always set if using obstacles
if ($('select[name="environment"]', html).val() == '' && $('select[name="obstacle"]', html).val() != '') {
$('select[name="environment"]', html).val($('select[name="obstacle"]', html).val());
$('select[name="obstacle"]', html).val('');
}

//make sure that obstacle is only set once, can't have an obstacle + obstacle, can only be environment + obstacle
if ($('select[name="environment"] option:selected', html).parent().attr('data-type') == 'obstacle' && $('select[name="obstacle"]', html).val() != '') {
if ($(this).attr('name') == 'obstacle') {
$('select[name="environment"]', html).val($('select[name="obstacle"]', html).val());
}
$('select[name="obstacle"]', html).val('');
};
});
}
}
}
69 changes: 68 additions & 1 deletion classes/terrainhud.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { TerrainLayer } from './terrainlayer.js';
import { log, setting, i18n } from '../terrain-main.js';

export class TerrainHUD extends BasePlaceableHUD {
_showEnvironments = false;

/** @override */
static get defaultOptions() {
Expand All @@ -10,17 +12,37 @@ export class TerrainHUD extends BasePlaceableHUD {
});
}

bind(object) {
this._showEnvironments = false;
return super.bind(object);
}

/* -------------------------------------------- */

/** @override */
getData() {
var _environments = canvas.terrain.getEnvironments().map(obj => {
obj.text = i18n(obj.text);
obj.active = (this.object.data.environment == obj.id);

return obj;
});

/*
var _obstacles = canvas.terrain.getObstacles().map(obj => {
obj.text = i18n(obj.text);
obj.active = (setting('use-obstacles') ? this.object.data.obstacle == obj.id : (this.object.data.environment || this.object.data.obstacle) == obj.id);
return obj;
});*/

const data = super.getData();
return mergeObject(data, {
lockedClass: data.locked ? "active" : "",
visibilityClass: data.hidden ? "active" : "",
cost: TerrainLayer.multipleText(this.object.multiple),
terraintype: this.object.terraintype,
environment: this.object.environment
environment: this.object.environment,
environments: _environments
});
}

Expand All @@ -29,6 +51,12 @@ export class TerrainHUD extends BasePlaceableHUD {

$('.inc-multiple', this.element).on("click", this._onHandleClick.bind(this, true));
$('.dec-multiple', this.element).on("click", this._onHandleClick.bind(this, false));
html.find(".environments > img").click(this._onClickEnvironments.bind(this));

html.find(".environment-list")
.on("click", ".environment-container", this._onToggleEnvironment.bind(this))
.on("contextmenu", ".environment-container", event => this._onToggleEnvironment(event));

/*
this.frame.handle.off("mouseover").off("mouseout").off("mousedown")
.on("mouseover", this._onHandleHoverIn.bind(this))
Expand All @@ -37,6 +65,45 @@ export class TerrainHUD extends BasePlaceableHUD {
this.frame.handle.interactive = true;*/
}

_onClickEnvironments(event) {
event.preventDefault();
this._toggleEnvironments(!this._showEnvironments);
}

/* -------------------------------------------- */

_toggleEnvironments(active) {
this._showEnvironments = active;
const button = this.element.find(".control-icon.environments")[0];
button.classList.toggle("active", active);
const palette = button.querySelector(".environment-list");
palette.classList.toggle("active", active);
}

/* -------------------------------------------- */

_onToggleEnvironment(event) {
event.preventDefault();
let ctrl = event.currentTarget;
let id = ctrl.dataset.environmentId;
$('.environment-list .environment-container.active', this.element).removeClass('active');
if (id != this.object.data.environment)
$('.environment-list .environment-container[data-environment-id="' + id + '"]', this.element).addClass('active');

const updates = this.layer.controlled.map(o => {
return { _id: o.id, environment: (id != this.object.data.environment ? id : '') };
});

this.layer.updateMany(updates).then(() => {
for (let terrain of this.layer.controlled) {
let data = updates.find(u => { return u._id == terrain.data._id });
terrain.update(data, { save: false }).then(() => {
$('.environments > img', this.element).attr('src', terrain?.environment?.icon || 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=');
});
}
});
}

/*
* async _onToggleVisibility(event) {
event.preventDefault();
Expand Down
53 changes: 32 additions & 21 deletions classes/terrainlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export let terraintypes = key => {
export let environments = key => {
return canvas.terrain.getEnvironments();
};

/*
export let obstacles = key => {
return canvas.terrain.getObstacles();
};
};*/

export class TerrainLayer extends PlaceablesLayer {
constructor() {
Expand Down Expand Up @@ -56,28 +56,34 @@ export class TerrainLayer extends PlaceablesLayer {

getEnvironments() {
return [
{ id: 'arctic', text: 'EnhancedTerrainLayer.environment.arctic', icon: 'arctic.png' },
{ id: 'coast', text: 'EnhancedTerrainLayer.environment.coast', icon: 'coast.png' },
{ id: 'desert', text: 'EnhancedTerrainLayer.environment.desert', icon: 'desert.png' },
{ id: 'forest', text: 'EnhancedTerrainLayer.environment.forest', icon: 'forest.png' },
{ id: 'grassland', text: 'EnhancedTerrainLayer.environment.grassland', icon: 'grassland.png' },
{ id: 'jungle', text: 'EnhancedTerrainLayer.environment.jungle', icon: 'jungle.png' },
{ id: 'mountain', text: 'EnhancedTerrainLayer.environment.mountain', icon: 'mountain.png' },
{ id: 'swamp', text: 'EnhancedTerrainLayer.environment.swamp', icon: 'swamp.png' },
{ id: 'underdark', text: 'EnhancedTerrainLayer.environment.underdark', icon: 'underdark.png' },
{ id: 'water', text: 'EnhancedTerrainLayer.environment.water', icon: 'water.png' }
{ id: 'arctic', text: 'EnhancedTerrainLayer.environment.arctic', icon: 'modules/enhanced-terrain-layer/img/environment/arctic.png' },
{ id: 'coast', text: 'EnhancedTerrainLayer.environment.coast', icon: 'modules/enhanced-terrain-layer/img/environment/coast.png' },
{ id: 'desert', text: 'EnhancedTerrainLayer.environment.desert', icon: 'modules/enhanced-terrain-layer/img/environment/desert.png' },
{ id: 'forest', text: 'EnhancedTerrainLayer.environment.forest', icon: 'modules/enhanced-terrain-layer/img/environment/forest.png' },
{ id: 'grassland', text: 'EnhancedTerrainLayer.environment.grassland', icon: 'modules/enhanced-terrain-layer/img/environment/grassland.png' },
{ id: 'jungle', text: 'EnhancedTerrainLayer.environment.jungle', icon: 'modules/enhanced-terrain-layer/img/environment/jungle.png' },
{ id: 'mountain', text: 'EnhancedTerrainLayer.environment.mountain', icon: 'modules/enhanced-terrain-layer/img/environment/mountain.png' },
{ id: 'swamp', text: 'EnhancedTerrainLayer.environment.swamp', icon: 'modules/enhanced-terrain-layer/img/environment/swamp.png' },
{ id: 'underdark', text: 'EnhancedTerrainLayer.environment.underdark', icon: 'modules/enhanced-terrain-layer/img/environment/underdark.png' },
{ id: 'water', text: 'EnhancedTerrainLayer.environment.water', icon: 'modules/enhanced-terrain-layer/img/environment/water.png' },

{ id: 'crowd', text: 'EnhancedTerrainLayer.obstacle.crowd', icon: 'modules/enhanced-terrain-layer/img/environment/crowd.png', obstacle: true },
{ id: 'current', text: 'EnhancedTerrainLayer.obstacle.current', icon: 'modules/enhanced-terrain-layer/img/environment/current.png', obstacle: true },
{ id: 'magic', text: 'EnhancedTerrainLayer.obstacle.magic', icon: 'modules/enhanced-terrain-layer/img/environment/magic.png', obstacle: true },
{ id: 'plants', text: 'EnhancedTerrainLayer.obstacle.plants', icon: 'modules/enhanced-terrain-layer/img/environment/plants.png', obstacle: true },
{ id: 'rubble', text: 'EnhancedTerrainLayer.obstacle.rubble', icon: 'modules/enhanced-terrain-layer/img/environment/rubble.png', obstacle: true }
];
}

/*
getObstacles() {
return [
{ id: 'crowd', text: 'EnhancedTerrainLayer.obstacle.crowd' },
{ id: 'current', text: 'EnhancedTerrainLayer.obstacle.current', icon: 'current.png' },
{ id: 'magic', text: 'EnhancedTerrainLayer.obstacle.magic', icon: 'magic.png' },
{ id: 'plants', text: 'EnhancedTerrainLayer.obstacle.plants', icon: 'plants.png' },
{ id: 'rubble', text: 'EnhancedTerrainLayer.obstacle.rubble', icon: 'rubble.png' }
{ id: 'crowd', text: 'EnhancedTerrainLayer.obstacle.crowd', icon: 'modules/enhanced-terrain-layer/img/environment/crowd.png' },
{ id: 'current', text: 'EnhancedTerrainLayer.obstacle.current', icon: 'modules/enhanced-terrain-layer/img/environment/current.png' },
{ id: 'magic', text: 'EnhancedTerrainLayer.obstacle.magic', icon: 'modules/enhanced-terrain-layer/img/environment/magic.png' },
{ id: 'plants', text: 'EnhancedTerrainLayer.obstacle.plants', icon: 'modules/enhanced-terrain-layer/img/environment/plants.png' },
{ id: 'rubble', text: 'EnhancedTerrainLayer.obstacle.rubble', icon: 'modules/enhanced-terrain-layer/img/environment/rubble.png' }
];
}
}*/

static multipleText(multiple) {
return (parseInt(multiple) == 0 || parseInt(multiple) == 0.5 ? '½' : multiple);
Expand Down Expand Up @@ -262,11 +268,16 @@ export class TerrainLayer extends PlaceablesLayer {
if (etl) {
for (let [k, v] of Object.entries(etl)) {
if (k.startsWith('terrain')) {
if (k != 'terrainundefined' && v != undefined && v.x != undefined && v.y != undefined)
if (k != 'terrainundefined' && v != undefined && v.x != undefined && v.y != undefined) {
if (v.environment == '' && v.obstacle != '') {
v.environment = v.obstacle;
v.obstacle = '';
}
if (v.points != undefined)
canvas.scene.data.terrain.push(v);
}
else
await canvas.scene.unsetFlag('enhanced-terrain-layer', k);
await canvas.scene.unsetFlag('enhanced-terrain-layer', k);
}
};
}
Expand Down
Loading

0 comments on commit e24e394

Please sign in to comment.