1+ import CreateDocumentDialog from "../create-document-dialog.mjs" ;
12import { ConsumptionTargetData } from "../../data/activity/fields/consumption-targets-field.mjs" ;
3+ import BaseActivityBehavior from "../../data/region-behavior/base-activity-behavior.mjs" ;
24import UsesField from "../../data/shared/uses-field.mjs" ;
35import PseudoDocumentSheet from "../api/pseudo-document-sheet.mjs" ;
46
@@ -13,10 +15,12 @@ export default class ActivitySheet extends PseudoDocumentSheet {
1315 icon : "fa-solid fa-gauge"
1416 } ,
1517 actions : {
18+ addBehavior : ActivitySheet . #addBehavior,
1619 addConsumption : ActivitySheet . #addConsumption,
1720 addDamagePart : ActivitySheet . #addDamagePart,
1821 addEffect : ActivitySheet . #addEffect,
1922 addRecovery : ActivitySheet . #addRecovery,
23+ deleteBehavior : ActivitySheet . #deleteBehavior,
2024 deleteConsumption : ActivitySheet . #deleteConsumption,
2125 deleteDamagePart : ActivitySheet . #deleteDamagePart,
2226 deleteEffect : ActivitySheet . #deleteEffect,
@@ -54,6 +58,9 @@ export default class ActivitySheet extends PseudoDocumentSheet {
5458 effect : {
5559 template : "systems/dnd5e/templates/activity/effect.hbs" ,
5660 templates : [
61+ "systems/dnd5e/templates/activity/parts/activity-behaviors.hbs" ,
62+ "systems/dnd5e/templates/activity/parts/activity-behavior-level-limit.hbs" ,
63+ "systems/dnd5e/templates/activity/parts/activity-behavior-settings.hbs" ,
5764 "systems/dnd5e/templates/activity/parts/activity-effects.hbs" ,
5865 "systems/dnd5e/templates/activity/parts/activity-effect-level-limit.hbs" ,
5966 "systems/dnd5e/templates/activity/parts/activity-effect-settings.hbs"
@@ -230,6 +237,19 @@ export default class ActivitySheet extends PseudoDocumentSheet {
230237
231238 /* -------------------------------------------- */
232239
240+ /**
241+ * Prepare a specific applied behavior if present in the activity data.
242+ * @param {ApplicationRenderContext } context Context being prepared.
243+ * @param {object } behavior Applied behavior context being prepared.
244+ * @returns {object }
245+ * @protected
246+ */
247+ _prepareAppliedBehaviorContext ( context , behavior ) {
248+ return behavior ;
249+ }
250+
251+ /* -------------------------------------------- */
252+
233253 /**
234254 * Prepare a specific applied effect if present in the activity data.
235255 * @param {ApplicationRenderContext } context Context being prepared.
@@ -266,6 +286,26 @@ export default class ActivitySheet extends PseudoDocumentSheet {
266286 async _prepareEffectContext ( context , options ) {
267287 context . tab = context . tabs . effect ;
268288
289+ if ( context . activity . behaviors && ( context . activity . target ?. template ?. type || this . activity . isRider ) ) {
290+ context . appliedBehaviors = context . activity . behaviors . values ( )
291+ . filter ( d => d . type in CONFIG . DND5E . activityBehaviorTypes )
292+ . map ( data => {
293+ const source = context . source . behaviors [ data . _index ] ;
294+ if ( ! source ) return null ;
295+ const instance = new CONFIG . DND5E . activityBehaviorTypes [ source . type ] . model ( source . config ) ;
296+ const ctx = {
297+ data, source,
298+ additionalFields : instance . generateFields ( source . config , { prefix : `behaviors.${ data . _index } .config.` } ) ,
299+ additionalSettings : "systems/dnd5e/templates/activity/parts/activity-behavior-settings.hbs" ,
300+ collapsed : this . expandedSections . get ( `behavior.${ data . _id } ` ) ? "" : "collapsed" ,
301+ config : CONFIG . DND5E . activityBehaviorTypes [ data . type ] ,
302+ fields : this . activity . schema . fields . behaviors . element . fields ,
303+ prefix : `behaviors.${ data . _index } .`
304+ } ;
305+ return this . _prepareAppliedBehaviorContext ( context , ctx ) ;
306+ } ) ;
307+ }
308+
269309 if ( context . activity . effects ) {
270310 const appliedEffects = new Set ( context . activity . effects ?. map ( e => e . _id ) ?? [ ] ) ;
271311 context . allEffects = this . item . effects
@@ -462,6 +502,21 @@ export default class ActivitySheet extends PseudoDocumentSheet {
462502
463503 /* -------------------------------------------- */
464504
505+ /**
506+ * Handle adding a new entry to the behaviors list.
507+ * @this {ActivitySheet}
508+ * @param {Event } event Triggering click event.
509+ * @param {HTMLElement } target Button that was clicked.
510+ */
511+ static async #addBehavior( event , target ) {
512+ if ( ! this . activity . behaviors ) return ;
513+ const createData = await CreateDocumentDialog . prompt ( BaseActivityBehavior , { } , { parent : this . activity } ) ;
514+ if ( ! createData ?. type ) return ;
515+ this . activity . update ( { behaviors : [ ...this . activity . toObject ( ) . behaviors , createData ] } ) ;
516+ }
517+
518+ /* -------------------------------------------- */
519+
465520 /**
466521 * Handle adding a new entry to the consumption list.
467522 * @this {ActivitySheet}
@@ -551,6 +606,20 @@ export default class ActivitySheet extends PseudoDocumentSheet {
551606
552607 /* -------------------------------------------- */
553608
609+ /**
610+ * Handle removing an entry from the behaviors list.
611+ * @this {ActivitySheet}
612+ * @param {Event } event Triggering click event.
613+ * @param {HTMLElement } target Button that was clicked.
614+ */
615+ static #deleteBehavior( event , target ) {
616+ if ( ! this . activity . behaviors ) return ;
617+ const behaviors = this . activity . toObject ( ) . behaviors ;
618+ this . activity . update ( { behaviors : behaviors . toSpliced ( target . closest ( "[data-index]" ) . dataset . index , 1 ) } ) ;
619+ }
620+
621+ /* -------------------------------------------- */
622+
554623 /**
555624 * Handle removing an entry from the consumption targets list.
556625 * @this {ActivitySheet}
0 commit comments