Skip to content

Commit

Permalink
Fill in any new config defaults when loading DungeonState.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcglincy committed Nov 14, 2021
1 parent 57df6e8 commit 46a7c97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion scripts/dungeonstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export class DungeonState {
return DungeonState.startState();
}
const obj = JSON.parse(s);
return new DungeonState(geo.wktToGeometry(obj.wkt), obj.doors, obj.config);
const geometry = geo.wktToGeometry(obj.wkt);
// fill in any new defaults
const config = foundry.utils.mergeObject(Dungeon.defaultConfig(), obj.config);
return new DungeonState(geometry, obj.doors, config);
}

/* -------------------------------------------- */
Expand Down
8 changes: 4 additions & 4 deletions scripts/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const render = async (container, state) => {
drawPolygonMask(clipMask, state.geometry);
}
container.addChild(clipMask);
await addTiledBackground(container, clipMask, state);
await addTiledBackground(container, clipMask, state.config, state.geometry);
}

// draw the dungeon geometry room(s)
Expand All @@ -39,8 +39,8 @@ export const render = async (container, state) => {
container.addChild(gfx);
}

const addTiledBackground = async (container, mask, state) => {
const texture = await loadTexture(state.config.floorTexture);
const addTiledBackground = async (container, mask, config, geometry) => {
const texture = await loadTexture(config.floorTexture);
if (!texture?.valid) {
return;
}
Expand All @@ -64,7 +64,7 @@ const addTiledBackground = async (container, mask, state) => {
[col * textureSize, (row + 1) * textureSize],
[col * textureSize, row * textureSize],
]);
if (state.geometry.intersects(rect) && !state.geometry.touches(rect)) {
if (geometry.intersects(rect) && !geometry.touches(rect)) {
const sprite = new PIXI.TilingSprite(texture, textureSize, textureSize);
sprite.x = col * textureSize;
sprite.y = row * textureSize;
Expand Down

0 comments on commit 46a7c97

Please sign in to comment.