Improve the chat message handling to make it so that the flavour can be properly updated if you include @active roll data
This commit is contained in:
parent
0fb10b7ae2
commit
c090daa2aa
2 changed files with 41 additions and 7 deletions
|
|
@ -136,12 +136,29 @@ export class AttributeItemData extends foundry.abstract.TypeDataModel {
|
||||||
|
|
||||||
// Provide the chat-specific context when required
|
// Provide the chat-specific context when required
|
||||||
if (macro.type === `chat`) {
|
if (macro.type === `chat`) {
|
||||||
Hooks.once(`taf.getRollData`, (data) => {
|
const extraContext = {
|
||||||
data.active = {
|
name: this.parent.name,
|
||||||
min: this.min,
|
min: this.min,
|
||||||
value: this.value,
|
value: this.value,
|
||||||
max: this.max,
|
max: this.max,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Hooks.once(`taf.getRollData`, (data) => {
|
||||||
|
data.active = extraContext;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Apply any roll data additions to the message flavour as well
|
||||||
|
// since that doesn't get formatted by the ChatLog
|
||||||
|
Hooks.once(`preCreateChatMessage`, (message) => {
|
||||||
|
if (message.flavor.includes(`@active`)) {
|
||||||
|
const flavor = message.flavor.replaceAll(
|
||||||
|
/@active\.(\w+)/g,
|
||||||
|
(fullMatch, key) => {
|
||||||
|
return extraContext[key] || fullMatch;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
message.updateSource({ flavor, });
|
||||||
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,11 +59,28 @@ export class GenericItemData extends foundry.abstract.TypeDataModel {
|
||||||
|
|
||||||
// Provide the chat-specific context when required
|
// Provide the chat-specific context when required
|
||||||
if (macro.type === `chat`) {
|
if (macro.type === `chat`) {
|
||||||
Hooks.once(`taf.getRollData`, (data) => {
|
const extraContext = {
|
||||||
data.active = {
|
name: this.parent.name,
|
||||||
quantity: this.quantity,
|
quantity: this.quantity,
|
||||||
equipped: this.equipped ? 1 : 0,
|
equipped: this.equipped ? 1 : 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Hooks.once(`taf.getRollData`, (data) => {
|
||||||
|
data.active = extraContext;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Apply any roll data additions to the message flavour as well
|
||||||
|
// since that doesn't get formatted by the ChatLog
|
||||||
|
Hooks.once(`preCreateChatMessage`, (message) => {
|
||||||
|
if (message.flavor.includes(`@active`)) {
|
||||||
|
const flavor = message.flavor.replaceAll(
|
||||||
|
/@active\.(\w+)/g,
|
||||||
|
(fullMatch, key) => {
|
||||||
|
return extraContext[key] || fullMatch;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
message.updateSource({ flavor, });
|
||||||
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue