Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foundry v10 updates #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 10 additions & 8 deletions scene-tiler-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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);
Expand All @@ -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) };
}
Expand All @@ -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 ]
}
Expand Down Expand Up @@ -129,4 +131,4 @@ class STLayerSwitcher {
static async down() {
return this.next(false);
}
}
}
38 changes: 17 additions & 21 deletions scene-tiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -219,16 +215,16 @@ 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;
update.height = undefined;
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);
}

/**
Expand Down Expand Up @@ -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 });
}

/**
Expand All @@ -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)
}]);
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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);
});
}

Expand Down