Skip to content

Commit

Permalink
Merge branch 'release/0.7.4' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed May 23, 2024
2 parents 57e3680 + 38f60dc commit 52daac9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.7.4
Fix for incompatibiity with Sound of Token and Token Attacher. Issues #16 and #17.

## 0.7.3
Force source update so that changes reflect in the placeable without moving the mouse. Force radius update when creating the preview. Closes issue #15.
Refactor to use Patcher class.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[![Version (latest)](https://img.shields.io/github/v/release/caewok/fvtt-light-mask)](https://github.com/caewok/fvtt-light-mask/releases/latest)
[![Foundry Version](https://img.shields.io/badge/dynamic/json.svg?url=https://github.com/caewok/fvtt-light-mask/releases/latest/download/module.json&label=Foundry%20Version&query=$.minimumCoreVersion&colorB=blueviolet)](https://github.com/caewok/fvtt-light-mask/releases/latest)
[![Foundry Version](https://img.shields.io/badge/dynamic/json.svg?url=https://github.com/caewok/fvtt-light-mask/releases/latest/download/module.json&label=Foundry%20Version&query=$.compatibility.verified&colorB=blueviolet)](https://github.com/caewok/fvtt-light-mask/releases/latest)
[![License](https://img.shields.io/github/license/caewok/fvtt-light-mask)](LICENSE)

![Forge Installs](https://img.shields.io/badge/dynamic/json?label=Forge%20Installs&query=package.installs&suffix=%25&url=https://forge-vtt.com/api/bazaar/package/lightmask&colorB=4aa94a)
![Latest Release Download Count](https://img.shields.io/github/downloads/caewok/fvtt-light-mask/latest/module.zip)
![All Downloads](https://img.shields.io/github/downloads/caewok/fvtt-light-mask/total)

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/H2H3Y7IJW)

# Light/Sound Mask

This module adds a toggle to Foundry VTT light and sound configuration to "mask" lights and sounds with a selected shape. Options:
Expand Down
5 changes: 4 additions & 1 deletion scripts/AmbientSoundConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ PATCHES.BASIC.STATIC_WRAPS = { defaultOptions };
*/
async function _render(wrapper, force, options) {
// Allow sound to be previewed.
if ( !this.rendered && !this.closing ) {
if ( !this.rendered && !this.closing && this.document.object ) {
if ( !this.preview ) {
const clone = this.document.object.clone();
clone.document.updateSource({ radius: this.document.radius })
Expand Down Expand Up @@ -89,6 +89,7 @@ async function _onChangeInput(wrapper, event) {
*/
function getData(wrapper, options = {}) {
const context = wrapper(options);
if ( !this.preview ) return context;
delete context.document; // Replaced below
return foundry.utils.mergeObject(context, {
data: this.preview.toObject(false),
Expand Down Expand Up @@ -123,6 +124,7 @@ PATCHES.BASIC.WRAPS = {
* @param {object} change Data which simulates a document update
*/
function _previewChanges(change) {
if ( !this.preview ) return;
if ( change ) this.preview.updateSource(change);
this.preview.object.renderFlags.set({refresh: true});
this.preview.object.updateSource();
Expand All @@ -135,6 +137,7 @@ function _previewChanges(change) {
* the light method.
*/
function _resetPreview() {
if ( !this.preview ) return;
this.preview.object.destroy({children: true});
this.preview = null;
this.document.object.visible = true;
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

0 comments on commit 52daac9

Please sign in to comment.