This commit is contained in:
Dapoolp 2025-06-27 18:00:17 +02:00
parent 8423ab6776
commit ddbb6c4fd8
34 changed files with 609 additions and 378 deletions

View file

@ -1,18 +1,13 @@
import { DualityRollColor } from '../data/settings/Appearance.mjs';
import DHDualityRoll from '../data/chat-message/dualityRoll.mjs';
export default class DhpChatMessage extends foundry.documents.ChatMessage {
async renderHTML() {
if (this.type === 'dualityRoll' || this.type === 'adversaryRoll') {
this.content = await foundry.applications.handlebars.renderTemplate(this.content, this.system);
}
if(this.system.messageTemplate) this.content = await foundry.applications.handlebars.renderTemplate(this.system.messageTemplate, this.system);
/* We can change to fully implementing the renderHTML function if needed, instead of augmenting it. */
const html = await super.renderHTML();
this.applyPermission(html);
if (this.type === 'dualityRoll') {
html.classList.add('duality');
/* const dualityResult = this.system.dualityResult; */
switch (this.system.roll.result.duality) {
case 1:
html.classList.add('hope');
@ -24,11 +19,18 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
html.classList.add('critical');
break;
}
/* if (dualityResult === DHDualityRoll.dualityResult.hope) html.classList.add('hope');
else if (dualityResult === DHDualityRoll.dualityResult.fear) html.classList.add('fear');
else html.classList.add('critical'); */
}
return html;
}
applyPermission(html) {
const elements = html.querySelectorAll('[data-perm-id]');
elements.forEach(e => {
const uuid = e.dataset.permId,
document = fromUuidSync(uuid);
e.setAttribute('data-view-perm', document.testUserPermission(game.user, 'OBSERVER'));
e.setAttribute('data-use-perm', document.testUserPermission(game.user, 'OWNER'));
});
}
}

View file

@ -65,9 +65,10 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
if (this.action.damage?.hasOwnProperty('includeBase') && this.action.type === 'attack')
context.hasBaseDamage = !!this.action.parent.damage;
context.getRealIndex = this.getRealIndex.bind(this);
context.getEffectDetails = this.getEffectDetails.bind(this);
context.disableOption = this.disableOption.bind(this);
context.isNPC = this.action.actor && this.action.actor.type !== 'character';
context.hasRoll = this.action.hasRoll();
context.hasRoll = this.action.hasRoll;
console.log(context)
return context;
}
@ -90,24 +91,16 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
return data.damage.parts.find(d => d.base) ? index - 1 : index;
}
getEffectDetails(id) {
return this.action.item.effects.get(id);
}
_prepareSubmitData(event, formData) {
const submitData = foundry.utils.expandObject(formData.object);
for ( const keyPath of this.constructor.CLEAN_ARRAYS ) {
const data = foundry.utils.getProperty(submitData, keyPath);
if ( data ) foundry.utils.setProperty(submitData, keyPath, Object.values(data));
/* const data = foundry.utils.getProperty(submitData, keyPath),
originalData = foundry.utils.getProperty(this.action.toObject(), keyPath);
if ( data ) {
const aData = Object.values(data);
originalData.forEach((v,i) => {
aData[i] = {...originalData[i], ...aData[i]};
})
foundry.utils.setProperty(submitData, keyPath, aData);
} */
}
// this.element.querySelectorAll("fieldset[disabled] :is(input, select)").forEach(input => {
// foundry.utils.setProperty(submitData, input.name, input.value);
// });
return submitData;
}
@ -138,6 +131,7 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
}
static removeElement(event) {
event.stopPropagation();
const data = this.action.toObject(),
key = event.target.closest('.action-category-data').dataset.key,
index = event.target.dataset.index;
@ -192,5 +186,8 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
this.action.item.deleteEmbeddedDocuments('ActiveEffect', [effectId]);
}
static editEffect(event) {}
static editEffect(event) {
const id = event.target.closest('[data-effect-id]')?.dataset?.effectId;
this.action.item.effects.get(id).sheet.render(true);
}
}

View file

@ -16,7 +16,7 @@ export class DHRoll extends Roll {
if (!roll) return;
await this.buildEvaluate(roll, config, (message = {}));
await this.buildPost(roll, config, (message = {}));
return roll;
return config;
}
static async buildConfigure(config = {}, message = {}) {
@ -58,7 +58,7 @@ export class DHRoll extends Roll {
if (message.data) {
} else {
const messageData = {};
await this.toMessage(roll, config);
config.message = await this.toMessage(roll, config);
}
}
@ -71,10 +71,9 @@ export class DHRoll extends Roll {
user: game.user.id,
sound: config.mute ? null : CONFIG.sounds.dice,
system: config,
content: await this.messageTemplate(config),
rolls: [roll]
};
await cls.create(msg);
return await cls.create(msg);
}
static applyKeybindings(config) {
@ -110,12 +109,6 @@ export class D20Roll extends DHRoll {
static messageType = 'adversaryRoll';
// static messageTemplate = 'systems/daggerheart/templates/chat/adversary-roll.hbs';
static messageTemplate = async config => {
return 'systems/daggerheart/templates/chat/adversary-roll.hbs';
};
static CRITICAL_TRESHOLD = 20;
static DefaultDialog = D20RollDialog;
@ -214,9 +207,9 @@ export class D20Roll extends DHRoll {
if (config.targets?.length) {
config.targets.forEach(target => {
const difficulty = config.roll.difficulty ?? target.difficulty ?? target.evasion;
target.hit = roll.total >= difficulty;
target.hit = this.isCritical || roll.total >= difficulty;
});
} else if (config.roll.difficulty) roll.success = roll.total >= config.roll.difficulty;
} else if (config.roll.difficulty) config.roll.success = roll.isCritical || roll.total >= config.roll.difficulty;
config.roll.total = roll.total;
config.roll.formula = roll.formula;
config.roll.advantage = {
@ -260,12 +253,6 @@ export class DualityRoll extends D20Roll {
static messageType = 'dualityRoll';
// static messageTemplate = 'systems/daggerheart/templates/chat/duality-roll.hbs';
static messageTemplate = async config => {
return 'systems/daggerheart/templates/chat/duality-roll.hbs';
};
static DefaultDialog = D20RollDialog;
get dHope() {
@ -395,21 +382,22 @@ export class DamageRoll extends DHRoll {
static messageType = 'damageRoll';
// static messageTemplate = 'systems/daggerheart/templates/chat/damage-roll.hbs';
static messageTemplate = async config => {
return await foundry.applications.handlebars.renderTemplate(
config.messageTemplate ?? 'systems/daggerheart/templates/chat/damage-roll.hbs',
config
);
};
static DefaultDialog = DamageDialog;
static async postEvaluate(roll, config = {}) {
config.roll = {
result: roll.total,
dice: roll.dice,
total: roll.total,
formula: roll.formula,
type: config.type
};
config.roll.dice = [];
roll.dice.forEach(d => {
config.roll.dice.push({
dice: d.denomination,
total: d.total,
formula: d.formula,
results: d.results
});
});
}
}

View file

@ -54,7 +54,9 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
context.document = this.document;
context.tabs = super._getTabs(this.constructor.TABS);
context.systemFields.attack.fields = this.document.system.attack.schema.fields;
context.getEffectDetails = this.getEffectDetails.bind(this);
context.isNPC = true;
console.log(context)
return context;
}
@ -80,6 +82,10 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
this.actor.diceRoll(config);
}
getEffectDetails(id) {
return {};
}
static async attackRoll(event) {
this.actor.system.attack.use(event);
}

View file

@ -5,7 +5,6 @@ import AncestrySelectionDialog from '../ancestrySelectionDialog.mjs';
import DaggerheartSheet from './daggerheart-sheet.mjs';
import { abilities } from '../../config/actorConfig.mjs';
import DhlevelUp from '../levelup.mjs';
import DHDualityRoll from '../../data/chat-message/dualityRoll.mjs';
const { ActorSheetV2 } = foundry.applications.sheets;
const { TextEditor } = foundry.applications.ux;
@ -370,47 +369,9 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
title: game.i18n.format('DAGGERHEART.Chat.DualityRoll.AbilityCheckTitle', { ability: abilityLabel }),
roll: {
trait: button.dataset.attribute
/* label: abilityLabel,
modifier: button.dataset.value */
}
/* chatMessage: {
template: 'systems/daggerheart/templates/chat/duality-roll.hbs'
} */
};
this.document.diceRoll(config);
// Delete when new roll logic test done
/* const { roll, hope, fear, advantage, disadvantage, modifiers } = await this.document.dualityRoll(
{ title: game.i18n.localize(abilities[button.dataset.attribute].label), value: button.dataset.value },
event.shiftKey
);
const cls = getDocumentClass('ChatMessage');
const systemContent = new DHDualityRoll({
title: game.i18n.format('DAGGERHEART.Chat.DualityRoll.AbilityCheckTitle', {
ability: game.i18n.localize(abilities[button.dataset.attribute].label)
}),
origin: this.document.id,
roll: roll._formula,
modifiers: modifiers,
hope: hope,
fear: fear,
advantage: advantage,
disadvantage: disadvantage
});
await cls.create({
type: 'dualityRoll',
sound: CONFIG.sounds.dice,
system: systemContent,
user: game.user.id,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/duality-roll.hbs',
systemContent
),
rolls: [roll]
}); */
}
static async toggleMarks(_, button) {

View file

@ -53,6 +53,7 @@ export default class DhpEnvironment extends DaggerheartSheet(ActorSheetV2) {
const context = await super._prepareContext(_options);
context.document = this.document;
context.tabs = super._getTabs(this.constructor.TABS);
context.getEffectDetails = this.getEffectDetails.bind(this);
return context;
}
@ -62,6 +63,10 @@ export default class DhpEnvironment extends DaggerheartSheet(ActorSheetV2) {
this.render();
}
getEffectDetails(id) {
return {};
}
static async addAdversary() {
await this.document.update({
[`system.potentialAdversaries.${foundry.utils.randomID()}.label`]: game.i18n.localize(

View file

@ -111,16 +111,18 @@ export default function DHItemMixin(Base) {
}
}
static async editAction(_, button) {
const action = this.document.system.actions[button.dataset.index];
static async editAction(event, button) {
const index = event.target.closest('[data-index]').dataset.index,
action = this.document.system.actions[index];
await new DHActionConfig(action).render(true);
}
static async removeAction(event, button) {
event.stopPropagation();
const action = event.target.closest('[data-index]').dataset.index;
await this.document.update({
'system.actions': this.document.system.actions.filter(
(_, index) => index !== Number.parseInt(button.dataset.index)
(_, index) => index !== Number.parseInt(action)
)
});
}