Implement the DiceField and required changes to get it working (closes #179)
This commit is contained in:
parent
0064e10635
commit
327f921b9c
5 changed files with 62 additions and 40 deletions
|
|
@ -6,7 +6,7 @@ export class DotDungeonActor extends Actor {
|
||||||
provide all that data to AE's without needing to disable any inputs.
|
provide all that data to AE's without needing to disable any inputs.
|
||||||
*/
|
*/
|
||||||
prepareEmbeddedDocuments() {
|
prepareEmbeddedDocuments() {
|
||||||
this.preAE = foundry.utils.deepClone(this.system);
|
this.preAE = foundry.utils.duplicate(this.system);
|
||||||
super.prepareEmbeddedDocuments();
|
super.prepareEmbeddedDocuments();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,12 +39,12 @@ export class PlayerData extends foundry.abstract.TypeDataModel {
|
||||||
integer: true,
|
integer: true,
|
||||||
}),
|
}),
|
||||||
stats: new fields.SchemaField({
|
stats: new fields.SchemaField({
|
||||||
build: diceChoiceField(), //new DiceField(),
|
build: new DiceField(),
|
||||||
meta: diceChoiceField(),
|
meta: new DiceField(),
|
||||||
presence: diceChoiceField(),
|
presence: new DiceField(),
|
||||||
hands: diceChoiceField(),
|
hands: new DiceField(),
|
||||||
tilt: diceChoiceField(),
|
tilt: new DiceField(),
|
||||||
rng: diceChoiceField(),
|
rng: new DiceField(),
|
||||||
}),
|
}),
|
||||||
skills: new fields.SchemaField({
|
skills: new fields.SchemaField({
|
||||||
build: new fields.SchemaField({
|
build: new fields.SchemaField({
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import { statDice } from "../../config.mjs";
|
import { statDice } from "../../config.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A subclass of StringField that allows ActiveEffects to integrate with dice
|
* A subclass of DataField that allows ActiveEffects to integrate with dice
|
||||||
* values and increase/decrease the value step-wise according to the dice ladder.
|
* values and increase/decrease the value step-wise according to the dice ladder.
|
||||||
*/
|
*/
|
||||||
export class DiceField extends foundry.data.fields.StringField {
|
export class DiceField extends foundry.data.fields.DataField {
|
||||||
static get _defaults() {
|
static get _defaults() {
|
||||||
return foundry.utils.mergeObject(super._defaults, {
|
return foundry.utils.mergeObject(super._defaults, {
|
||||||
trim: true,
|
trim: true,
|
||||||
|
|
@ -19,51 +19,70 @@ export class DiceField extends foundry.data.fields.StringField {
|
||||||
|
|
||||||
// v- because for some reason Foundry doesn't respect the _defaults getter
|
// v- because for some reason Foundry doesn't respect the _defaults getter
|
||||||
this.blank = true;
|
this.blank = true;
|
||||||
console.log(this.choices)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_castChangeDelta(delta) {
|
_cast(value) { return value };
|
||||||
console.log(`DiceField._castChangeDelta(${delta})`)
|
_castChangeDelta(delta) { return delta };
|
||||||
return parseInt(delta) ?? 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** @inheritdoc */
|
/**
|
||||||
_applyChangeAdd(value, delta, model, change) {
|
* @param {string} value The current value
|
||||||
console.warn(`Cannot apply Add ActiveEffects to DiceFields. Not changing value.`);
|
* @param {string} delta The AE value
|
||||||
|
* @param {unknown} model
|
||||||
|
* @param {unknown} changes
|
||||||
|
*/
|
||||||
|
_applyChangeAdd(value, delta, model, changes) {
|
||||||
|
if (value === "") return value;
|
||||||
|
delta = parseInt(delta);
|
||||||
|
const dieIndex = statDice.findIndex(die => die === value);
|
||||||
|
const newIndex = Math.min(Math.max(0, dieIndex + delta), statDice.length - 1);
|
||||||
|
value = statDice[newIndex];
|
||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
|
|
||||||
_applyChangeMultiply(value, delta, model, change) {
|
/**
|
||||||
console.warn(`Cannot apply Multiply ActiveEffects to DiceFields. Not changing value.`);
|
* @param {string} value The current value
|
||||||
|
* @param {string} delta The AE value
|
||||||
|
* @param {unknown} model
|
||||||
|
* @param {unknown} changes
|
||||||
|
*/
|
||||||
|
_applyChangeMultiply(value, delta, model, changes) {
|
||||||
|
console.warn(`.dungeon | Cannot apply Multiply ActiveEffects to DiceFields. Not changing value.`);
|
||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
|
|
||||||
_applyChangeOverride(value, delta, model, change) {
|
/**
|
||||||
|
* @param {string} value The current value
|
||||||
|
* @param {string} delta The AE value
|
||||||
|
* @param {unknown} model
|
||||||
|
* @param {unknown} changes
|
||||||
|
*/
|
||||||
|
_applyChangeOverride(value, delta, model, changes) {
|
||||||
return delta;
|
return delta;
|
||||||
};
|
};
|
||||||
|
|
||||||
_applyChangeUpgrade(value, delta, model, change) {
|
/**
|
||||||
console.log(`.dungeon | Pre: value=${value}; delta=${delta}`);
|
* @param {string} value The current value
|
||||||
|
* @param {string} delta The AE value
|
||||||
|
* @param {unknown} model
|
||||||
|
* @param {unknown} changes
|
||||||
|
*/
|
||||||
|
_applyChangeUpgrade(value, delta, model, changes) {
|
||||||
if (value === "") return value;
|
if (value === "") return value;
|
||||||
const dieIndex = statDice.findIndex(value);
|
const currentIndex = statDice.findIndex(die => die === value);
|
||||||
const newIndex = Math.min(Math.max(0, dieIndex - delta), statDice.length - 1);
|
const upgradedIndex = statDice.findIndex(die => die === delta);
|
||||||
value = statDice[newIndex];
|
return statDice[Math.max(currentIndex, upgradedIndex)];
|
||||||
console.log(`.dungeon | Post: value=${value}; delta=${delta}`);
|
|
||||||
return value;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_applyChangeDowngrade(value, delta, model, change) {
|
/**
|
||||||
console.log(`.dungeon | Pre: value=${value}; delta=${delta}`);
|
* @param {string} value The current value
|
||||||
|
* @param {string} delta The AE value
|
||||||
|
* @param {unknown} model
|
||||||
|
* @param {unknown} changes
|
||||||
|
*/
|
||||||
|
_applyChangeDowngrade(value, delta, model, changes) {
|
||||||
if (value === "") return value;
|
if (value === "") return value;
|
||||||
const dieIndex = statDice.findIndex(value);
|
const currentIndex = statDice.findIndex(die => die === value);
|
||||||
const newIndex = Math.min(Math.max(0, dieIndex + delta), statDice.length - 1);
|
const upgradedIndex = statDice.findIndex(die => die === delta);
|
||||||
value = statDice[newIndex];
|
return statDice[Math.min(currentIndex, upgradedIndex)];
|
||||||
console.log(`.dungeon | Post: value=${value}; delta=${delta}`);
|
|
||||||
return value
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_applyChangeCustom(...args) {
|
|
||||||
console.log(`.dungeon | Dicefield._applyChangeCustom`)
|
|
||||||
return super._applyChangeCustom(...args);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ export class PlayerSheetv2 extends GenericActorSheet {
|
||||||
|
|
||||||
get #statData() {
|
get #statData() {
|
||||||
const stats = [];
|
const stats = [];
|
||||||
const usedDice = new Set(Object.values(this.actor.system.stats));
|
const usedDice = new Set(Object.values(this.actor.preAE.stats));
|
||||||
for (const statName in this.actor.system.stats) {
|
for (const statName in this.actor.system.stats) {
|
||||||
const stat = {
|
const stat = {
|
||||||
key: statName,
|
key: statName,
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,9 @@
|
||||||
data-roll-label="Stat Roll : {{stat.name}}"
|
data-roll-label="Stat Roll : {{stat.name}}"
|
||||||
>
|
>
|
||||||
Roll
|
Roll
|
||||||
|
{{#if stat.value}}
|
||||||
|
1{{stat.value}}
|
||||||
|
{{/if}}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{{#if stat.skills}}
|
{{#if stat.skills}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue