diff --git a/CHANGELOG.md b/CHANGELOG.md index 24391fb..8f4421f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/classes/terrainlayer.js b/classes/terrainlayer.js index 876d755..7667742 100644 --- a/classes/terrainlayer.js +++ b/classes/terrainlayer.js @@ -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 { @@ -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' }, @@ -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 diff --git a/js/settings.js b/js/settings.js index 13fb7a4..34fb586 100644 --- a/js/settings.js +++ b/js/settings.js @@ -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 + }); }; \ No newline at end of file diff --git a/module.json b/module.json index 89879a7..5a8a108 100644 --- a/module.json +++ b/module.json @@ -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": [ @@ -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, diff --git a/terrain-main.js b/terrain-main.js index 70c2f65..ae85c72 100644 --- a/terrain-main.js +++ b/terrain-main.js @@ -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'; @@ -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);