Skip to content

Commit 5310480

Browse files
authored
More Clock Trackable Resources (#968)
* feat:Moved addClockResource to BaseCharacterDataModel * feat:Pressure clock trackable resource only added if feature is enabled; added brainwave clock to trackable PC resources * feat:Added garden clock * feat:Added (optional) zero power trackable resource * fix:Updated garden clock fuid
1 parent fcdf1d2 commit 5310480

File tree

4 files changed

+60
-43
lines changed

4 files changed

+60
-43
lines changed

module/documents/actors/character/character-data-model.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export class CharacterDataModel extends BaseCharacterDataModel {
109109
this.resources.hp.attribute = 'mig';
110110
this.resources.mp.attribute = 'wlp';
111111
this.#prepareBasicResources();
112+
this.#prepareClockResources();
112113
this.vehicle.prepareData();
113114
this.floralist.prepareData();
114115
this.derived.prepareData();
@@ -236,4 +237,10 @@ export class CharacterDataModel extends BaseCharacterDataModel {
236237
this.resources.fp.value = this.resources.fp.value || 0;
237238
this.resources.exp.value = this.resources.exp.value || 0;
238239
}
240+
241+
#prepareClockResources() {
242+
this.addClockResource('brainwave', 'brainwave-clock');
243+
this.addClockResource('garden', 'garden');
244+
this.addClockResource('zeroPower', 'zero-power');
245+
}
239246
}

module/documents/actors/common/base-character-data-model.mjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,38 @@ export class BaseCharacterDataModel extends foundry.abstract.TypeDataModel {
3434
};
3535
}
3636

37+
/**
38+
* Adds a trackable resource to the clocks property of this DataModel
39+
* @param {string} key - Key name for the clock to be added to the DataModel
40+
* @param {string} fuid - fuid of the progress clock -- will be resolved with {@link FUActor.resolveProgress}
41+
*/
42+
addClockResource(key, fuid) {
43+
this.clocks ??= {};
44+
this.clocks[key] ??= {};
45+
46+
const actor = this.parent;
47+
48+
Object.defineProperty(this.clocks[key], 'value', {
49+
configurable: true,
50+
enumerable: true,
51+
get() {
52+
const clock = actor?.resolveProgress(fuid);
53+
if (!clock) return 0;
54+
return clock.current;
55+
},
56+
});
57+
58+
Object.defineProperty(this.clocks[key], 'max', {
59+
configurable: true,
60+
enumerable: true,
61+
get() {
62+
const clock = actor?.resolveProgress(fuid);
63+
if (!clock) return 0;
64+
return clock.max;
65+
},
66+
});
67+
}
68+
3769
/**
3870
* @return FUActor
3971
*/

module/documents/actors/npc/npc-data-model.mjs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -225,38 +225,6 @@ export class NpcDataModel extends BaseCharacterDataModel {
225225
});
226226
}
227227

228-
/**
229-
* Adds a trackable resource to the clocks property of this DataModel
230-
* @param {string} key - Key name for the clock to be added to the DataModel
231-
* @param {string} fuid - fuid of the progress clock -- will be resolved with {@link FUActor.resolveProgress}
232-
*/
233-
addClockResource(key, fuid) {
234-
this.clocks ??= {};
235-
this.clocks[key] ??= {};
236-
237-
const actor = this.parent;
238-
239-
Object.defineProperty(this.clocks[key], 'value', {
240-
configurable: true,
241-
enumerable: true,
242-
get() {
243-
const clock = actor?.resolveProgress(fuid);
244-
if (!clock) return 0;
245-
return clock.current;
246-
},
247-
});
248-
249-
Object.defineProperty(this.clocks[key], 'max', {
250-
configurable: true,
251-
enumerable: true,
252-
get() {
253-
const clock = actor?.resolveProgress(fuid);
254-
if (!clock) return 0;
255-
return clock.max;
256-
},
257-
});
258-
}
259-
260228
#prepareClockResources() {
261229
this.addClockResource('pressure', 'pressure');
262230
}

module/projectfu.mjs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { FUStandardItemSheet } from './sheets/item-standard-sheet.mjs';
77
// Import helper/utility classes and constants.
88
import { preloadHandlebarsTemplates } from './helpers/templates.mjs';
99
import { FU, SYSTEM } from './helpers/config.mjs';
10-
import { registerSystemSettings } from './settings.js';
10+
import { registerSystemSettings, SETTINGS } from './settings.js';
1111
import { FUCombatTracker } from './ui/combat-tracker.mjs';
1212
import { FUCombat, FUCombatDataModel } from './ui/combat.mjs';
1313
import { FUCombatant } from './ui/combatant.mjs';
@@ -233,16 +233,7 @@ Hooks.once('init', async () => {
233233
party: PartyDataModel,
234234
stash: StashDataModel,
235235
};
236-
CONFIG.Actor.trackableAttributes = {
237-
character: {
238-
bar: ['resources.hp', 'resources.mp', 'resources.ip'],
239-
value: ['resources.fp.value', 'resources.exp.value'],
240-
},
241-
npc: {
242-
bar: ['resources.hp', 'resources.mp', 'clocks.pressure'],
243-
value: ['resources.fp.value'],
244-
},
245-
};
236+
246237
CONFIG.Item.documentClass = FUItem;
247238
CONFIG.Item.dataModels = {
248239
accessory: AccessoryDataModel,
@@ -276,6 +267,25 @@ Hooks.once('init', async () => {
276267
await registerSystemSettings();
277268
await registerKeyBindings();
278269

270+
CONFIG.Actor.trackableAttributes = {
271+
character: {
272+
bar: ['resources.hp', 'resources.mp', 'resources.ip', 'clocks.brainwave', 'clocks.garden'],
273+
value: ['resources.fp.value', 'resources.exp.value'],
274+
},
275+
npc: {
276+
bar: ['resources.hp', 'resources.mp'],
277+
value: ['resources.fp.value'],
278+
},
279+
};
280+
281+
if (game.settings.get(SYSTEM, SETTINGS.pressureSystem)) {
282+
CONFIG.Actor.trackableAttributes.npc.bar.push('clocks.pressure');
283+
}
284+
285+
if (game.settings.get(SYSTEM, SETTINGS.optionZeroPower)) {
286+
CONFIG.Actor.trackableAttributes.character.bar.push('clocks.zeroPower');
287+
}
288+
279289
// Set combat tracker
280290
console.log(`${SYSTEM} | Initializing combat tracker`);
281291
CONFIG.Combat.documentClass = FUCombat;

0 commit comments

Comments
 (0)