Skip to content

Commit

Permalink
10.6 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ironmonk88 committed Nov 11, 2022
1 parent c62b443 commit bfc767c
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 28 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 4 additions & 2 deletions classes/terrain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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),
Expand Down
16 changes: 10 additions & 6 deletions classes/terrainlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 7 additions & 9 deletions templates/terrain-form.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
{{#if full}}
<p class="notes">Set the default settings when terrain is created on this scene</p>
<div class="form-group">
<label>{{localize "EnhancedTerrainLayer.opacity.name"}}</label>
<div class="form-fields">
<input type="range" dtype="Number" min="0" max="1.0" step="0.1" name="flags.enhanced-terrain-layer.opacity" value="{{data.opacity}}">
<span class="range-value" style="flex: 0 1 48px;">{{data.opacity}}</span>
<input type="range" dtype="Number" min="0" max="1.0" step="0.1" value="{{rangeOpacity}}">
<input type="text" class="range-value" style="flex: 0 1 48px;" name="flags.enhanced-terrain-layer.opacity" placeholder="{{defaults.opacity}}" value="{{data.opacity}}">
</div>
<p class="notes">Set the opacity for all terrain on this scene</p>
</div>
<hr />
<p class="notes">Set the default settings when terrain is created on this scene</p>
{{/if}}
<div class="form-group">
<label for="multiple">{{localize "EnhancedTerrainLayer.Cost"}}</label>
<input type="number" name="flags.enhanced-terrain-layer.multiple" step="any" value="{{data.multiple}}" style="flex: 0 0 80px; text-align: right;">
<input type="number" name="flags.enhanced-terrain-layer.multiple" step="any" placeholder="{{defaults.multiple}}" value="{{data.multiple}}" style="flex: 0 0 80px; text-align: right;">
</div>
<div class="form-group">
<label for="elevation">{{localize "EnhancedTerrainLayer.TerrainElevation"}}</label>
<input type="number" name="flags.enhanced-terrain-layer.elevation" step="any" value="{{data.elevation}}" style="flex: 0 0 80px; text-align: right;">
<input type="number" name="flags.enhanced-terrain-layer.elevation" step="any" placeholder="{{defaults.elevation}}" value="{{data.elevation}}" style="flex: 0 0 80px; text-align: right;">
</div>
<div class="form-group">
<label for="depth">{{localize "EnhancedTerrainLayer.TerrainDepth"}}</label>
<input type="number" name="flags.enhanced-terrain-layer.depth" step="any" value="{{data.depth}}" style="flex: 0 0 80px; text-align: right;">
<input type="number" name="flags.enhanced-terrain-layer.depth" step="any" placeholder="{{defaults.depth}}" value="{{data.depth}}" style="flex: 0 0 80px; text-align: right;">
</div>
<div class="form-group">
<label for="environment">{{localize "EnhancedTerrainLayer.Environment"}}</label>
Expand Down Expand Up @@ -50,7 +48,7 @@
<div class="form-group">
<label for="flags.enhanced-terrain-layer.drawcolor">{{localize "EnhancedTerrainLayer.TerrainColor"}}</label>
<div class="form-fields">
{{ colorPicker name="drawcolor" value=data.drawcolor}}
{{ colorPicker name="flags.enhanced-terrain-layer.drawcolor" value=data.drawcolor}}
</div>
</div>
{{/if}}
57 changes: 48 additions & 9 deletions terrain-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -285,16 +285,40 @@ 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
};
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', () => {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -529,14 +564,18 @@ 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";
app._tabs = app._createTabHandlers();
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);
Expand All @@ -551,7 +590,7 @@ Hooks.on("renderSceneConfig", async (app, html, data) => {
$('.sheet-tabs', html).append($('<a>').addClass('item').attr('data-tab', "terrain").html('<i class="fas fa-mountain"></i> Terrain'));
let tab = $('<div>').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();

Expand Down Expand Up @@ -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($('<h3>').addClass('form-header').html('Terrain Effects'));
addControlsv9(app, details).then(() => {
let title = $('<h3>').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' });
Expand Down

0 comments on commit bfc767c

Please sign in to comment.