From e2ee815b33a0e4bc30da0e1e6cda02a10a3abc35 Mon Sep 17 00:00:00 2001 From: Jeff Hitchcock Date: Fri, 2 Aug 2024 15:20:57 -0700 Subject: [PATCH] [#1964] Add arbitrary roll to `UtilityActivity` Adds a rolling formula and name that can be rolled when a `UtilityActivity` is used, similar to the "Other Formula" field on items currently. --- lang/en.json | 15 +++++++++++- module/applications/activity/_module.mjs | 1 + .../applications/activity/utility-sheet.mjs | 23 ++++++++++++++++++ module/data/activity/_module.mjs | 1 + module/data/activity/utility-data.mjs | 24 +++++++++++++++++++ module/documents/activity/utility.mjs | 8 +++---- templates/activity/utility-effect.hbs | 8 +++++++ 7 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 module/applications/activity/utility-sheet.mjs create mode 100644 module/data/activity/utility-data.mjs create mode 100644 templates/activity/utility-effect.hbs diff --git a/lang/en.json b/lang/en.json index b3f09185db..901786e3f3 100644 --- a/lang/en.json +++ b/lang/en.json @@ -2323,7 +2323,20 @@ }, "DND5E.UTILITY": { - "Title": "Utility" + "Title": "Utility", + "FIELDS": { + "roll": { + "label": "Utility Roll", + "formula": { + "label": "Roll Formula", + "hint": "Formula for an arbitrary roll." + }, + "name": { + "label": "Roll Label", + "hint": "Display name for the rolling button." + } + } + } }, "DND5E.Vehicle": "Vehicle", diff --git a/module/applications/activity/_module.mjs b/module/applications/activity/_module.mjs index 9bff596660..23a19afcf3 100644 --- a/module/applications/activity/_module.mjs +++ b/module/applications/activity/_module.mjs @@ -1,5 +1,6 @@ export {default as ActivitySheet} from "./activity-sheet.mjs"; export {default as AttackSheet} from "./attack-sheet.mjs"; export {default as SummonSheet} from "./summon-sheet.mjs"; +export {default as UtilitySheet} from "./utility-sheet.mjs"; export {default as ActivityUsageDialog} from "./activity-usage-dialog.mjs"; diff --git a/module/applications/activity/utility-sheet.mjs b/module/applications/activity/utility-sheet.mjs new file mode 100644 index 0000000000..02c9166da8 --- /dev/null +++ b/module/applications/activity/utility-sheet.mjs @@ -0,0 +1,23 @@ +import ActivitySheet from "./activity-sheet.mjs"; + +/** + * Sheet for the utility activity. + */ +export default class UtilitySheet extends ActivitySheet { + + /** @inheritDoc */ + static DEFAULT_OPTIONS = { + classes: ["utility-activity"] + }; + + /* -------------------------------------------- */ + + /** @inheritDoc */ + static PARTS = { + ...super.PARTS, + effect: { + template: "systems/dnd5e/templates/activity/utility-effect.hbs", + templates: super.PARTS.effect.templates + } + }; +} diff --git a/module/data/activity/_module.mjs b/module/data/activity/_module.mjs index 9b05e5cb5e..c5a7fac54f 100644 --- a/module/data/activity/_module.mjs +++ b/module/data/activity/_module.mjs @@ -2,3 +2,4 @@ export {default as BaseActivityData} from "./base-activity.mjs"; export {default as AttackActivityData} from "./attack-data.mjs"; export {default as SummonActivityData} from "./summon-data.mjs"; +export {default as UtilityActivityData} from "./utility-data.mjs"; diff --git a/module/data/activity/utility-data.mjs b/module/data/activity/utility-data.mjs new file mode 100644 index 0000000000..f3a0b2b771 --- /dev/null +++ b/module/data/activity/utility-data.mjs @@ -0,0 +1,24 @@ +import FormulaField from "../fields/formula-field.mjs"; +import BaseActivityData from "./base-activity.mjs"; + +const { SchemaField, StringField } = foundry.data.fields; + +/** + * Data model for an utility activity. + * + * @property {object} roll + * @property {string} roll.formula Arbitrary formula that can be rolled. + * @property {string} roll.name Label for the rolling button. + */ +export default class UtilityActivityData extends BaseActivityData { + /** @inheritDoc */ + static defineSchema() { + return { + ...super.defineSchema(), + roll: new SchemaField({ + formula: new FormulaField(), + name: new StringField() + }) + }; + } +} diff --git a/module/documents/activity/utility.mjs b/module/documents/activity/utility.mjs index e3a49ebb72..1985124154 100644 --- a/module/documents/activity/utility.mjs +++ b/module/documents/activity/utility.mjs @@ -1,11 +1,11 @@ -import ActivitySheet from "../../applications/activity/activity-sheet.mjs"; -import BaseActivityData from "../../data/activity/base-activity.mjs"; +import UtilitySheet from "../../applications/activity/utility-sheet.mjs"; +import UtilityActivityData from "../../data/activity/utility-data.mjs"; import ActivityMixin from "./mixin.mjs"; /** * Generic activity for applying effects and rolling an arbitrary die. */ -export default class UtilityActivity extends ActivityMixin(BaseActivityData) { +export default class UtilityActivity extends ActivityMixin(UtilityActivityData) { /* -------------------------------------------- */ /* Model Configuration */ /* -------------------------------------------- */ @@ -21,7 +21,7 @@ export default class UtilityActivity extends ActivityMixin(BaseActivityData) { type: "utility", img: "systems/dnd5e/icons/svg/activity/utility.svg", title: "DND5E.UTILITY.Title", - sheetClass: ActivitySheet + sheetClass: UtilitySheet }, { inplace: false }) ); } diff --git a/templates/activity/utility-effect.hbs b/templates/activity/utility-effect.hbs new file mode 100644 index 0000000000..1722b043ae --- /dev/null +++ b/templates/activity/utility-effect.hbs @@ -0,0 +1,8 @@ +
+ {{> "systems/dnd5e/templates/activity/parts/activity-effects.hbs" }} +
+ {{ localize "DND5E.UTILITY.FIELDS.roll.label" }} + {{ formField fields.roll.fields.name value=source.roll.name }} + {{ formField fields.roll.fields.formula value=source.roll.formula }} +
+