Roll Styling
This commit is contained in:
1 parent
a99369dd43
commit
816de0e9ce
12 files changed
+734
-292
No files matched your search
@@ -0,0 +1,5 @@
|
||||
export const loadPartials = async function () {
|
||||
await foundry.applications.handlebars.loadTemplates([
|
||||
"systems/midgard6-lvd/src/templates/chat/chat-message-header.hbs"
|
||||
]);
|
||||
};
|
||||
@@ -2,6 +2,7 @@ import { systemPath } from "../constants.mjs";
|
||||
import { prepareActiveEffectCategories } from "../helpers/utils.mjs";
|
||||
import { addSpezialisierung, editSepzialisierung } from "./components/spezialisierung-actions.mjs";
|
||||
import { prepArmor, prepWeapons, prepWeight, prepSpells } from "./components/character-prep.mjs";
|
||||
import { rollSpell, rollWeapon, rollSkill } from "./components/roll-actions.mjs";
|
||||
|
||||
const { api, sheets } = foundry.applications;
|
||||
|
||||
@@ -24,9 +25,9 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
|
||||
createDoc: this.#createDoc,
|
||||
deleteDoc: this.#deleteDoc,
|
||||
toggleEffect: this.#toggleEffect,
|
||||
rollSkill: this.#rollSkill,
|
||||
rollWeapon: this.#rollWeapon,
|
||||
rollSpell: this.#rollSpell,
|
||||
rollSkill: rollSkill,
|
||||
rollWeapon: rollWeapon,
|
||||
rollSpell: rollSpell,
|
||||
cycleEquip: this.#cycleEquip,
|
||||
cycleLock: this.#cycleLock,
|
||||
addSpezialisierung: addSpezialisierung,
|
||||
@@ -492,287 +493,6 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
|
||||
effect.update({ disabled: !effect.disabled });
|
||||
}
|
||||
|
||||
static async #rollSpell(event, target) {
|
||||
const dataset = target.dataset;
|
||||
const skill = foundry.utils.getProperty(this.actor, "system.skills.magie.zaubern");
|
||||
const item = this.actor.items.get(dataset.itemId);
|
||||
const actor = this.actor;
|
||||
const dialogResult = await this.rollDialog({
|
||||
name: dataset.name,
|
||||
skill,
|
||||
damageRoll: item.system.eigenschaften.schaden,
|
||||
preSelectedSpez: item.system.eigenschaften.ursprung,
|
||||
actor
|
||||
});
|
||||
console.log("Dialog Result", dialogResult);
|
||||
if (dialogResult === "abort") {
|
||||
return;
|
||||
}
|
||||
// Construct the Roll instance
|
||||
const skillValue = skill.value;
|
||||
let die = "";
|
||||
switch (dialogResult.vorteil) {
|
||||
case -1:
|
||||
die = "2d20kl";
|
||||
break;
|
||||
case 1:
|
||||
die = "2d20kh";
|
||||
break;
|
||||
default:
|
||||
die = "1d20";
|
||||
break;
|
||||
}
|
||||
|
||||
let rollTerm = "@die + @skill";
|
||||
let rollFlavor = dataset.name;
|
||||
let roll;
|
||||
|
||||
if (dialogResult.spezLevel) {
|
||||
rollTerm += " + @spezBonus";
|
||||
rollFlavor += ": " + dialogResult.spezName;
|
||||
}
|
||||
|
||||
if (dialogResult.customRoll) {
|
||||
roll = new Roll(dialogResult.customRoll);
|
||||
} else {
|
||||
roll = new Roll(
|
||||
rollTerm,
|
||||
{ die: die, skill: skillValue, spezBonus: dialogResult.spezLevel + 1 },
|
||||
{ flavor: rollFlavor }
|
||||
);
|
||||
}
|
||||
|
||||
// The parsed terms of the roll formula
|
||||
console.log("Roll:", roll); // [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm]
|
||||
|
||||
// Execute the roll
|
||||
await roll.evaluate();
|
||||
|
||||
roll.toMessage();
|
||||
}
|
||||
|
||||
static async #rollSkill(event, target) {
|
||||
const dataset = target.dataset;
|
||||
const skill = foundry.utils.getProperty(this.actor, target.dataset.path.replace(".value", ""));
|
||||
const actor = this.actor;
|
||||
const dialogResult = await this.rollDialog({
|
||||
name: dataset.name,
|
||||
skill,
|
||||
actor
|
||||
});
|
||||
console.log("Dialog Result", dialogResult);
|
||||
if (dialogResult === "abort") {
|
||||
return;
|
||||
}
|
||||
// Construct the Roll instance
|
||||
const skillValue = skill.value;
|
||||
let die = "";
|
||||
switch (dialogResult.vorteil) {
|
||||
case -1:
|
||||
die = "2d20kl";
|
||||
break;
|
||||
case 1:
|
||||
die = "2d20kh";
|
||||
break;
|
||||
default:
|
||||
die = "1d20";
|
||||
break;
|
||||
}
|
||||
|
||||
let rollTerm = "@die + @skill";
|
||||
let rollFlavor = dataset.name;
|
||||
let roll;
|
||||
|
||||
if (dialogResult.spezLevel) {
|
||||
rollTerm += " + @spezBonus";
|
||||
rollFlavor += ": " + dialogResult.spezName;
|
||||
}
|
||||
|
||||
if (dialogResult.customRoll) {
|
||||
roll = new Roll(dialogResult.customRoll);
|
||||
} else {
|
||||
roll = new Roll(
|
||||
rollTerm,
|
||||
{ die: die, skill: skillValue, spezBonus: dialogResult.spezLevel + 1 },
|
||||
{ flavor: rollFlavor }
|
||||
);
|
||||
}
|
||||
|
||||
// The parsed terms of the roll formula
|
||||
console.log("Roll:", roll); // [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm]
|
||||
|
||||
// Execute the roll
|
||||
await roll.evaluate();
|
||||
|
||||
roll.toMessage();
|
||||
}
|
||||
|
||||
static async #rollWeapon(event, target) {
|
||||
const dataset = target.dataset;
|
||||
const weapon = this.actor.items.get(dataset.itemId);
|
||||
const skill = foundry.utils.getProperty(this.actor, weapon.system.fertigkeit);
|
||||
const actor = this.actor;
|
||||
const dialogResult = await this.rollDialog({
|
||||
name: weapon.name,
|
||||
skill,
|
||||
damageRoll: weapon.system.schaden,
|
||||
preSelectedSpez: weapon.system.spezialisierung,
|
||||
actor
|
||||
});
|
||||
console.log("Dialog Result", dialogResult);
|
||||
if (dialogResult === "abort") {
|
||||
return;
|
||||
}
|
||||
// Construct the Roll instance
|
||||
const skillValue = skill.value;
|
||||
let die = "";
|
||||
switch (dialogResult.vorteil) {
|
||||
case -1:
|
||||
die = "2d20kl";
|
||||
break;
|
||||
case 1:
|
||||
die = "2d20kh";
|
||||
break;
|
||||
default:
|
||||
die = "1d20";
|
||||
break;
|
||||
}
|
||||
|
||||
let rollTerm = "@die + @skill";
|
||||
let rollFlavor = game.i18n.localize("Midgard6.Angriff");
|
||||
let attackRoll;
|
||||
let damageRoll;
|
||||
|
||||
if (dialogResult.spezLevel) {
|
||||
rollTerm += " + @spezBonus";
|
||||
rollFlavor += " (" + dialogResult.spezName + ")";
|
||||
}
|
||||
rollFlavor += ": " + weapon.name;
|
||||
|
||||
if (dialogResult.customRoll) {
|
||||
attackRoll = await new Roll(dialogResult.customRoll).evaluate();
|
||||
} else {
|
||||
attackRoll = await new Roll(
|
||||
rollTerm,
|
||||
{ die: die, skill: skillValue, spezBonus: dialogResult.spezLevel + 1 },
|
||||
{ flavor: rollFlavor }
|
||||
).evaluate();
|
||||
}
|
||||
|
||||
damageRoll = await new Roll(
|
||||
"@die",
|
||||
{ die: weapon.system.schaden },
|
||||
{ flavor: game.i18n.localize("Midgard6.Schaden") }
|
||||
).evaluate();
|
||||
|
||||
// The parsed terms of the roll formula
|
||||
|
||||
const chatData = {
|
||||
user: game.user.id,
|
||||
rolls: [attackRoll, damageRoll] // Übergibt beide Rolls an die Nachricht
|
||||
};
|
||||
|
||||
console.log("Roll:", chatData.rolls);
|
||||
|
||||
await ChatMessage.create(chatData);
|
||||
}
|
||||
|
||||
async rollDialog(rollDialogRequest) {
|
||||
// Assamble dialog depending on roll type
|
||||
let label = rollDialogRequest.name;
|
||||
let skillValue = rollDialogRequest.skill.value || rollDialogRequest.skill;
|
||||
let bonuses = rollDialogRequest.skill.bonuses || [];
|
||||
let damageRoll = rollDialogRequest.damageRoll || "";
|
||||
let preSelectedSpez = rollDialogRequest.preSelectedSpez || "";
|
||||
let vorteil = 0;
|
||||
let customRoll = "";
|
||||
let spezLevel;
|
||||
let spezName = "";
|
||||
// 1. Define the path to .hbs template
|
||||
const templatePath = systemPath("templates/dialog/roll-dialog.hbs");
|
||||
const templateData = {
|
||||
skillValue,
|
||||
bonuses,
|
||||
vorteil,
|
||||
damageRoll,
|
||||
preSelectedSpez,
|
||||
customRoll
|
||||
};
|
||||
// 2. Render the Handlebars template into an HTML string
|
||||
const content = await foundry.applications.handlebars.renderTemplate(
|
||||
templatePath,
|
||||
templateData
|
||||
);
|
||||
// return new Promise((resolve, reject) => {
|
||||
// const dialog = new foundry.applications.api.DialogV2({
|
||||
return foundry.applications.api.DialogV2.wait({
|
||||
window: { title: "Würfel Modifikatoren: " + label },
|
||||
position: {
|
||||
width: 600
|
||||
},
|
||||
classes: ["M6", "dialog"],
|
||||
content,
|
||||
actions: {},
|
||||
render: (_event, dialog) => {
|
||||
const dialogHTML = dialog.element;
|
||||
|
||||
const display = dialogHTML.querySelector("#rollDisplay");
|
||||
|
||||
// Variable bei jeder Änderung aktualisieren
|
||||
document.querySelectorAll('input[name="vorteil-segment"]').forEach((radio) => {
|
||||
radio.addEventListener("change", (e) => {
|
||||
vorteil = parseInt(e.target.value);
|
||||
switch (vorteil) {
|
||||
case 1:
|
||||
display.placeholder = `2d20kh + ${skillValue} (Vorteil)`;
|
||||
break;
|
||||
case -1:
|
||||
display.placeholder = `2d20kl + ${skillValue} (Nachteil)`;
|
||||
break;
|
||||
default:
|
||||
display.placeholder = `1d20 + ${skillValue}`;
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('input[name="spezialisierung-segment"]').forEach((radio) => {
|
||||
radio.addEventListener("change", (e) => {
|
||||
spezLevel = parseInt(e.target.value);
|
||||
spezName = e.target.dataset.name;
|
||||
});
|
||||
if (radio.dataset.name === preSelectedSpez) {
|
||||
radio.click();
|
||||
}
|
||||
});
|
||||
},
|
||||
buttons: [
|
||||
{
|
||||
action: "abort",
|
||||
label: "Midgard6.Dialog.abbrechen",
|
||||
callback: (event, button, dialog) => {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
{
|
||||
action: "roll",
|
||||
label: "Midgard6.Dialog.würfeln",
|
||||
default: true,
|
||||
callback: (event, button, dialog) => {
|
||||
const rollData = {
|
||||
customRoll: button.form.elements.customRoll.value,
|
||||
customDamageRoll: button.form.elements.customDamageRoll?.value || "",
|
||||
vorteil,
|
||||
spezLevel,
|
||||
spezName
|
||||
};
|
||||
return rollData;
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Helper functions */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
@@ -0,0 +1,348 @@
|
||||
import { systemPath } from "../../constants.mjs";
|
||||
|
||||
export async function rollSpell(event, target) {
|
||||
const dataset = target.dataset;
|
||||
const skill = foundry.utils.getProperty(this.actor, "system.skills.magie.zaubern");
|
||||
const item = this.actor.items.get(dataset.itemId);
|
||||
const actor = this.actor;
|
||||
const dialogResult = await rollDialog({
|
||||
name: dataset.name,
|
||||
skill,
|
||||
damageRoll: item.system.eigenschaften.schaden,
|
||||
preSelectedSpez: item.system.eigenschaften.ursprung,
|
||||
actor
|
||||
});
|
||||
console.log("Dialog Result", dialogResult);
|
||||
if (dialogResult === "abort") {
|
||||
return;
|
||||
}
|
||||
// Construct the Roll instance
|
||||
const skillValue = skill.value;
|
||||
let die = "";
|
||||
switch (dialogResult.vorteil) {
|
||||
case -1:
|
||||
die = "2d20kl";
|
||||
break;
|
||||
case 1:
|
||||
die = "2d20kh";
|
||||
break;
|
||||
default:
|
||||
die = "1d20";
|
||||
break;
|
||||
}
|
||||
|
||||
let rollTerm = "@die + @skill";
|
||||
let rollFlavor = dataset.name;
|
||||
let roll;
|
||||
|
||||
if (dialogResult.spezLevel) {
|
||||
rollTerm += " + @spezBonus";
|
||||
rollFlavor += ": " + dialogResult.spezName;
|
||||
}
|
||||
|
||||
if (dialogResult.customRoll) {
|
||||
roll = new Roll(dialogResult.customRoll);
|
||||
} else {
|
||||
roll = new Roll(
|
||||
rollTerm,
|
||||
{
|
||||
die: die,
|
||||
skill: skillValue,
|
||||
spezBonus: dialogResult.spezLevel + 1
|
||||
},
|
||||
{ title: rollFlavor }
|
||||
);
|
||||
}
|
||||
|
||||
// The parsed terms of the roll formula
|
||||
console.log("Roll:", roll); // [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm]
|
||||
|
||||
// Execute the roll
|
||||
await roll.evaluate();
|
||||
|
||||
const chatData = {
|
||||
rolls: roll,
|
||||
speaker: ChatMessage.getSpeaker(),
|
||||
flags: {
|
||||
"midgard6-lvd": {
|
||||
title: rollFlavor,
|
||||
eigenschaften: item.eigenschaften,
|
||||
isSpell: true,
|
||||
beschreibung: await foundry.applications.ux.TextEditor.implementation.enrichHTML(
|
||||
item.system.beschreibung,
|
||||
{
|
||||
// Whether to show secret blocks in the finished html
|
||||
secrets: false,
|
||||
// Data to fill in for inline rolls
|
||||
rollData: this.actor.getRollData(),
|
||||
// Relative UUID resolution
|
||||
relativeTo: this.actor
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ChatMessage.applyMode(chatData, dialogResult.rollMode);
|
||||
|
||||
await ChatMessage.create(chatData);
|
||||
}
|
||||
|
||||
export async function rollSkill(event, target) {
|
||||
const dataset = target.dataset;
|
||||
const skill = foundry.utils.getProperty(this.actor, target.dataset.path.replace(".value", ""));
|
||||
const actor = this.actor;
|
||||
const dialogResult = await rollDialog({
|
||||
name: dataset.name,
|
||||
skill,
|
||||
actor
|
||||
});
|
||||
console.log("Dialog Result", dialogResult);
|
||||
if (dialogResult === "abort") {
|
||||
return;
|
||||
}
|
||||
// Construct the Roll instance
|
||||
const skillValue = skill.value;
|
||||
let die = "";
|
||||
switch (dialogResult.vorteil) {
|
||||
case -1:
|
||||
die = "2d20kl";
|
||||
break;
|
||||
case 1:
|
||||
die = "2d20kh";
|
||||
break;
|
||||
default:
|
||||
die = "1d20";
|
||||
break;
|
||||
}
|
||||
|
||||
let rollTerm = "@die + @skill";
|
||||
let rollFlavor = dataset.name;
|
||||
let roll;
|
||||
|
||||
if (dialogResult.spezLevel) {
|
||||
rollTerm += " + @spezBonus";
|
||||
rollFlavor += ": " + dialogResult.spezName;
|
||||
}
|
||||
|
||||
if (dialogResult.customRoll) {
|
||||
roll = new Roll(dialogResult.customRoll);
|
||||
} else {
|
||||
roll = new Roll(
|
||||
rollTerm,
|
||||
{
|
||||
die: die,
|
||||
skill: skillValue,
|
||||
spezBonus: dialogResult.spezLevel + 1
|
||||
},
|
||||
{ title: rollFlavor }
|
||||
);
|
||||
}
|
||||
|
||||
// The parsed terms of the roll formula
|
||||
console.log("Roll:", roll); // [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm]
|
||||
|
||||
// Execute the roll
|
||||
await roll.evaluate();
|
||||
|
||||
const chatData = {
|
||||
rolls: roll,
|
||||
speaker: ChatMessage.getSpeaker(),
|
||||
flags: {
|
||||
"midgard6-lvd": {
|
||||
title: rollFlavor
|
||||
}
|
||||
}
|
||||
};
|
||||
console.warn(dialogResult);
|
||||
|
||||
// Nutze applyRollMode, um Sichtbarkeiten (Whisper, Blind) korrekt zu setzen
|
||||
ChatMessage.applyMode(chatData, dialogResult.rollMode);
|
||||
|
||||
// Erstelle die Nachricht mit den manipulierten Daten
|
||||
await ChatMessage.create(chatData);
|
||||
}
|
||||
|
||||
export async function rollWeapon(event, target) {
|
||||
const dataset = target.dataset;
|
||||
const weapon = this.actor.items.get(dataset.itemId);
|
||||
const skill = foundry.utils.getProperty(this.actor, weapon.system.fertigkeit);
|
||||
const actor = this.actor;
|
||||
const dialogResult = await rollDialog({
|
||||
name: weapon.name,
|
||||
skill,
|
||||
damageRoll: weapon.system.schaden,
|
||||
preSelectedSpez: weapon.system.spezialisierung,
|
||||
actor
|
||||
});
|
||||
console.log("Dialog Result", dialogResult);
|
||||
if (dialogResult === "abort") {
|
||||
return;
|
||||
}
|
||||
// Construct the Roll instance
|
||||
const skillValue = skill.value;
|
||||
let die = "";
|
||||
switch (dialogResult.vorteil) {
|
||||
case -1:
|
||||
die = "2d20kl";
|
||||
break;
|
||||
case 1:
|
||||
die = "2d20kh";
|
||||
break;
|
||||
default:
|
||||
die = "1d20";
|
||||
break;
|
||||
}
|
||||
|
||||
let rollTerm = "@die + @skill";
|
||||
let rollFlavor = game.i18n.localize("Midgard6.Angriff");
|
||||
let attackRoll;
|
||||
let damageRoll;
|
||||
|
||||
if (dialogResult.spezLevel) {
|
||||
rollTerm += " + @spezBonus";
|
||||
rollFlavor += " (" + dialogResult.spezName + ")";
|
||||
}
|
||||
rollFlavor += ": " + weapon.name;
|
||||
|
||||
if (dialogResult.customRoll) {
|
||||
attackRoll = await new Roll(dialogResult.customRoll).evaluate();
|
||||
} else {
|
||||
attackRoll = await new Roll(
|
||||
rollTerm,
|
||||
{
|
||||
die: die,
|
||||
skill: skillValue,
|
||||
spezBonus: dialogResult.spezLevel + 1
|
||||
},
|
||||
{ title: rollFlavor }
|
||||
).evaluate();
|
||||
}
|
||||
|
||||
damageRoll = await new Roll(
|
||||
"@die",
|
||||
{ die: weapon.system.schaden },
|
||||
{ title: game.i18n.localize("Midgard6.Schaden") }
|
||||
).evaluate();
|
||||
|
||||
// The parsed terms of the roll formula
|
||||
console.warn(dialogResult);
|
||||
const chatData = {
|
||||
rolls: [attackRoll, damageRoll],
|
||||
speaker: ChatMessage.getSpeaker(),
|
||||
flags: {
|
||||
"midgard6-lvd": {
|
||||
title: rollFlavor,
|
||||
eigenschaften: weapon.eigenschaften,
|
||||
beschreibung: await foundry.applications.ux.TextEditor.implementation.enrichHTML(
|
||||
weapon.system.beschreibung,
|
||||
{
|
||||
secrets: false,
|
||||
rollData: this.actor.getRollData(),
|
||||
relativeTo: this.actor
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ChatMessage.applyMode(chatData, dialogResult.rollMode);
|
||||
|
||||
await ChatMessage.create(chatData);
|
||||
}
|
||||
|
||||
async function rollDialog(rollDialogRequest) {
|
||||
// Assamble dialog depending on roll type
|
||||
let label = rollDialogRequest.name;
|
||||
let skillValue = rollDialogRequest.skill.value || rollDialogRequest.skill;
|
||||
let bonuses = rollDialogRequest.skill.bonuses || [];
|
||||
let damageRoll = rollDialogRequest.damageRoll || "";
|
||||
let preSelectedSpez = rollDialogRequest.preSelectedSpez || "";
|
||||
let vorteil = 0;
|
||||
let customRoll = "";
|
||||
let spezLevel;
|
||||
let spezName = "";
|
||||
// 1. Define the path to .hbs template
|
||||
const templatePath = systemPath("templates/dialog/roll-dialog.hbs");
|
||||
const templateData = {
|
||||
skillValue,
|
||||
bonuses,
|
||||
vorteil,
|
||||
damageRoll,
|
||||
preSelectedSpez,
|
||||
customRoll,
|
||||
rollModes: CONFIG.ChatMessage.modes
|
||||
};
|
||||
// 2. Render the Handlebars template into an HTML string
|
||||
const content = await foundry.applications.handlebars.renderTemplate(templatePath, templateData);
|
||||
// return new Promise((resolve, reject) => {
|
||||
// const dialog = new foundry.applications.api.DialogV2({
|
||||
return foundry.applications.api.DialogV2.wait({
|
||||
window: { title: "Würfel Modifikatoren: " + label },
|
||||
position: {
|
||||
width: 600
|
||||
},
|
||||
classes: ["M6", "dialog"],
|
||||
content,
|
||||
actions: {},
|
||||
render: (_event, dialog) => {
|
||||
const dialogHTML = dialog.element;
|
||||
|
||||
const display = dialogHTML.querySelector("#rollDisplay");
|
||||
|
||||
// Variable bei jeder Änderung aktualisieren
|
||||
document.querySelectorAll('input[name="vorteil-segment"]').forEach((radio) => {
|
||||
radio.addEventListener("change", (e) => {
|
||||
vorteil = parseInt(e.target.value);
|
||||
switch (vorteil) {
|
||||
case 1:
|
||||
display.placeholder = `2d20kh + ${skillValue} (Vorteil)`;
|
||||
break;
|
||||
case -1:
|
||||
display.placeholder = `2d20kl + ${skillValue} (Nachteil)`;
|
||||
break;
|
||||
default:
|
||||
display.placeholder = `1d20 + ${skillValue}`;
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('input[name="spezialisierung-segment"]').forEach((radio) => {
|
||||
radio.addEventListener("change", (e) => {
|
||||
spezLevel = parseInt(e.target.value);
|
||||
spezName = e.target.dataset.name;
|
||||
});
|
||||
if (radio.dataset.name === preSelectedSpez) {
|
||||
radio.click();
|
||||
}
|
||||
});
|
||||
},
|
||||
buttons: [
|
||||
{
|
||||
action: "abort",
|
||||
label: "Midgard6.Dialog.abbrechen",
|
||||
callback: (event, button, dialog) => {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
{
|
||||
action: "roll",
|
||||
label: "Midgard6.Dialog.würfeln",
|
||||
default: true,
|
||||
callback: (event, button, dialog) => {
|
||||
const rollData = {
|
||||
customRoll: button.form.elements.customRoll.value,
|
||||
customDamageRoll: button.form.elements.customDamageRoll?.value || "",
|
||||
vorteil,
|
||||
spezLevel,
|
||||
spezName,
|
||||
rollMode:
|
||||
button.form.elements.rollMode?.value || game.settings.get("core", "messageMode")
|
||||
};
|
||||
return rollData;
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
@import url("./items-page.scss");
|
||||
@import url("./hintergrund.scss");
|
||||
@import url("./icons.scss");
|
||||
@import url("./chat-messages.scss");
|
||||
|
||||
:root {
|
||||
--M6-background-grey: #d3d7d7;
|
||||
@@ -15,6 +16,9 @@
|
||||
--M6-text-brown: #be7742;
|
||||
}
|
||||
|
||||
.inline-roll {
|
||||
background-color: var(--M6-background-brown);
|
||||
}
|
||||
.M6 {
|
||||
fieldset {
|
||||
border-radius: 0;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
.chat-message {
|
||||
background: none;
|
||||
border-radius: 0;
|
||||
}
|
||||
.message-header {
|
||||
.message-names {
|
||||
color: var(--M6-text-brown);
|
||||
font-weight: bold;
|
||||
font-size: 18px;
|
||||
}
|
||||
}
|
||||
.chat-message.message {
|
||||
background-color: var(--M6-background-grey);
|
||||
|
||||
fieldset {
|
||||
background-color: var(--M6-background-white);
|
||||
|
||||
&.highlight {
|
||||
background-color: var(--M6-background-brown);
|
||||
}
|
||||
legend {
|
||||
color: var(--M6-text-brown);
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
||||
.collapsible {
|
||||
background-color: var(--M6-background-white);
|
||||
cursor: pointer;
|
||||
padding: 12px;
|
||||
font-size: 15px;
|
||||
margin-bottom: 4px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin: 8px 4px;
|
||||
|
||||
&.active {
|
||||
background-color: var(--M6-background-brown);
|
||||
box-shadow: none;
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */
|
||||
|
||||
/* Style the collapsible content. Note: hidden by default */
|
||||
.content {
|
||||
padding: 0 18px;
|
||||
display: none;
|
||||
width: auto;
|
||||
overflow: hidden;
|
||||
background-color: var(--M6-background-white);
|
||||
&.active {
|
||||
display: block;
|
||||
width: auto;
|
||||
margin: 8px 4px;
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
-5
@@ -1,3 +1,7 @@
|
||||
import { systemPath } from "./constants.mjs";
|
||||
import { loadHelpers } from "./helpers/handlebar-helpers.mjs";
|
||||
import { loadPartials } from "./helpers/partials.mjs";
|
||||
|
||||
import { CharacterData } from "./data/character-data.mjs";
|
||||
import { WeaponData } from "./data/weapon-data.mjs";
|
||||
import { ItemData } from "./data/item-data.mjs";
|
||||
@@ -10,10 +14,13 @@ import { M6WeaponSheet } from "./sheets/weapon-sheet.mjs";
|
||||
import { M6ArmorSheet } from "./sheets/armor-sheet.mjs";
|
||||
import { M6ZauberSheet } from "./sheets/zauber-sheet.mjs";
|
||||
import { M6HintergrundSheet } from "./sheets/hintergrund-sheet.mjs";
|
||||
import { loadHelpers } from "./helpers/handlebar-helpers.mjs";
|
||||
import { M6ChatMessage } from "./ui/chat-message.mjs";
|
||||
import "./styles/M6.scss";
|
||||
|
||||
Hooks.once("init", () => {
|
||||
CONFIG.ChatMessage.documentClass = M6ChatMessage;
|
||||
CONFIG.ChatMessage.template = systemPath("templates/chat/message-default.hbs");
|
||||
|
||||
CONFIG.Actor.dataModels.character = CharacterData;
|
||||
CONFIG.Actor.trackableAttributes = {
|
||||
pc: {
|
||||
@@ -57,7 +64,7 @@ Hooks.once("init", () => {
|
||||
"midgard6-lvd",
|
||||
M6HintergrundSheet,
|
||||
{
|
||||
types: ["hintergrund", "gunst"]
|
||||
types: ["gunst"]
|
||||
}
|
||||
);
|
||||
foundry.applications.apps.DocumentSheetConfig.registerSheet(
|
||||
@@ -65,7 +72,7 @@ Hooks.once("init", () => {
|
||||
"midgard6-lvd",
|
||||
M6HintergrundSheet,
|
||||
{
|
||||
types: ["hintergrund", "makel"]
|
||||
types: ["makel"]
|
||||
}
|
||||
);
|
||||
foundry.applications.apps.DocumentSheetConfig.registerSheet(
|
||||
@@ -73,7 +80,7 @@ Hooks.once("init", () => {
|
||||
"midgard6-lvd",
|
||||
M6HintergrundSheet,
|
||||
{
|
||||
types: ["hintergrund", "schicksalsgabe"]
|
||||
types: ["schicksalsgabe"]
|
||||
}
|
||||
);
|
||||
foundry.applications.apps.DocumentSheetConfig.registerSheet(
|
||||
@@ -81,9 +88,29 @@ Hooks.once("init", () => {
|
||||
"midgard6-lvd",
|
||||
M6HintergrundSheet,
|
||||
{
|
||||
types: ["hintergrund", "legende"]
|
||||
types: ["legende"]
|
||||
}
|
||||
);
|
||||
|
||||
loadHelpers();
|
||||
|
||||
loadPartials();
|
||||
});
|
||||
|
||||
Hooks.on("renderChatMessageHTML", (message, html, data) => {
|
||||
const collapsible = html.querySelectorAll("div[data-action=collapsible]");
|
||||
if (collapsible) {
|
||||
collapsible.forEach((node) => {
|
||||
node.addEventListener(
|
||||
"click",
|
||||
function () {
|
||||
node.classList.toggle("active");
|
||||
var content = node.nextElementSibling;
|
||||
content.classList.toggle("active");
|
||||
node.getElementsByTagName("i")[0].classList.toggle("fa-compress");
|
||||
},
|
||||
{ capture: true }
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -7,7 +7,6 @@
|
||||
<legend>{{localize "Midgard6.Item.type.zauber.plural" }}</legend>
|
||||
|
||||
<ul class="itemTypes">
|
||||
{{!-- {{#with itemTypes.zauber}} --}}
|
||||
<li class="itemHeader">
|
||||
<div class="document-controls">
|
||||
{{#if @root.editable}}
|
||||
@@ -31,7 +30,7 @@
|
||||
<p class="col-3 item-name">{{zauber.system.eigenschaften.ursprung}}</p>
|
||||
<p class="col-2 item-name">{{localize "Midgard6.Zauber.stufe"}} {{zauber.system.eigenschaften.stufe}}</p>
|
||||
<a class="align-self-center col-1 fa-solid {{#if zauber.system.equipped}}fa-book-open{{else}}fa-book{{/if}}" data-action="cycleEquip" data-item-id="{{zauber._id}}" style="{{#if zauber.system.equipped}}color: var(--M6-text-brown);{{/if}}"></a>
|
||||
<a class="align-self-center col-2 fa-solid fa-dice-d20" data-action="rollSpell" data-item-id="{{zauber._id}}"></a>
|
||||
<a class="align-self-center col-2 fa-solid fa-dice-d20" data-action="rollSpell" data-name="{{zauber.name}}" data-item-id="{{zauber._id}}"></a>
|
||||
<div class="col-1 d-flex document-controls" style="margin: 0.5rem 0; padding: 0">
|
||||
{{#if @root.editable}}
|
||||
<a
|
||||
@@ -53,7 +52,6 @@
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{!-- {{/with}} --}}
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<header class="message-header flexrow">
|
||||
<div class="portrait token">
|
||||
<img src="{{portrait}}" alt="{{alias}}" inert />
|
||||
</div>
|
||||
<div class="message-names flexcol">
|
||||
<span class="message-sender">
|
||||
{{alias}}
|
||||
</span>
|
||||
{{#if isWhisper}}
|
||||
<span class="whisper-to">{{localize "CHAT.To"}}: {{whisperTo}}</span>
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="message-metadata">
|
||||
{{!-- <time class="message-timestamp">{{timeSinceShort message.timestamp}}</time> --}}
|
||||
{{#if canDelete}}
|
||||
<a aria-label="{{localize 'Delete'}}" class="message-delete" data-action="deleteMessage">
|
||||
<i class="fa-solid fa-trash" inert></i>
|
||||
</a>
|
||||
{{/if}}
|
||||
{{#if canClose}}
|
||||
<a
|
||||
aria-label="{{localize 'CHAT.Dismiss'}}"
|
||||
class="message-dismiss"
|
||||
data-action="dismissMessage"
|
||||
>
|
||||
<i class="fa-solid fa-xmark" inert></i>
|
||||
</a>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
{{#if message.flavor}}
|
||||
<span class="flavor-text">{{{message.flavor}}}</span>
|
||||
{{/if}}
|
||||
</header>
|
||||
@@ -0,0 +1,48 @@
|
||||
<li class="chat-message message flexcol {{cssClass}}" data-message-id="{{message._id}}" {{#if borderColor}}style="border-color:{{borderColor}}"{{/if}}>
|
||||
{{> "systems/midgard6-lvd/src/templates/chat/chat-message-header.hbs"}}
|
||||
|
||||
{{!-- <hr> --}}
|
||||
{{#if isContentVisible}}
|
||||
{{#if isRoll}}
|
||||
{{#each message.content as |roll|}}
|
||||
<fieldset>
|
||||
{{#if roll.options.title}}<legend>{{roll.options.title}}</legend>{{/if}}
|
||||
{{{roll.html}}}
|
||||
</fieldset>
|
||||
{{/each}}
|
||||
{{else}}
|
||||
<fieldset>
|
||||
{{#if title}}<legend>{{title}}</legend>{{/if}}
|
||||
{{{message.content}}}
|
||||
</fieldset>
|
||||
{{/if}}
|
||||
|
||||
{{#if beschreibung}}
|
||||
<div
|
||||
class="collapsible"
|
||||
data-action="collapsible"
|
||||
>{{localize "Midgard6.Item.Description"}}
|
||||
<div>
|
||||
<i class="fas fa-expand"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
{{{beschreibung}}}
|
||||
</div>
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<fieldset>
|
||||
{{#if isRoll}}
|
||||
<legend>???</legend>
|
||||
<div class="dice-roll">
|
||||
<div class="dice-result">
|
||||
<div class="dice-formula">???</div>
|
||||
<h4 class="dice-total">?</h4>
|
||||
</div>
|
||||
</div>
|
||||
{{else}}
|
||||
<p>???</p>
|
||||
{{/if}}
|
||||
</fieldset>
|
||||
{{/if}}
|
||||
</li>
|
||||
@@ -80,6 +80,12 @@
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="d-flex">
|
||||
<select style="max-width: 15rem; margin-left: 8px" name="rollMode" data-type="String">
|
||||
{{selectOptions rollModes selected=rollMode localize=true}}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</fieldset>
|
||||
</section>
|
||||
@@ -0,0 +1,188 @@
|
||||
// import { processMessage } from "./message-logic/process-message.js";
|
||||
|
||||
export class M6ChatMessage extends ChatMessage {
|
||||
// Default avatar for the chat message
|
||||
static DEFAULT_AVATAR = "icons/svg/mystery-man.svg";
|
||||
|
||||
_attachPartListeners(partId, html, bubble) {
|
||||
super._attachPartListeners(partId, html, bubble);
|
||||
console.warn("Here");
|
||||
|
||||
switch (partId) {
|
||||
case "hintergrund":
|
||||
const collapsible = html.querySelectorAll("div[data-action=collapsible]");
|
||||
if (collapsible) {
|
||||
collapsible.forEach((node) => {
|
||||
node.addEventListener(
|
||||
"click",
|
||||
function () {
|
||||
node.classList.toggle("active");
|
||||
var content = node.nextElementSibling;
|
||||
content.classList.toggle("active");
|
||||
node.getElementsByTagName("i")[0].classList.toggle("fa-compress");
|
||||
},
|
||||
{ capture: true }
|
||||
);
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the HTML for the ChatMessage which should be added to the log
|
||||
* @param {object} [options] Additional options passed to the Handlebars template.
|
||||
* @param {boolean} [options.canDelete] Render a delete button. By default, this is true for GM users.
|
||||
* @param {boolean} [options.canClose] Render a close button for dismissing chat card notifications.
|
||||
* @returns {Promise<HTMLElement>}
|
||||
*/
|
||||
async renderHTML({ canDelete, canClose = false, ...rest } = {}) {
|
||||
// Default message template
|
||||
this.template = CONFIG.ChatMessage.template;
|
||||
|
||||
// By default, GM users have the trash-bin icon in the chat log itself
|
||||
canDelete ??= game.user.isGM;
|
||||
|
||||
if (typeof this.system.renderHTML === "function") {
|
||||
const html = await this.system.renderHTML({ canDelete, canClose, ...rest });
|
||||
Hooks.callAll("renderChatMessageHTML", this, html);
|
||||
return html;
|
||||
}
|
||||
// Determine some metadata
|
||||
const speakerActor = this.speakerActor;
|
||||
const data = this.toObject(false);
|
||||
if (!this.isRoll || this.isContentVisible) {
|
||||
data.content = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
|
||||
data?.flags?.m6?.description || this.content,
|
||||
{
|
||||
rollData: this.getRollData(),
|
||||
secrets: speakerActor?.isOwner ?? game.user.isGM
|
||||
}
|
||||
);
|
||||
}
|
||||
const isWhisper = this.whisper.length;
|
||||
|
||||
// Construct message data
|
||||
this.messageData = {
|
||||
// Base messageData and permissions
|
||||
...rest,
|
||||
message: data,
|
||||
canDelete,
|
||||
canClose,
|
||||
isGM: game.user.isGM,
|
||||
isWhisper: this.whisper.length,
|
||||
whisperTo: this.whisper.map((u) => game.users.get(u)?.name).filterJoin(", "),
|
||||
isContentVisible: this.isContentVisible,
|
||||
|
||||
// User and author data
|
||||
user: game.user,
|
||||
author: this.author,
|
||||
|
||||
// Display info
|
||||
title: this.flags["midgard6-lvd"]?.title,
|
||||
name: this.flags["midgard6-lvd"]?.name,
|
||||
description: this.flags["midgard6-lvd"]?.description,
|
||||
alias: this.alias,
|
||||
speakerActor,
|
||||
|
||||
// If the user can't see the currently visible content, then prefer the author's avatar;
|
||||
// Otherwise, use the character's avatar (if present), and fall back to the default avatar
|
||||
// as a last resort
|
||||
portrait:
|
||||
((this.isContentVisible ? speakerActor?.img : undefined) ?? this.author?.avatar) ||
|
||||
this.constructor.DEFAULT_AVATAR,
|
||||
|
||||
// CSS classes
|
||||
cssClass: [
|
||||
this.style === CONST.CHAT_MESSAGE_STYLES.IC ? "ic" : null,
|
||||
this.style === CONST.CHAT_MESSAGE_STYLES.EMOTE ? "emote" : null,
|
||||
isWhisper ? "whisper" : null,
|
||||
this.blind ? "blind" : null
|
||||
].filterJoin(" "),
|
||||
|
||||
// System-specific flags
|
||||
beschreibung: this.isContentVisible ? this.getFlag("midgard6-lvd", "beschreibung") : "",
|
||||
isSpell: this.getFlag("midgard6-lvd", "isSpell"),
|
||||
isRoll: this?.isRoll || false
|
||||
};
|
||||
// Render additional message data
|
||||
if (this.isRoll) {
|
||||
await this.#renderRollContent(this.messageData);
|
||||
}
|
||||
|
||||
// Add a check in for in case modules are adding content to use that as the description
|
||||
// if (this.messageData?.message?.content) {
|
||||
// this.messageData.description = this.messageData?.message?.content;
|
||||
// }
|
||||
console.warn(this.messageData);
|
||||
// Render the chat message
|
||||
let html = await foundry.applications.handlebars.renderTemplate(
|
||||
this.template,
|
||||
this.messageData
|
||||
);
|
||||
html = foundry.utils.parseHTML(html);
|
||||
// Flag expanded state of dice rolls
|
||||
Hooks.callAll("renderChatMessageHTML", this, html, this.messageData);
|
||||
|
||||
// Get whether descriptions should auto-collapse for this user or not and apply the styling
|
||||
// const autoCollapse = game.settings.get("midgard6-lvd", "autoCollapseDescriptions");
|
||||
// if (!autoCollapse) {
|
||||
// const collapsibleContent = html.querySelector(".collapsible-content");
|
||||
// if (collapsibleContent) collapsibleContent.style.maxHeight = "unset";
|
||||
// }
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
// Code pulled from core since this is a private method as of V13
|
||||
async #renderRollContent(messageData) {
|
||||
const data = messageData.message;
|
||||
const renderRolls = async (isPrivate) => {
|
||||
let html = "";
|
||||
let content = [];
|
||||
|
||||
for (const roll of this.rolls) {
|
||||
html = await roll.render({
|
||||
isPrivate
|
||||
});
|
||||
content.push({ options: roll.options, html });
|
||||
}
|
||||
return content;
|
||||
};
|
||||
|
||||
// Suppress the "to:" whisper flavor for private rolls
|
||||
if (this.blind || this.whisper.length) messageData.isWhisper = false;
|
||||
|
||||
// Display standard Roll HTML content
|
||||
if (this.isContentVisible) {
|
||||
const el = document.createElement("div");
|
||||
el.innerHTML = data.content; // Ensure the content does not already contain custom HTML
|
||||
if (!el.childElementCount && this.rolls.length) {
|
||||
data.content = await this.#renderRollHTML(false);
|
||||
}
|
||||
} else {
|
||||
// Otherwise, show "rolled privately" messages for Roll content
|
||||
const name = this.author?.name ?? game.i18n.localize("CHAT.UnknownUser");
|
||||
data.flavor = game.i18n.format("CHAT.PrivateRollContent", {
|
||||
user: foundry.utils.escapeHTML(name)
|
||||
});
|
||||
data.content = await renderRolls(true);
|
||||
messageData.alias = name;
|
||||
}
|
||||
}
|
||||
|
||||
async #renderRollHTML(isPrivate) {
|
||||
let html = "";
|
||||
let content = [];
|
||||
|
||||
for (const roll of this.rolls) {
|
||||
html = await roll.render({
|
||||
isPrivate,
|
||||
message: this
|
||||
});
|
||||
content.push({ options: roll.options, html });
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user