|
| 1 | +import { defaultUnits, prepareFormulaValue } from "../../utils.mjs"; |
| 2 | +import FormulaField from "../fields/formula-field.mjs"; |
| 3 | +import BaseActivityData from "./base-activity.mjs"; |
| 4 | + |
| 5 | +const { BooleanField, SchemaField, StringField } = foundry.data.fields; |
| 6 | + |
| 7 | +/** |
| 8 | + * @import { TeleportActivityData } from "./_types.mjs"; |
| 9 | + */ |
| 10 | + |
| 11 | +/** |
| 12 | + * Data model for a teleport activity. |
| 13 | + * @extends {BaseActivityData<TeleportActivityData>} |
| 14 | + * @mixes TeleportActivityData |
| 15 | + */ |
| 16 | +export default class BaseTeleportActivityData extends BaseActivityData { |
| 17 | + /** @inheritDoc */ |
| 18 | + static defineSchema() { |
| 19 | + return { |
| 20 | + ...super.defineSchema(), |
| 21 | + teleport: new SchemaField({ |
| 22 | + useRange: new BooleanField({ initial: true }), |
| 23 | + units: new StringField({ required: true, blank: false, initial: () => defaultUnits("length") }), |
| 24 | + unlimited: new BooleanField(), |
| 25 | + value: new FormulaField({ deterministic: true }) |
| 26 | + }) |
| 27 | + }; |
| 28 | + } |
| 29 | + |
| 30 | + /* -------------------------------------------- */ |
| 31 | + /* Data Preparation */ |
| 32 | + /* -------------------------------------------- */ |
| 33 | + |
| 34 | + /** @inheritDoc */ |
| 35 | + prepareFinalData(rollData) { |
| 36 | + rollData ??= this.getRollData({ deterministic: true }); |
| 37 | + super.prepareFinalData(rollData); |
| 38 | + |
| 39 | + if ( this.teleport.useRange ) { |
| 40 | + this.teleport.unlimited = this.range.units === "any"; |
| 41 | + if ( this.range.scalar ) { |
| 42 | + this.teleport.units = this.range.units; |
| 43 | + this.teleport.value = this.range.value; |
| 44 | + } |
| 45 | + } else if ( !this.teleport.unlimited ) { |
| 46 | + prepareFormulaValue(this, "teleport.value", "DND5E.TELEPORT.FIELDS.teleport.value.label", rollData); |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments