diff --git a/module/module.json b/module/module.json index 0dbcc1e..edd1f4b 100644 --- a/module/module.json +++ b/module/module.json @@ -5,8 +5,8 @@ "author": "troygoode, Argonius-Angelus, mattd", "url": "https://github.com/mattd/foundryvtt-progress-clocks", "manifest": "https://raw.githubusercontent.com/mattd/foundryvtt-progress-clocks/main/module/module.json", - "download": "https://github.com/mattd/foundryvtt-progress-clocks/releases/download/v1.5.3/build.zip", - "version": "1.5.3", + "download": "https://github.com/mattd/foundryvtt-progress-clocks/releases/download/v1.5.4/build.zip", + "version": "1.5.4", "minimumCoreVersion": "0.7.0", "compatibleCoreVersion": "10", "compatibility": { diff --git a/module/scripts/clock.mjs b/module/scripts/clock.mjs index dccca5c..6b0a802 100644 --- a/module/scripts/clock.mjs +++ b/module/scripts/clock.mjs @@ -33,16 +33,6 @@ export class Clock { this.theme = theme || 'wallflower_green'; } - get flags () { - return { - clocks: { - size: this.size, - progress: this.progress, - theme: this.theme - } - }; - } - increment () { const old = this; return new Clock({ diff --git a/module/scripts/sheet.mjs b/module/scripts/sheet.mjs index 55d198d..490b325 100644 --- a/module/scripts/sheet.mjs +++ b/module/scripts/sheet.mjs @@ -140,24 +140,18 @@ export class ClockSheet extends ActorSheet { // Update the tokens for (const token of tokens) { + const tokenData = { + name: actor.name, + img: ( + `/${Clock.themes[clock.theme]}` + + `/${clock.size}clock_${clock.progress}.png` + ), + actorLink: true + }; if (foundryVersion.major >= 8) { - await token.document.update({ - name: actor.name, - img: ( - `/${Clock.themes[clock.theme]}` + - `/${clock.size}clock_${clock.progress}.png` - ), - actorLink: true - }); + await token.document.update(tokenData); } else { - await token.update({ - name: actor.name, - img: ( - `/${Clock.themes[clock.theme]}` + - `/${clock.size}clock_${clock.progress}.png` - ), - actorLink: true - }); + await token.update(tokenData); }; } diff --git a/module/scripts/systems/dnd5e.mjs b/module/scripts/systems/dnd5e.mjs index 5e7e819..2053eb9 100644 --- a/module/scripts/systems/dnd5e.mjs +++ b/module/scripts/systems/dnd5e.mjs @@ -1,14 +1,6 @@ export default { registerSheetOptions: { types: ["npc"] }, - loadClockFromActor: ({ actor }) => { - return { - progress: actor.getFlag("clocks", "progress"), - size: actor.getFlag("clocks", "size"), - theme: actor.getFlag("clocks", "theme") - }; - }, - persistClockToActor: ({ clock }) => { return { data: { @@ -20,7 +12,7 @@ export default { } }, flags: { - clocks: { + "progress-clocks": { progress: clock.progress, size: clock.size, theme: clock.theme, diff --git a/package-lock.json b/package-lock.json index a7cd8b0..e5fa8d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "foundryvtt-progress-clocks", - "version": "1.5.3", + "version": "1.5.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "foundryvtt-progress-clocks", - "version": "1.5.3", + "version": "1.5.4", "license": "MIT", "devDependencies": { "ava": "^4.3.1" diff --git a/package.json b/package.json index a34b60a..a9956c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "foundryvtt-progress-clocks", - "version": "1.5.3", + "version": "1.5.4", "description": "Brings Forged in the Dark style progress clocks to your FoundryVTT games.", "main": "module/scripts/init.mjs", "scripts": { diff --git a/test/clock/constructor.mjs b/test/clock/constructor.mjs index c54691f..6821763 100644 --- a/test/clock/constructor.mjs +++ b/test/clock/constructor.mjs @@ -13,3 +13,44 @@ test("sets a default theme when none is provided", t => { const clock = new Clock(); t.assert(clock.theme); }); + +test("sets size to a supported size if supplied an unsupported size", t => { + const size = 1; + const clock = new Clock({ + size: size + }); + t.assert(Clock.sizes.indexOf(parseInt(size)) == -1); + t.assert(Clock.sizes.indexOf(parseInt(clock.size)) >= 0); +}); + +test("sets a default size when none is provided", t=> { + const clock = new Clock(); + t.assert(clock.size); +}); + +test("sets the correct progress when provided", t => { + const clock = new Clock({ + progress: 2 + }); + t.is(clock.progress, 2); +}); + +test("sets progress equal to size if progress is larger than size", t=> { + const clock = new Clock({ + size: 8, + progress: 9 + }); + t.is(clock.progress, 8); +}) + +test("sets progress to zero if no progress is provided", t => { + const clock = new Clock(); + t.is(clock.progress, 0); +}) + +test("sets progress to zero if provided progress is less than zero", t => { + const clock = new Clock({ + progress: -1 + }); + t.is(clock.progress, 0); +}); diff --git a/test/clock/decrement.mjs b/test/clock/decrement.mjs new file mode 100644 index 0000000..c237908 --- /dev/null +++ b/test/clock/decrement.mjs @@ -0,0 +1,38 @@ +import test from 'ava'; + +import { Clock } from "../../module/scripts/clock.mjs"; + +test("returns a new Clock object", t => { + const oldClock = new Clock({ + progress: 1 + }); + const newClock = oldClock.decrement(); + t.assert(newClock instanceof Clock); + t.not(newClock, oldClock); +}); + +test("decrements the previous progress by 1", t => { + const oldClock = new Clock({ + progress: 1 + }); + const newClock = oldClock.decrement(); + t.is(newClock.progress, 0); +}); + +test("does not alter the previous size", t => { + const oldClock = new Clock({ + size: 4, + progress: 1 + }); + const newClock = oldClock.decrement(); + t.is(newClock.size, 4); +}); + +test("does not alter the previous theme", t => { + const oldClock = new Clock({ + theme: 'gms_red', + progress: 1 + }); + const newClock = oldClock.decrement(); + t.is(newClock.theme, 'gms_red'); +}); diff --git a/test/clock/increment.mjs b/test/clock/increment.mjs new file mode 100644 index 0000000..cf2c121 --- /dev/null +++ b/test/clock/increment.mjs @@ -0,0 +1,38 @@ +import test from 'ava'; + +import { Clock } from "../../module/scripts/clock.mjs"; + +test("returns a new Clock object", t => { + const oldClock = new Clock({ + progress: 1 + }); + const newClock = oldClock.increment(); + t.assert(newClock instanceof Clock); + t.not(newClock, oldClock); +}); + +test("increments the previous progress by 1", t => { + const oldClock = new Clock({ + progress: 1 + }); + const newClock = oldClock.increment(); + t.is(newClock.progress, 2); +}); + +test("does not alter the previous size", t => { + const oldClock = new Clock({ + size: 4, + progress: 1 + }); + const newClock = oldClock.increment(); + t.is(newClock.size, 4); +}); + +test("does not alter the previous theme", t => { + const oldClock = new Clock({ + theme: 'gms_red', + progress: 1 + }); + const newClock = oldClock.increment(); + t.is(newClock.theme, 'gms_red'); +});