Skip to content

Commit

Permalink
Merge branch 'release/0.8.2' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Nov 3, 2024
2 parents 2536d5b + 782749f commit cb79b3d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.8.2
Improve performance for token animation after a drag operation. Addresses #20.

## 0.8.1
Fix for scene not loading due to errors with rendering cached walls when Elevation Ruler v0.10.12 is active.

Expand Down
18 changes: 9 additions & 9 deletions scripts/ClockwiseSweepPolygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ PATCHES.BASIC = {};

/**
* Modify edge types to include cached edges for the light source.
* @param {Edge} edge The Edge being considered
* @param {Record<EdgeTypes, 0|1|2>} edgeTypes Which types of edges are being used? 0=no, 1=maybe, 2=always
* @param {PIXI.Rectangle} bounds The overall bounding box
* @returns {boolean} Should the edge be included?
* @returns {Record<EdgeTypes, 0|1|2>} edgeTypes Which types of edges are being used? 0=no, 1=maybe, 2=always
*/
function _testEdgeInclusion(wrapped, edge, edgeTypes, bounds) {
const CACHED_ID = `${MODULE_ID}.cachedWall`;
function _determineEdgeTypes(wrapped) {
const edgeTypes = wrapped();
const obj = this.config.source?.object;
if ( obj ) {
log(`Sweep of ${obj.id} ${obj.isPreview ? ".preview" : ""}`);
edgeTypes[`${MODULE_ID}.cachedWall.${obj.id}${obj.isPreview ? ".preview" : ""}`] = 1;
let id = `${CACHED_ID}.${obj.id}`;
if ( obj.isPreview ) id += ".preview";
edgeTypes[id] = 1;
}
return wrapped(edge, edgeTypes, bounds);
return edgeTypes;
}

PATCHES.BASIC.WRAPS = { _testEdgeInclusion };
PATCHES.BASIC.WRAPS = { _determineEdgeTypes };
10 changes: 6 additions & 4 deletions scripts/customEdges.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function updateCachedEdges(placeable, edgesCache) {
for ( const cacheData of edgesCache ) {
const edgeConfig = foundry.utils.duplicate(cacheData);
const id = `${MODULE_ID}.${clName}.${placeable.id}${placeable.isPreview ? ".preview" : ""}.wall.${cacheData.id}`;
log(`updateCachedEdges|updating cached edge ${id}`);
// log(`updateCachedEdges|updating cached edge ${id}`);

edgeConfig.type = `${MODULE_ID}.cachedWall.${placeable.id}${placeable.isPreview ? ".preview" : ""}`;
edgeConfig.object = placeable;
Expand Down Expand Up @@ -129,8 +129,10 @@ export function getCachedWallEdgeData(idString) {
export function removeCachedEdges(placeable) {
const clName = placeable.constructor.name;
const keyString = `${MODULE_ID}.${clName}.${placeable.id}${placeable.isPreview ? ".preview" : ""}`;
log(`removeCachedEdges|removing cached edges ${keyString}`);
getCachedEdgeKeys(placeable).forEach(key => canvas.edges.delete(key));
// log(`removeCachedEdges|removing cached edges ${keyString}`);
const edges = getCachedEdgeKeys(placeable);
if ( !edges.length ) return;
edges.forEach(key => canvas.edges.delete(key));
// canvas.perception.renderFlags.set({ refreshEdges: true });
canvas.perception.update({ refreshEdges: true, initializeLighting: true });
}
Expand All @@ -153,7 +155,7 @@ export function getCachedEdgeKeys(placeable) {
* @return {Object[]} edges_cache
*/
export function shiftCustomEdgeCache(edgesCache, delta) {
log(`shiftCustomEdgeCache delta is ${delta.x}, ${delta.y}`, edgesCache);
// log(`shiftCustomEdgeCache delta is ${delta.x}, ${delta.y}`, edgesCache);
edgesCache = foundry.utils.duplicate(edgesCache);
edgesCache.forEach(e => {
const old = foundry.utils.duplicate(e.c); // Debugging.
Expand Down
6 changes: 3 additions & 3 deletions scripts/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function activateListenersV2(app, html) {
}

function shapeChanged(event) {
log("shapeChanged!", event, this);
// log("shapeChanged!", event, this);
configShapeSubmenu(event.target.value);
}

Expand Down Expand Up @@ -64,7 +64,7 @@ function configShapeSubmenu(shape) {
* @param {string} type See const.js for type.
*/
export async function injectConfiguration(app, html, data, type) {
log(`injectConfiguration for ${type}`, app, html, data);
// log(`injectConfiguration for ${type}`, app, html, data);

// If default token config, make sure the default flags are set if not already.
// Setting flags directly fails, so do manually.
Expand Down Expand Up @@ -107,7 +107,7 @@ export async function injectConfiguration(app, html, data, type) {
* @param {PointerEvent} event The originating click event
*/
function onAddWallIDs(event) {
log("lightMaskOnAddWallIDs", event, this);
// log("lightMaskOnAddWallIDs", event, this);

// Confirm the walls are valid.
let idString;
Expand Down
24 changes: 12 additions & 12 deletions scripts/updateSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function createAmbientSourceHook(document, _options, _userId) {
const edgesCache = document?.flags?.[MODULE_ID]?.[FLAGS.CUSTOM_WALLS.EDGES];
const object = document.object;
if ( !edgesCache || !object ) return;
log(`createAmbientSourceHook|Updating cached edges for source ${object.constructor.name} ${object.id}${object.isPreview ? ".preview" : ""}`);
// log(`createAmbientSourceHook|Updating cached edges for source ${object.constructor.name} ${object.id}${object.isPreview ? ".preview" : ""}`);
updateCachedEdges(object);
}

Expand Down Expand Up @@ -155,10 +155,10 @@ export function preUpdateAmbientSourceHook(doc, changes, _options, _userId) {

// Update the edge cache if the edge ids changed.
// TODO: Does the cached wall data need to be updated with changes.x, changes.y?
log(`preUpdateAmbientSourceHook|Source ${doc.object?.constructor?.name} ${doc.object?.id}${doc.object.isPreview ? ".preview" : ""}`)
// log(`preUpdateAmbientSourceHook|Source ${doc.object?.constructor?.name} ${doc.object?.id}${doc.object.isPreview ? ".preview" : ""}`)
let edgesCache = doc.flags[MODULE_ID][FLAGS.CUSTOM_WALLS.EDGES];
if ( idStringChanged ) {
log(`\tNew wall cache`);
// log(`\tNew wall cache`);
changes.flags ??= {};
changes.flags[MODULE_ID] ??= {};
edgesCache = changes.flags[MODULE_ID][FLAGS.CUSTOM_WALLS.EDGES] = getCachedWallEdgeData(idStringC);
Expand All @@ -173,14 +173,14 @@ export function preUpdateAmbientSourceHook(doc, changes, _options, _userId) {
x: newPosition.x - doc.x,
y: newPosition.y - doc.y
}
log(`\tShifting cached edge data by ${delta.x},${delta.y}`);
// log(`\tShifting cached edge data by ${delta.x},${delta.y}`);
edgesCache = shiftCustomEdgeCache(edgesCache, delta);
changes.flags ??= {};
changes.flags[MODULE_ID] ??= {};
changes.flags[MODULE_ID][FLAGS.CUSTOM_WALLS.EDGES] = edgesCache
}

log(`\tNew position ${newPosition.x},${newPosition.y}`);
// log(`\tNew position ${newPosition.x},${newPosition.y}`);
}

/**
Expand All @@ -197,12 +197,12 @@ export function updateAmbientSourceHook(doc, changed, _options, _userId) {
const edgesCache = changed?.flags?.[MODULE_ID]?.[FLAGS.CUSTOM_WALLS.EDGES];
const object = doc.object;
if ( !edgesCache || !object ) return;
log(`updateAmbientSourceHook|Source ${object.constructor.name} ${object.id}${object.isPreview ? ".preview" : ""}`);
log(`\tUpdating cached edges `);
// log(`updateAmbientSourceHook|Source ${object.constructor.name} ${object.id}${object.isPreview ? ".preview" : ""}`);
// log(`\tUpdating cached edges `);
updateCachedEdges(object);

// Refresh the source shape.
log(`\tRefreshing source`);
// log(`\tRefreshing source`);
object.initializeLightSource();
}

Expand Down Expand Up @@ -247,7 +247,7 @@ export function updateAmbientSourceHook(doc, changed, _options, _userId) {
* @param {PlaceableObject} object The object instance being refreshed
*/
export function refreshAmbientSourceHook(object, flags) {
log(`refreshAmbientSourceHook|Source ${object.constructor.name} ${object.id}${object.isPreview ? ".preview" : ""} @${object.document.x},${object.document.y}`);
// log(`refreshAmbientSourceHook|Source ${object.constructor.name} ${object.id}${object.isPreview ? ".preview" : ""} @${object.document.x},${object.document.y}`);
if ( !object.isPreview || !flags.refreshPosition ) return;
const isRelative = object.document.getFlag(MODULE_ID, FLAGS.RELATIVE);
if ( !isRelative ) return;
Expand All @@ -273,7 +273,7 @@ export function refreshAmbientSourceHook(object, flags) {
* @param {PlaceableObject} object The object instance being refreshed
*/
export function destroyAmbientSourceHook(object) {
log(`destroyAmbientSourceHook|Source ${object.constructor.name} ${object.id}${object.isPreview ? ".preview" : ""}`);
// log(`destroyAmbientSourceHook|Source ${object.constructor.name} ${object.id}${object.isPreview ? ".preview" : ""}`);
removeCachedEdges(object);
}

Expand All @@ -285,13 +285,13 @@ export function destroyAmbientSourceHook(object) {
* @param {boolean} [options.deleted=false] Indicate that this light source has been deleted
*/
export function initializeSource(wrapped, {deleted=false}={}) {
log(`initializeSource|Source ${this.constructor.name} ${this.id}${this.isPreview ? ".preview" : ""} @${this.document.x},${this.document.y}`);
// log(`initializeSource|Source ${this.constructor.name} ${this.id}${this.isPreview ? ".preview" : ""} @${this.document.x},${this.document.y}`);

// If no edges defined for this (likely preview) source, update the edges.
// Need to do that here b/c no way to hook the preview object creation before it is drawn.
let edgesCache = this.document.getFlag(MODULE_ID, FLAGS.CUSTOM_WALLS.EDGES);
if ( !deleted && edgesCache && edgesCache.length && !getCachedEdgeKeys(this).length ) {
log(`\tUpdating edges cache.`);
// log(`\tUpdating edges cache.`);
updateCachedEdges(this, edgesCache);
}
wrapped({ deleted });
Expand Down

0 comments on commit cb79b3d

Please sign in to comment.