Begin work on the custom editor for dice
This commit is contained in:
parent
36e3a551b8
commit
0deda3235a
6 changed files with 145 additions and 4 deletions
44
module/dialogs/DiceList.mjs
Normal file
44
module/dialogs/DiceList.mjs
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
import { GenericDialog } from "./GenericDialog.mjs";
|
||||||
|
|
||||||
|
export class DiceList extends GenericDialog {
|
||||||
|
constructor(mobActor) {
|
||||||
|
super({}, { title: `${mobActor.name}'s Dice List` });
|
||||||
|
this.actor = mobActor;
|
||||||
|
this.dice = this.actor.system.dice.map((d) => ({
|
||||||
|
...d,
|
||||||
|
id: randomID(),
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
static get defaultOptions() {
|
||||||
|
const opts = mergeObject({
|
||||||
|
...super.defaultOptions,
|
||||||
|
template: `systems/dotdungeon/templates/dialogs/diceList.hbs`,
|
||||||
|
width: 400,
|
||||||
|
height: 400,
|
||||||
|
submitOnClose: true,
|
||||||
|
});
|
||||||
|
opts.classes.push(`dotdungeon`);
|
||||||
|
return opts;
|
||||||
|
};
|
||||||
|
|
||||||
|
async getData() {
|
||||||
|
const ctx = await super.getData();
|
||||||
|
ctx.dice = this.dice;
|
||||||
|
return ctx;
|
||||||
|
};
|
||||||
|
|
||||||
|
async _updateObject(event, formData) {
|
||||||
|
console.log(event, formData);
|
||||||
|
};
|
||||||
|
|
||||||
|
addDie() {
|
||||||
|
this.dice.push({
|
||||||
|
count: 1,
|
||||||
|
sides: 2,
|
||||||
|
repeat: 1,
|
||||||
|
id: randomID(),
|
||||||
|
});
|
||||||
|
this.render();
|
||||||
|
};
|
||||||
|
};
|
||||||
45
module/dialogs/GenericDialog.mjs
Normal file
45
module/dialogs/GenericDialog.mjs
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
import DOTDUNGEON from "../config.mjs";
|
||||||
|
|
||||||
|
export class GenericDialog extends FormApplication {
|
||||||
|
|
||||||
|
#propogatedSettings = [
|
||||||
|
`devMode`,
|
||||||
|
];
|
||||||
|
|
||||||
|
async getData() {
|
||||||
|
const ctx = {};
|
||||||
|
|
||||||
|
// Send all of the settings that sheets need into their context
|
||||||
|
ctx.settings = {};
|
||||||
|
for (const setting of this.#propogatedSettings) {
|
||||||
|
ctx.settings[setting] = game.settings.get(`dotdungeon`, setting);
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.isGM = game.users.current.hasRole(CONST.USER_ROLES.ASSISTANT);
|
||||||
|
|
||||||
|
ctx.meta = {
|
||||||
|
expanded: this._expanded,
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.config = DOTDUNGEON;
|
||||||
|
ctx.icons = CONFIG.CACHE.icons;
|
||||||
|
|
||||||
|
return ctx;
|
||||||
|
};
|
||||||
|
|
||||||
|
activateListeners(html) {
|
||||||
|
super.activateListeners(html);
|
||||||
|
|
||||||
|
if (!this.isEditable) return;
|
||||||
|
console.debug(`.dungeon | Generic dialog adding listeners`);
|
||||||
|
|
||||||
|
html.find(`[data-action]`)
|
||||||
|
.on(`click`, this._handleActionClick.bind(this));
|
||||||
|
};
|
||||||
|
|
||||||
|
_handleActionClick($e) {
|
||||||
|
const data = $e.currentTarget.dataset;
|
||||||
|
if (!this[data.action]) return;
|
||||||
|
this[data.action].bind(this)($e);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
@ -2,10 +2,6 @@ export class MobData extends foundry.abstract.TypeDataModel {
|
||||||
static defineSchema() {
|
static defineSchema() {
|
||||||
const fields = foundry.data.fields;
|
const fields = foundry.data.fields;
|
||||||
return {
|
return {
|
||||||
dice: new fields.StringField({
|
|
||||||
initial: ``,
|
|
||||||
blank: true,
|
|
||||||
}),
|
|
||||||
bonus: new fields.NumberField({
|
bonus: new fields.NumberField({
|
||||||
initial: 0,
|
initial: 0,
|
||||||
nullable: false,
|
nullable: false,
|
||||||
|
|
@ -42,6 +38,15 @@ export class MobData extends foundry.abstract.TypeDataModel {
|
||||||
initial: ``,
|
initial: ``,
|
||||||
blank: true,
|
blank: true,
|
||||||
}),
|
}),
|
||||||
|
dice: new fields.ArrayField(
|
||||||
|
new fields.SchemaField({
|
||||||
|
// {count}d{sides} x {repeat}
|
||||||
|
count: new fields.NumberField({ min: 1 }),
|
||||||
|
sides: new fields.NumberField({ min: 2 }),
|
||||||
|
repeat: new fields.NumberField({ min: 1 }),
|
||||||
|
}),
|
||||||
|
{ initial: [] }
|
||||||
|
),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { ActorHandler } from "../documents/Actor/Handler.mjs";
|
import { ActorHandler } from "../documents/Actor/Handler.mjs";
|
||||||
import { GenericActorSheet } from "./GenericActorSheet.mjs";
|
import { GenericActorSheet } from "./GenericActorSheet.mjs";
|
||||||
|
import { DiceList } from "../dialogs/DiceList.mjs";
|
||||||
|
|
||||||
export class MobSheet extends GenericActorSheet {
|
export class MobSheet extends GenericActorSheet {
|
||||||
static get defaultOptions() {
|
static get defaultOptions() {
|
||||||
|
|
@ -21,6 +22,12 @@ export class MobSheet extends GenericActorSheet {
|
||||||
if (this.document.isEmbedded) return;
|
if (this.document.isEmbedded) return;
|
||||||
if (!this.isEditable) return;
|
if (!this.isEditable) return;
|
||||||
console.debug(`.dungeon | Adding event listeners for Mob: ${this.id}`);
|
console.debug(`.dungeon | Adding event listeners for Mob: ${this.id}`);
|
||||||
|
|
||||||
|
html.find(`.edit-dice`)
|
||||||
|
.on(`click`, async () => {
|
||||||
|
let d = new DiceList(this.actor);
|
||||||
|
d.render(true);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
async getData() {
|
async getData() {
|
||||||
|
|
|
||||||
3
styles/dialog/DiceList.scss
Normal file
3
styles/dialog/DiceList.scss
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
.dotdungeon.dialog--dice-list {
|
||||||
|
padding: 4px;
|
||||||
|
}
|
||||||
37
templates/dialogs/diceList.hbs
Normal file
37
templates/dialogs/diceList.hbs
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<form class="dialog--dice-list">
|
||||||
|
{{#each dice as | die |}}
|
||||||
|
<div class="die" data-die-id="{{die.id}}">
|
||||||
|
{{dd-stringify die}}
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
name="die.count"
|
||||||
|
>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
name="die.sides"
|
||||||
|
>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
name="die.repeat"
|
||||||
|
>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{{/each}}
|
||||||
|
<button type="button" data-action="addDie">
|
||||||
|
Add Die
|
||||||
|
</button>
|
||||||
|
{{#if settings.devMode}}
|
||||||
|
<div class="debug-data">
|
||||||
|
Dice:
|
||||||
|
{{dd-stringify dice}}
|
||||||
|
<hr>
|
||||||
|
Settings:
|
||||||
|
{{dd-stringify settings}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
</form>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue