add functoning rolls
This commit is contained in:
1 parent
24c81dbcf8
commit
2fa131d2c5
9 files changed
+275
-19
No files matched your search
@@ -1,6 +1,13 @@
|
|||||||
|
:root {
|
||||||
|
--M6-background-grey: #d3d7d7;
|
||||||
|
--M6-background-brown: #eedecd;
|
||||||
|
--M6-background-white: #fdfeff;
|
||||||
|
--M6-text-grey: #595d5f;
|
||||||
|
--M6-text-brown: #be7742;
|
||||||
|
}
|
||||||
.application.sheet.M6 {
|
.application.sheet.M6 {
|
||||||
background-color: #d3d7d7;
|
background-color: var(--M6-background-grey);
|
||||||
color: #595d5f;
|
color: var(--M6-text-grey);
|
||||||
|
|
||||||
section {
|
section {
|
||||||
.sheet-header {
|
.sheet-header {
|
||||||
@@ -9,7 +16,7 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
top: 8px;
|
top: 8px;
|
||||||
left: 44%;
|
left: 44%;
|
||||||
background-color: #d3d7d7;
|
background-color: var(--M6-background-grey);
|
||||||
&:hover {
|
&:hover {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
@@ -23,7 +30,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
input {
|
input {
|
||||||
background-color: #fdfeff;
|
background-color: var(--M6-background-white);
|
||||||
color: black;
|
color: black;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
&.skill {
|
&.skill {
|
||||||
@@ -48,13 +55,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fieldset {
|
fieldset {
|
||||||
background-color: #eedecd;
|
background-color: var(--M6-background-brown);
|
||||||
|
legend {
|
||||||
|
color: var(--M6-text-brown);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.sheet-header {
|
.sheet-header {
|
||||||
img {
|
img {
|
||||||
border-radius: 0 0 50% 50%;
|
border-radius: 0 0 50% 50%;
|
||||||
border: solid 16px #d3d7d7;
|
border: solid 16px var(--M6-background-grey);
|
||||||
border-top: none;
|
border-top: none;
|
||||||
flex: 0 0 100px;
|
flex: 0 0 100px;
|
||||||
object-fit: fill;
|
object-fit: fill;
|
||||||
@@ -126,3 +136,49 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.application.dialog {
|
||||||
|
background-color: var(--M6-background-grey);
|
||||||
|
color: var(--M6-text-grey);
|
||||||
|
|
||||||
|
section {
|
||||||
|
input {
|
||||||
|
background-color: var(--M6-background-white);
|
||||||
|
color: black;
|
||||||
|
border-radius: 0;
|
||||||
|
&[type="range"] {
|
||||||
|
background-color: var(--M6-background-brown);
|
||||||
|
max-width: 30px;
|
||||||
|
}
|
||||||
|
&.skill {
|
||||||
|
max-width: 2rem;
|
||||||
|
text-align: center;
|
||||||
|
margin-left: 0.5rem;
|
||||||
|
}
|
||||||
|
&.attribut {
|
||||||
|
max-width: 2rem;
|
||||||
|
text-align: center;
|
||||||
|
margin: 0 0.5rem;
|
||||||
|
}
|
||||||
|
&.text {
|
||||||
|
&.right {
|
||||||
|
text-align: end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
&.center {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldset {
|
||||||
|
background-color: var(--M6-background-brown);
|
||||||
|
legend {
|
||||||
|
color: var(--M6-text-brown);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i {
|
||||||
|
color: var(--M6-text-brown);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,10 @@
|
|||||||
"glaube": "Glaube",
|
"glaube": "Glaube",
|
||||||
"mondgestalt": "Mondgestalt"
|
"mondgestalt": "Mondgestalt"
|
||||||
},
|
},
|
||||||
|
"Dialog": {
|
||||||
|
"abbrechen": "Abbrechen",
|
||||||
|
"würfeln": "Würfeln"
|
||||||
|
},
|
||||||
"Skills": {
|
"Skills": {
|
||||||
"gruppen": {
|
"gruppen": {
|
||||||
"kampf": "Kampf",
|
"kampf": "Kampf",
|
||||||
@@ -40,6 +44,11 @@
|
|||||||
"zaubern": "Zaubern",
|
"zaubern": "Zaubern",
|
||||||
"zauberwissen": "Zauberwissen"
|
"zauberwissen": "Zauberwissen"
|
||||||
},
|
},
|
||||||
|
"Resistenzen": {
|
||||||
|
"reflexe": "Reflexe",
|
||||||
|
"willenskraft": "Willenskraft",
|
||||||
|
"zähigkeit": "Zähigkeit"
|
||||||
|
},
|
||||||
"Sheets": {
|
"Sheets": {
|
||||||
"Tabs": {
|
"Tabs": {
|
||||||
"properties": "Fertigkeiten",
|
"properties": "Fertigkeiten",
|
||||||
|
|||||||
@@ -32,6 +32,23 @@ function defineSchema() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
resistenzen: new fields.SchemaField({
|
||||||
|
reflexe: new fields.NumberField({
|
||||||
|
required: true,
|
||||||
|
min: 0,
|
||||||
|
initial: 4
|
||||||
|
}),
|
||||||
|
willenskraft: new fields.NumberField({
|
||||||
|
required: true,
|
||||||
|
min: 0,
|
||||||
|
initial: 4
|
||||||
|
}),
|
||||||
|
zähigkeit: new fields.NumberField({
|
||||||
|
required: true,
|
||||||
|
min: 0,
|
||||||
|
initial: 4
|
||||||
|
})
|
||||||
|
}),
|
||||||
skills: new fields.SchemaField({
|
skills: new fields.SchemaField({
|
||||||
kampf: new fields.SchemaField(
|
kampf: new fields.SchemaField(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export const loadHelpers = async function () {
|
||||||
|
Handlebars.registerHelper("ifeq", function (arg1, arg2, options) {
|
||||||
|
return arg1 == arg2 ? options.fn(this) : options.inverse(this);
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -112,6 +112,10 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
|
|||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
async _preparePartContext(partId, context) {
|
async _preparePartContext(partId, context) {
|
||||||
switch (partId) {
|
switch (partId) {
|
||||||
|
case "stats":
|
||||||
|
context.fields = await this._getResources();
|
||||||
|
context.tab = context.tabs[partId];
|
||||||
|
break;
|
||||||
case "effects":
|
case "effects":
|
||||||
context.effects = prepareActiveEffectCategories(this.actor.allApplicableEffects());
|
context.effects = prepareActiveEffectCategories(this.actor.allApplicableEffects());
|
||||||
context.tab = context.tabs[partId];
|
context.tab = context.tabs[partId];
|
||||||
@@ -174,6 +178,30 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
|
|||||||
return fieldSets;
|
return fieldSets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _getResources() {
|
||||||
|
const doc = this.actor;
|
||||||
|
const source = doc._source;
|
||||||
|
const systemFields = CONFIG.Actor.dataModels[doc.type]?.schema.fields.resources.fields;
|
||||||
|
const fieldSets = [];
|
||||||
|
// TODO: Find a clever way to handle enrichment
|
||||||
|
for (const field of Object.values(systemFields ?? {})) {
|
||||||
|
const path = `system.skills.${field.name}`;
|
||||||
|
if (field instanceof foundry.data.fields.SchemaField) {
|
||||||
|
const fieldset = {
|
||||||
|
fieldset: true,
|
||||||
|
legend: `Midgard6.resources.${field.label}`,
|
||||||
|
fields: []
|
||||||
|
};
|
||||||
|
await this.#addSystemFields(fieldset, field.fields, source, path);
|
||||||
|
fieldSets.push(fieldset);
|
||||||
|
} else {
|
||||||
|
fieldSets.push({ outer: { field, value: foundry.utils.getProperty(source, path) } });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.warn(fieldSets);
|
||||||
|
return fieldSets;
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------- */
|
/* -------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -301,10 +329,32 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async #rollSkill(event, target) {
|
static async #rollSkill(event, target) {
|
||||||
console.warn(event, target.dataset);
|
const dataset = target.dataset;
|
||||||
|
const actor = this.actor;
|
||||||
|
const dialogResult = await this.rollDialog({
|
||||||
|
dataset,
|
||||||
|
actor
|
||||||
|
});
|
||||||
|
if (dialogResult.noRoll) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Construct the Roll instance
|
// Construct the Roll instance
|
||||||
const skillValue = target.dataset.value;
|
const skillValue = dataset.value;
|
||||||
let roll = new Roll("2d20kh + @skill", { skill: skillValue }, { flavor: target.dataset.name });
|
let die = "";
|
||||||
|
console.warn(dialogResult);
|
||||||
|
switch (dialogResult.vorteil) {
|
||||||
|
case "-1":
|
||||||
|
die = "2d20kl";
|
||||||
|
break;
|
||||||
|
case "1":
|
||||||
|
die = "2d20kh";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
die = "1d20";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
let roll = new Roll("@die + @skill", { die: die, skill: skillValue }, { flavor: dataset.name });
|
||||||
|
|
||||||
// The parsed terms of the roll formula
|
// The parsed terms of the roll formula
|
||||||
console.log("Roll:", roll); // [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm]
|
console.log("Roll:", roll); // [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm]
|
||||||
@@ -319,6 +369,86 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
|
|||||||
// console.warn(message);
|
// console.warn(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async rollDialog(rollDialogRequest) {
|
||||||
|
// Assamble dialog depending on roll type
|
||||||
|
let label = rollDialogRequest.dataset.name;
|
||||||
|
let skill = rollDialogRequest.dataset.value;
|
||||||
|
let vorteil = 0;
|
||||||
|
let customRoll = "";
|
||||||
|
// 1. Define the path to .hbs template
|
||||||
|
const templatePath = systemPath("templates/dialog/roll-dialog.hbs");
|
||||||
|
const templateData = {
|
||||||
|
classes: ["roll"],
|
||||||
|
skill,
|
||||||
|
vorteil,
|
||||||
|
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
|
||||||
|
},
|
||||||
|
content,
|
||||||
|
actions: {},
|
||||||
|
render: (_event, dialog) => {
|
||||||
|
const dialogHTML = dialog.element;
|
||||||
|
|
||||||
|
const slider = dialogHTML.querySelector("#vorteilSlider");
|
||||||
|
const display = dialogHTML.querySelector("#rollDisplay");
|
||||||
|
|
||||||
|
slider.addEventListener("input", (e) => {
|
||||||
|
const vorteilWert = parseInt(e.target.value);
|
||||||
|
switch (vorteilWert) {
|
||||||
|
case 1:
|
||||||
|
display.placeholder = `2d20kh + ${skill} (Vorteil)`;
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
display.placeholder = `2d20kl + ${skill} (Nachteil)`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
display.placeholder = `1d20 + ${skill}`;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
action: "abort",
|
||||||
|
label: "Midgard6.Dialog.abbrechen",
|
||||||
|
callback: (event, button, dialog) => {
|
||||||
|
return { noRoll: true };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: "roll",
|
||||||
|
label: "Midgard6.Dialog.würfeln",
|
||||||
|
default: true,
|
||||||
|
callback: (event, button, dialog) => {
|
||||||
|
const rollData = {
|
||||||
|
customRoll: button.form.elements.customRoll.value,
|
||||||
|
vorteil: button.form.elements.vorteil.value
|
||||||
|
};
|
||||||
|
return rollData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
// submit: (rollData) => {
|
||||||
|
// if (noRoll) {
|
||||||
|
// resolve({ noRoll: true });
|
||||||
|
// } else {
|
||||||
|
// resolve(rollData);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------- */
|
/* -------------------------------------------------- */
|
||||||
/* Helper functions */
|
/* Helper functions */
|
||||||
/* -------------------------------------------------- */
|
/* -------------------------------------------------- */
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { CharacterData } from "./data/character-data.mjs";
|
import { CharacterData } from "./data/character-data.mjs";
|
||||||
import { ItemData } from "./data/item-data.mjs";
|
import { ItemData } from "./data/item-data.mjs";
|
||||||
import { M6ActorSheet } from "./sheets/character-sheet.mjs";
|
import { M6ActorSheet } from "./sheets/character-sheet.mjs";
|
||||||
|
import { loadHelpers } from "./helpers/handlebar-helpers.mjs";
|
||||||
|
|
||||||
Hooks.once("init", () => {
|
Hooks.once("init", () => {
|
||||||
CONFIG.Actor.dataModels.character = CharacterData;
|
CONFIG.Actor.dataModels.character = CharacterData;
|
||||||
@@ -20,6 +21,8 @@ Hooks.once("init", () => {
|
|||||||
types: ["character"],
|
types: ["character"],
|
||||||
makeDefault: true
|
makeDefault: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
loadHelpers();
|
||||||
// foundry.applications.apps.DocumentSheetConfig.registerSheet(Item, "midgard6-lvd", ItemSheet, {
|
// foundry.applications.apps.DocumentSheetConfig.registerSheet(Item, "midgard6-lvd", ItemSheet, {
|
||||||
// types: ["item"],
|
// types: ["item"],
|
||||||
// makeDefault: true
|
// makeDefault: true
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<section class="flexrow">
|
<section class="standard-form" style="margin-bottom: 1rem">
|
||||||
|
<div class="flexrow">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>LP</legend>
|
<legend>LP</legend>
|
||||||
<div class="flexrow">
|
<div class="flexrow">
|
||||||
@@ -36,30 +37,31 @@
|
|||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Reflexe</legend>
|
<legend>{{localize "Midgard6.Resistenzen.reflexe"}}</legend>
|
||||||
<input
|
<input
|
||||||
class="attribut"
|
class="attribut"
|
||||||
type="number"
|
type="number"
|
||||||
name="system.resources.leben.value"
|
name="system.resistenzen.reflexe"
|
||||||
value="{{system.resources.leben.value}}"
|
value="{{system.resistenzen.reflexe}}"
|
||||||
/>
|
/>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Willenskraft</legend>
|
<legend>{{localize "Midgard6.Resistenzen.willenskraft"}}</legend>
|
||||||
<input
|
<input
|
||||||
class="attribut"
|
class="attribut"
|
||||||
type="number"
|
type="number"
|
||||||
name="system.resources.leben.value"
|
name="system.resistenzen.willenskraft"
|
||||||
value="{{system.resources.leben.value}}"
|
value="{{system.resistenzen.reflexe}}"
|
||||||
/>
|
/>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Zähigkeit</legend>
|
<legend>{{localize "Midgard6.Resistenzen.zähigkeit"}}</legend>
|
||||||
<input
|
<input
|
||||||
class="attribut"
|
class="attribut"
|
||||||
type="number"
|
type="number"
|
||||||
name="system.resources.leben.value"
|
name="system.resistenzen.zähigkeit"
|
||||||
value="{{system.resources.leben.value}}"
|
value="{{system.resistenzen.zähigkeit}}"
|
||||||
/>
|
/>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<section class="standard-form" style="margin-bottom: 1rem">
|
||||||
|
<fieldset>
|
||||||
|
<legend>Modifikation</legend>
|
||||||
|
<div class="flexrow">
|
||||||
|
<i class="flex0 fa-solid fa-dice-d20"></i>
|
||||||
|
{{#ifeq vorteil 1}}
|
||||||
|
<i class="flex0 fa-solid fa-dice-d20"></i>
|
||||||
|
|
||||||
|
{{/ifeq}}
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
style="margin-left: 8px; max-width:10rem"
|
||||||
|
name="customRoll"
|
||||||
|
id="rollDisplay"
|
||||||
|
placeholder="1d20 + {{skill}}"
|
||||||
|
value="{{customRoll}}"
|
||||||
|
/>
|
||||||
|
<div class="flexrow" style="padding-left: 8px">
|
||||||
|
<i class="flex0 fa-solid fa-dice-d20" style="color:red"></i>
|
||||||
|
<input
|
||||||
|
class="flex1"
|
||||||
|
style="max-width:30px"
|
||||||
|
type="range"
|
||||||
|
id="vorteilSlider"
|
||||||
|
value="{{vorteil}}"
|
||||||
|
name="vorteil"
|
||||||
|
min="-1"
|
||||||
|
max="1"
|
||||||
|
/>
|
||||||
|
<i class="flex0 fa-solid fa-dice-d20" style="color:blue"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
</section>
|
||||||
Whitespace-only changes.
Reference in new issue
Block a user