Skip to content

Commit

Permalink
1.0.17 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
IronMonk88 committed Mar 29, 2021
1 parent b207a41 commit 53aef97
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#Version 1.0.17
Added function to try and copy old data from TerrainLayer

Changed the way environment and terraintype are handled to better override

#Version 1.0.16
Fixed an issue with ignoring environment

Expand Down
10 changes: 5 additions & 5 deletions classes/terrainlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { TerrainHUD } from './terrainhud.js';
import { makeid, log, error, i18n, setting } from '../terrain-main.js';

export let terraintype = key => {
return TerrainLayer.terraintype;
return canvas.terrain.terraintype();
};

export let environment = key => {
return TerrainLayer.environment();
return canvas.terrain.environment();
};

export class TerrainLayer extends PlaceablesLayer {
Expand Down Expand Up @@ -43,11 +43,11 @@ export class TerrainLayer extends PlaceablesLayer {
return [0.5, 1, 2, 3, 4];
}

static get terraintype() {
terraintype() {
return [{ id: 'ground', text: 'Ground' }, { id: 'air', text: 'Air Only' }, { id: 'both', text: 'Air & Ground' }];
}

static environment() {
environment() {
return [
{ id: '', text: '' },
{ id: 'arctic', text: 'Arctic' },
Expand Down Expand Up @@ -87,7 +87,7 @@ export class TerrainLayer extends PlaceablesLayer {
let cost = 0;
let [gx, gy] = canvas.grid.grid.getPixelsFromGridPosition(pt.y, pt.x);

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

//get the cost for the terrain layer
Expand Down
7 changes: 7 additions & 0 deletions js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ export const registerSettings = function () {
default: false,
type: Boolean
});

game.settings.register(modulename, 'conversion', {
scope: "world",
config: false,
default: false,
type: Boolean
});
};
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "enhanced-terrain-layer",
"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": "1.0.16",
"version": "1.0.17",
"author": "IronMonk, ironmonk88#4075",
"socket": true,
"languages": [
Expand Down Expand Up @@ -30,7 +30,7 @@
"styles": [ "css/terrainlayer.css" ],
"packs": [],
"url" : "https://github.com/ironmonk88/enhanced-terrain-layer",
"download" : "https://github.com/ironmonk88/enhanced-terrain-layer/archive/1.0.16.zip",
"download" : "https://github.com/ironmonk88/enhanced-terrain-layer/archive/1.0.17.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
44 changes: 44 additions & 0 deletions terrain-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,43 @@ function registerLayer() {
});
}

async function checkUpgrade() {
let hasInformed = false;
let inform = function () {
if (!hasInformed) {
ui.notifications.info('Converting old TerrainLayer data, please wait');
hasInformed = true;
}
}

for (let scene of game.scenes.entries) {
if (scene.data.flags?.TerrainLayer) {
let gW = scene.data.grid;
let gH = scene.data.grid;

let data = duplicate(scene.data.flags?.TerrainLayer);
for (let [k, v] of Object.entries(data)) {
if (k == 'costGrid') {
let grid = scene.getFlag('TerrainLayer', 'costGrid');
for (let y in grid) {
for (let x in grid[y]) {
//if (Object.values(data).find(t => { return t.x == (parseInt(x) * gW) && t.y == (parseInt(y) * gH); }) == undefined) {
inform();
let id = makeid();
let data = { _id: id, x: parseInt(x) * gW, y: parseInt(y) * gH, points: [[0, 0], [gW, 0], [gW, gH], [0, gH], [0, 0]], width: gW, height: gH, multiple: grid[y][x].multiple };
await scene.setFlag('enhanced-terrain-layer', 'terrain' + id, data);
//}
}
}
}
};
}
}

if (hasInformed)
ui.notifications.info('TerrainLayer conversion complete.');
}

export function makeid() {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
Expand All @@ -45,6 +82,13 @@ Hooks.on('canvasInit', () => {
//Scene.constructor.config.embeddedEntities.Terrain = "terrain";
});

Hooks.on('ready', () => {
if (game.user.isGM && !setting('conversion')) {
checkUpgrade();
game.settings.set('enhanced-terrain-layer', 'conversion', true);
}
})

Hooks.on('init', () => {
game.socket.on('module.enhanced-terrain-layer', async (data) => {
console.log(data);
Expand Down

0 comments on commit 53aef97

Please sign in to comment.