Skip to content

Commit

Permalink
Merge fix
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Feb 16, 2024
2 parents 95c0118 + f2ca2ab commit cf2a1f7
Show file tree
Hide file tree
Showing 15 changed files with 290 additions and 3,531 deletions.
7 changes: 7 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.1.3
Bug fixes related to calculating movement penalty; added ability to calculate movement penalty for a given shape.
Fix for tile cache not updating.
Move PixelCache to lib geometry.
Fix for updating settings cache.
Update lib geometry to v0.2.17.

## 0.1.2
Improvements to calculating movement penalty across a path for compatibility with Elevation Ruler:
- Change `Terrain.percentMovementForTokenAlongPath` to return the movement penalty, not the movement percent applied to the token. So if the token is at 50% movement speed for a given terrain, this would return 1.5 for a path completely in the terrain. Necessary so the averaging across different terrains works properly.
Expand Down
14 changes: 5 additions & 9 deletions scripts/ModuleSettingsAbstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ PATCHES.BASIC = {};
/**
* Wipe the settings cache on update
*/
function updateSetting(document, change, options, userId) { // eslint-disable-line no-unused-vars
const [module, ...arr] = document.key.split(".");
const key = arr.join("."); // If the key has periods, multiple will be returned by split.
if ( module === MODULE_ID && ModuleSettingsAbstract.cache.has(key) ) ModuleSettingsAbstract.cache.delete(key);
async function set(wrapper, namespace, key, value, options) {
if ( namespace === MODULE_ID ) ModuleSettingsAbstract.cache.delete(key);
return wrapper(namespace, key, value, options);
}

PATCHES.BASIC.HOOKS = { updateSetting };
PATCHES.BASIC.WRAPS = { set };

export class ModuleSettingsAbstract {
/** @type {Map<string, *>} */
Expand Down Expand Up @@ -64,10 +63,7 @@ export class ModuleSettingsAbstract {
* @param {*} value
* @returns {Promise<boolean>}
*/
static async set(key, value) {
this.cache.delete(key);
return game.settings.set(MODULE_ID, key, value);
}
static async set(key, value) { return game.settings.set(MODULE_ID, key, value); }

static async toggle(key) {
const curr = this.get(key);
Expand Down
38 changes: 31 additions & 7 deletions scripts/Patcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export class Patcher {
isStatic: typeName.includes("STATIC") };
switch ( typeName ) {
case "HOOKS": patchCl = HookPatch; break;

case "STATIC_OVERRIDES": // eslint-disable-line no-fallthrough
case "OVERRIDES":
case "STATIC_MIXES":
Expand All @@ -142,10 +143,20 @@ export class Patcher {
? libWrapper.OVERRIDE : typeName.includes("MIXES")
? libWrapper.MIXED : libWrapper.WRAPPER;
break;
case "STATIC_GETTERS": // eslint-disable-line no-fallthrough

case "STATIC_GETTERS": // eslint-disable-line no-fallthrough
case "GETTERS":
cfg.isGetter = true;
default: // eslint-disable-line no-fallthrough
patchCl = MethodPatch;
break;

case "STATIC_SETTERS": // eslint-disable-line no-fallthrough
case "SETTERS":
cfg.isSetter = true;
patchCl = MethodPatch;
break;

default:
patchCl = MethodPatch;
}
const thePatch = patchCl.create(patchName, patch, cfg);
Expand All @@ -166,11 +177,20 @@ export class Patcher {
* @param {boolean} [opts.optional] True if the getter should not be set if it already exists.
* @returns {undefined|object<id{string}} Either undefined if the getter already exists or the cl.prototype.name.
*/
static addClassMethod(cl, name, fn, { getter = false, optional = false } = {}) {
static addClassMethod(cl, name, fn, { getter = false, setter = false, optional = false } = {}) {
if ( optional && Object.hasOwn(cl, name) ) return undefined;
const descriptor = { configurable: true };
if ( getter ) descriptor.get = fn;
else {

// For getters and setters, keep the getter when creating a setter and vice-versa
if ( getter ) {
descriptor.get = fn;
const currentSetter = Object.getOwnPropertyDescriptor(cl, name)?.set;
if ( currentSetter ) descriptor.set = currentSetter;
} else if ( setter ) {
descriptor.set = fn;
const currentGetter = Object.getOwnPropertyDescriptor(cl, name)?.get;
if ( currentGetter ) descriptor.get = currentGetter;
} else {
descriptor.writable = true;
descriptor.value = fn;
}
Expand Down Expand Up @@ -351,6 +371,9 @@ export class MethodPatch extends AbstractPatch {
}

cfg.isGetter = Boolean(config.isGetter);
cfg.isSetter = Boolean(config.isSetter);
if ( cfg.isGetter && cfg.isSetter ) console.warn("Patcher|Getter and Setter both true; you probably only want 1 at a time!");

cfg.isStatic = Boolean(config.isStatic);
this.cl = config.className;
}
Expand All @@ -374,9 +397,10 @@ export class MethodPatch extends AbstractPatch {

this.prevMethod = Object.getOwnPropertyDescriptor(this.#cl, this.target);
if ( this.config.isGetter ) this.prevMethod = this.prevMethod?.get;
else if ( this.config.isSetter ) this.prevMethod = this.prevMethod?.set;
else this.prevMethod = this.prevMethod?.value;

this.regId = Patcher.addClassMethod(this.#cl, this.target, this.patchFn, { getter: this.config.isGetter });
this.regId = Patcher.addClassMethod(this.#cl, this.target, this.patchFn, { getter: this.config.isGetter, setter: this.config.isSetter });
}

/**
Expand All @@ -388,7 +412,7 @@ export class MethodPatch extends AbstractPatch {

// Add back the original, if any.
if ( this.prevMethod ) {
Patcher.addClassMethod(this.#cl, this.target, this.prevMethod, { getter: this.config.isGetter });
Patcher.addClassMethod(this.#cl, this.target, this.prevMethod, { getter: this.config.isGetter, setter: this.config.isSetter });
this.prevMethod = undefined;
}
this.regId = undefined;
Expand Down
Loading

0 comments on commit cf2a1f7

Please sign in to comment.