diff --git a/changelog.md b/changelog.md
index 1082b46a..188e2573 100644
--- a/changelog.md
+++ b/changelog.md
@@ -6,6 +6,7 @@
- Fix: affichage des points de tâche
- Fix: affichage des ajustements cohérent
- L'ouverture depuis les caractéristiques permet plusieurs types de jets
+ - On peut créer ou modifier les tâches dans la fenêtre de jets de tâches
- attaque/défense
- les maladresses sont affichées dans le résultat du jet
- le message au défenseur s'affiche correctement
diff --git a/module/actor-sheet.js b/module/actor-sheet.js
index 27f658b8..6fdbdc07 100644
--- a/module/actor-sheet.js
+++ b/module/actor-sheet.js
@@ -342,7 +342,7 @@ export class RdDActorSheet extends RdDBaseActorSangSheet {
/* -------------------------------------------- */
async createEmptyTache() {
- await this.actor.createItem('tache', 'Nouvelle tache');
+ await this.actor.createItem(ITEM_TYPES.tache, 'Nouvelle tache')
}
_getActionCombat(event) {
diff --git a/module/roll/roll-dialog.mjs b/module/roll/roll-dialog.mjs
index a72d1b17..d2eefe70 100644
--- a/module/roll/roll-dialog.mjs
+++ b/module/roll/roll-dialog.mjs
@@ -316,6 +316,7 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2
constructor(rollData, rollOptions) {
super()
+ this.hooks = []
this.rollData = RollDialog.$prepareRollData(rollData)
this.rollOptions = {
callbacks: [
@@ -328,8 +329,23 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2
}
this.chatRollResult = new ChatRollResult()
this.selectType()
+ this.registerHooks(rollData);
}
+ registerHooks(rollData) {
+ ROLL_PARTS.filter(p => p.isValid(rollData))
+ .forEach(p => p.getHooks(this).forEach(h => {
+ const hook = h.hook;
+ const id = Hooks.on(hook, h.fn)
+ this.hooks.push({ hook, id })
+ }))
+ }
+
+ unregisterHooks() {
+ this.hooks.forEach(h => Hooks.off(h.hook, h.id))
+ }
+
+
selectType() {
const selectedType = this.getSelectedType();
this.rollData.type.label = selectedType.title(this.rollData)
@@ -445,6 +461,7 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2
if (this.rollOptions.onClose) {
this.rollOptions.onClose()
}
+ this.unregisterHooks()
return await super.close(options)
}
diff --git a/module/roll/roll-part-tache.mjs b/module/roll/roll-part-tache.mjs
index 1abb670e..3f4a81b7 100644
--- a/module/roll/roll-part-tache.mjs
+++ b/module/roll/roll-part-tache.mjs
@@ -22,6 +22,7 @@ export class RollPartTache extends RollPartSelect {
.filter(tache => !selected.forced || tache.id == selected.key)
.filter(tache => tache.system.points_de_tache_courant < tache.system.points_de_tache)
.map(tache => RollPartTache.$extractTache(tache, rollData.active.actor))
+
refs.taches = refs.all
if (refs.taches.length > 0) {
this.$selectTache(rollData)
@@ -46,13 +47,39 @@ export class RollPartTache extends RollPartSelect {
async _onRender(rollDialog, context, options) {
const selectTache = rollDialog.element.querySelector(`roll-section[name="${this.code}"] select[name="select-tache"]`)
-
+ const buttonCreate = rollDialog.element.querySelector(`roll-section[name="${this.code}"] button[name="create-tache"]`)
+ const buttonEdit = rollDialog.element.querySelector(`roll-section[name="${this.code}"] button[name="edit-tache"]`)
selectTache.addEventListener("change", e => {
const selectOptions = e.currentTarget.options
const index = selectOptions.selectedIndex
this.$selectTache(rollDialog.rollData, selectOptions[index]?.value)
rollDialog.render()
})
+ buttonCreate.addEventListener(
+ "click", async e => {
+ e.preventDefault()
+ await rollDialog.rollData.active.actor.createItem(ITEM_TYPES.tache, 'Nouvelle tache')
+ })
+ buttonEdit.addEventListener(
+ "click", e => {
+ e.preventDefault()
+ const current = this.getCurrent(rollDialog.rollData)
+ current.tache?.sheet.render(true)
+ })
+ }
+
+ getHooks(rollDialog) {
+ return [
+ { hook: "createItem", fn: (item, options, id) => this.onCreateUpdateItem(rollDialog, item, options, id) },
+ { hook: "updateItem", fn: (item, options, id) => this.onCreateUpdateItem(rollDialog, item, options, id) }
+ ]
+ }
+
+ onCreateUpdateItem(rollDialog, item, options, id) {
+ if (item.type == ITEM_TYPES.tache && item.parent?.id == rollDialog.rollData.active.actor.id) {
+ this.loadRefs(rollDialog.rollData)
+ rollDialog.render()
+ }
}
impactOtherPart(part, rollData) {
diff --git a/module/roll/roll-part.mjs b/module/roll/roll-part.mjs
index 942f51bd..386cc709 100644
--- a/module/roll/roll-part.mjs
+++ b/module/roll/roll-part.mjs
@@ -110,4 +110,5 @@ export class RollPart {
async _onRender(rollDialog, context, options) { }
+ getHooks() { return [] }
}
\ No newline at end of file
diff --git a/templates/roll/roll-part-tache.hbs b/templates/roll/roll-part-tache.hbs
index a7aac7e4..603851b5 100644
--- a/templates/roll/roll-part-tache.hbs
+++ b/templates/roll/roll-part-tache.hbs
@@ -7,6 +7,8 @@
{{selectOptions refs.taches selected=current.key valueAttr="key" labelAttr="label"}}
{{plusMoins current.value}}
+
+
Points de tâche: {{current.tache.system.points_de_tache_courant}} /