Skip to content

Commit

Permalink
[foundryvtt#1964] Add arbitrary roll to UtilityActivity
Browse files Browse the repository at this point in the history
Adds a rolling formula and name that can be rolled when a
`UtilityActivity` is used, similar to the "Other Formula" field
on items currently.
  • Loading branch information
arbron committed Aug 2, 2024
1 parent 65b1d55 commit e2ee815
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 5 deletions.
15 changes: 14 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions module/applications/activity/_module.mjs
Original file line number Diff line number Diff line change
@@ -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";
23 changes: 23 additions & 0 deletions module/applications/activity/utility-sheet.mjs
Original file line number Diff line number Diff line change
@@ -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
}
};
}
1 change: 1 addition & 0 deletions module/data/activity/_module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
24 changes: 24 additions & 0 deletions module/data/activity/utility-data.mjs
Original file line number Diff line number Diff line change
@@ -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()
})
};
}
}
8 changes: 4 additions & 4 deletions module/documents/activity/utility.mjs
Original file line number Diff line number Diff line change
@@ -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 */
/* -------------------------------------------- */
Expand All @@ -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 })
);
}
8 changes: 8 additions & 0 deletions templates/activity/utility-effect.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<section class="tab activity-{{ tab.id }} {{ tab.cssClass }}" data-tab="{{ tab.id }}" data-group="{{ tab.group }}">
{{> "systems/dnd5e/templates/activity/parts/activity-effects.hbs" }}
<fieldset>
<legend>{{ localize "DND5E.UTILITY.FIELDS.roll.label" }}</legend>
{{ formField fields.roll.fields.name value=source.roll.name }}
{{ formField fields.roll.fields.formula value=source.roll.formula }}
</fieldset>
</section>

0 comments on commit e2ee815

Please sign in to comment.