Skip to content

Commit

Permalink
Reduce scope.
Browse files Browse the repository at this point in the history
  • Loading branch information
krbz999 committed Dec 28, 2024
1 parent 3512ec8 commit 0d51509
Showing 1 changed file with 5 additions and 47 deletions.
52 changes: 5 additions & 47 deletions module/data/fields/advantage-mode-field.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,52 +37,13 @@ export default class AdvantageModeField extends foundry.data.fields.NumberField

/* -------------------------------------------- */

/**
* Have sources of advantage been nullified?
* @type {boolean}
*/
#nullAdvantage;

/* -------------------------------------------- */

/**
* Have sources of disadvantage been nullified?
* @type {boolean}
*/
#nullDisadvantage;

/* -------------------------------------------- */

/**
* A forced value due to an override.
* @type {-1|0|1|void}
*/
#override;

/* -------------------------------------------- */

/** @inheritDoc */
initialize(value, model, options={}) {
this.#advantage = Number(value === 1);
this.#disadvantage = Number(value === -1);
this.#nullAdvantage = this.#nullDisadvantage = false;
this.#override = null;
return value;
}

/* -------------------------------------------- */

/**
* Calculate the current advantage mode.
* @returns {-1|0|1}
*/
#calculateAdvantageMode() {
if ( AdvantageModeField.#values.includes(this.#override) ) return this.#override;
const advantage = this.#nullAdvantage ? 0 : Math.sign(this.#advantage);
const disadvantage = this.#nullDisadvantage ? 0 : Math.sign(this.#disadvantage);
return advantage - disadvantage;
}

/* -------------------------------------------- */
/* Active Effect Integration */
/* -------------------------------------------- */
Expand All @@ -97,37 +58,34 @@ export default class AdvantageModeField extends foundry.data.fields.NumberField
this.#disadvantage++;
break;
}
return this.#calculateAdvantageMode();
return Math.sign(this.#advantage) - Math.sign(this.#disadvantage);
}

/* -------------------------------------------- */

/** @override */
_applyChangeDowngrade(value, delta, model, change) {
if ( [-1, 0].includes(delta) ) this.#nullAdvantage = true;
return this.#calculateAdvantageMode();
return value;
}

/* -------------------------------------------- */

/** @override */
_applyChangeMultiply(value, delta, model, change) {
return this.#calculateAdvantageMode();
return value;
}

/* -------------------------------------------- */

/** @override */
_applyChangeOverride(value, delta, model, change) {
if ( AdvantageModeField.#values.includes(delta) ) this.#override = delta;
return this.#calculateAdvantageMode();
return value;
}

/* -------------------------------------------- */

/** @override */
_applyChangeUpgrade(value, delta, model, change) {
if ( [0, 1].includes(delta) ) this.#nullDisadvantage = true;
return this.#calculateAdvantageMode();
return value;
}
}

0 comments on commit 0d51509

Please sign in to comment.