From 00ad6e53e14f438d01e97af69f550320219c843b Mon Sep 17 00:00:00 2001 From: Arne Link Date: Wed, 19 Oct 2022 10:17:17 +0200 Subject: [PATCH] update for foundry v10 --- module.json | 8 ++++++-- scene-tiler-helpers.js | 18 ++++++++++-------- scene-tiler.js | 38 +++++++++++++++++--------------------- 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/module.json b/module.json index 90f57ae..5db473f 100644 --- a/module.json +++ b/module.json @@ -12,8 +12,12 @@ } ], "version": "2.1.0", - "minimumCoreVersion": "0.8.5", - "compatibleCoreVersion": "0.8.9", + "manifestPlusVersion": "1.2.0", + "compatibility": { + "minimum": 10, + "verified": 10, + "maximum": 10 + }, "scripts": [ "entity-translators.js", "scene-tiler-helpers.js", diff --git a/scene-tiler-helpers.js b/scene-tiler-helpers.js index 9614a08..bb1a8cb 100644 --- a/scene-tiler-helpers.js +++ b/scene-tiler-helpers.js @@ -21,12 +21,12 @@ class SceneTilerHelpers { * @memberof SceneTilerHelpers */ static getScaleFactor(source, target) { - if (source.gridUnits != target.gridUnits) + if (source.grid.units != target.grid.units) ui.notifications.warn(game.i18n.localize("SCNTILE.notifications.warn.unmatchedUnits")); const distScale = - STEntityTranslators.calculateScaleFactor(source.gridDistance, target.gridDistance) - return STEntityTranslators.calculateScaleFactor(source.grid, target.grid) / distScale; + STEntityTranslators.calculateScaleFactor(source.grid.distance, target.grid.distance) + return STEntityTranslators.calculateScaleFactor(source.grid.size, target.grid.size) / distScale; } /** @@ -47,7 +47,7 @@ class SceneTilerHelpers { * @memberof SceneTilerHelpers */ static getTilePos(source, x, y, centered = true) { - const scale = this.getScaleFactor(source, canvas.scene.data); + const scale = this.getScaleFactor(source, canvas.scene); const { width, height } = STEntityTranslators.getScaledTileSize(source, scale); @@ -56,8 +56,10 @@ class SceneTilerHelpers { x = x - width / 2; y = y - height / 2; } - - if (!canvas.grid.hitArea.contains(x, y)) x = y = 0; + + const d = game.canvas.dimensions; + x = Math.clamped(x, 0, d.width-1); + y = Math.clamped(y, 0, d.height-1); return { width, height, ...canvas.grid.getSnappedPosition(x, y) }; } @@ -71,7 +73,7 @@ class SceneTilerHelpers { * @memberof SceneTilerHelpers */ static getPadding(source) { - const padding = source.padding, grid = source.grid; + const padding = source.padding, grid = source.grid.size; return [ Math.ceil(source.width / grid * padding) * grid, Math.ceil(source.height / grid * padding) * grid ] } @@ -129,4 +131,4 @@ class STLayerSwitcher { static async down() { return this.next(false); } -} \ No newline at end of file +} diff --git a/scene-tiler.js b/scene-tiler.js index d6e0e78..4bcc145 100644 --- a/scene-tiler.js +++ b/scene-tiler.js @@ -101,15 +101,15 @@ class SceneTiler { static async create(scene, { x, y, rotation, populate, centered } = {}) { const tiles = await this.createTile( scene, scene.uuid, - x ?? game.canvas.scene.data.width / 2, - y ?? game.canvas.scene.data.height / 2, + x ?? game.canvas.scene.width / 2, + y ?? game.canvas.scene.height / 2, rotation ?? 0, centered ?? false, populate ?? false ); const tile = tiles[0]; - if (populate) await this.deploySceneTile(tile.data); + if (populate) await this.deploySceneTile(tile); return tile; } @@ -154,7 +154,7 @@ class SceneTiler { * @memberof SceneTiler */ static async setTileState(tile, state) { - if (tile.data.flags["scene-tiler"]?.scene) + if (tile.flags["scene-tiler"]?.scene) return await tile.update({ locked: state }); else { const message = game.i18n.localize("scene-tiler.notifications.warn.notaSceneTile"); @@ -184,13 +184,9 @@ class SceneTiler { * @return {Object|void} The created tile, or returns early if not dropping a Scene or if the source isn't found * @memberof SceneTiler */ - static async dropCanvasData(canvas, { id, type, pack, x, y }) { + static async dropCanvasData(canvas, { id, type, uuid, x, y }) { if (type != "Scene") return; - let uuid = ""; - if (pack) uuid = `Compendium.${pack}.${id}`; - else uuid = `${type}.${id}`; - const source = await fromUuid(uuid); if (!source) { @@ -219,7 +215,7 @@ class SceneTiler { if ( typeof update?.locked == "undefined" && typeof update?.width == "undefined" && typeof update?.height == "undefined" || - !tileDoc.data?.flags["scene-tiler"]?.scene ) return; + !tileDoc?.flags["scene-tiler"]?.scene ) return; if (update.width || update.height) { update.width = undefined; @@ -227,8 +223,8 @@ class SceneTiler { ui.notifications.warn(game.i18n.localize("SCNTILE.notifications.warn.noResize")); } - if (update.locked) this.deploySceneTile(tileDoc.data); - else this.clearSceneTile(tileDoc.data); + if (update.locked) this.deploySceneTile(tileDoc); + else this.clearSceneTile(tileDoc); } /** @@ -269,7 +265,7 @@ class SceneTiler { if (!entities) continue; await canvas.scene.deleteEmbeddedDocuments(def.className, entities); } - await canvas.background.get(data._id).document.update({ "flags.scene-tiler.entities": null }); + await canvas.tiles.get(data._id).document.update({ "flags.scene-tiler.entities": null }); } /** @@ -292,10 +288,10 @@ class SceneTiler { */ static async createTile(source, uuid, x, y, rotation = 0, centered = true, locked = false) { return await canvas.scene.createEmbeddedDocuments("Tile", [{ - img: source.img || "modules/scene-tiler/_Blank.png", + img: source.background.src || "modules/scene-tiler/_Blank.png", flags: { "scene-tiler": { scene: uuid } }, rotation, locked, - ...this.Helpers.getTilePos(source.data, x, y, centered) + ...this.Helpers.getTilePos(source, x, y, centered) }]); } @@ -318,7 +314,7 @@ class SceneTiler { const flagData = this.getObjectIds(createdObjects); - await canvas.background.get(tileData._id).document.update({ "flags.scene-tiler.entities": flagData }); + await canvas.tiles.get(tileData._id).document.update({ "flags.scene-tiler.entities": flagData }); Hooks.callAll("createPlaceableObjects", canvas.scene, createdObjects, {}, game.userId); } @@ -382,10 +378,10 @@ class SceneTiler { */ static getObjects(source, tile) { const objects = {}; - const [px, py] = this.Helpers.getPadding(source.data); + const [px, py] = this.Helpers.getPadding(source); /** @type {Number} The ratio of grid size between source and target scenes */ - const scale = this.Helpers.getScaleFactor(source.data, canvas.scene.data); + const scale = this.Helpers.getScaleFactor(source, canvas.scene); for (const def of this.layers) { const entities = this.prepareObjects(source, def.type, tile, scale, px, py); @@ -413,7 +409,7 @@ class SceneTiler { */ static getForegroundTile(tiles, source, tile, scale) { // If there isn't a foreground image, do nothing. - if (!source.data.foreground) return; + if (!source.foreground) return; /** @type {number} The lowest z value of any overhead tile */ const minZ = tiles @@ -422,7 +418,7 @@ class SceneTiler { // The primary data of the new tile const foreground = { - img: source.data.foreground, + img: source.foreground.src, overhead: true, occlusion: { mode: 0 }, // Mode 0 is no occlusion, this tile is always visible x: tile.x, y: tile.y, @@ -451,7 +447,7 @@ class SceneTiler { return source[type].map(entity => { if (type == this.layerDefs.tiles.type) entity.z += tile.z; - return this.translateEntity(entity.data.toObject(), type, tile, ...spxy); + return this.translateEntity(entity.toObject(), type, tile, ...spxy); }); }