foundryvtt-reve-de-dragon/module/sommeil/dialog-repos.js

83 lines
2.8 KiB
JavaScript
Raw Normal View History

import { ReglesOptionelles } from "../settings/regles-optionelles.js";
export class DialogRepos extends Dialog {
static async create(actor) {
if (!ReglesOptionelles.isUsing("chateau-dormant-gardien")) {
actor.system.sommeil = {
"nouveaujour": true,
"insomnie": false,
"moral": "neutre",
"heures": 4
}
}
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/sommeil/dialog-repos.html", actor);
const dialog = new DialogRepos(html, actor);
dialog.render(true);
}
constructor(html, actor) {
let options = { classes: ["DialogCreateSigneDraconiqueActorsActors"], width: 400, height: 'fit-content', 'z-index': 99999 };
let conf = {
title: "Se reposer",
content: html,
default: "repos",
buttons: {
"repos": { label: "Se reposer", callback: async it => { this.repos(); } }
}
};
super(conf, options);
this.actor = actor;
}
activateListeners(html) {
super.activateListeners(html);
this.html = html;
this.html.find(`.sommeil-actor-moral a`).click(event => this.onActorMoral(event));
}
/* -------------------------------------------- */
async repos() {
const selection = await this.html.find("[name='repos']:checked").val();
switch (selection) {
case "sieste": return await this.sieste();
case "nuit": return await this.nuit();
case "chateau-dormant": return await this.chateauDormant();
case "gris-reve": return await this.grisReve();
}
}
async grisReve() {
await this.html.find("[name='nb-jours']").change();
const nbJours = Number.parseInt(await this.html.find("[name='nb-jours']").val());
await this.actor.grisReve(nbJours);
}
async chateauDormant() {
await this.actor.dormirChateauDormant();
}
async nuit() {
await this.html.find("[name='sommeil.heures']").change();
const sommeilHeures = Number.parseInt(await this.html.find("[name='sommeil.heures']").val());
await this.actor.dormir(sommeilHeures, { chateauDormant: true });
}
async sieste() {
await this.html.find("[name='sieste.heures']").change();
const siesteHeures = Number.parseInt(await this.html.find("[name='sieste.heures']").val());
await this.actor.dormir(siesteHeures);
}
async onActorMoral(event) {
const selected = this.html.find(event.currentTarget);
const parentDiv = selected.parents().find('.sommeil-actor-moral');
const situationMoral = selected.data('moral');
await this.actor.update({"system.sommeil.moral": situationMoral});
const htmlMoral = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/sommeil/sommeil-actor-moral.hbs', {
moral: situationMoral
});
parentDiv.html(htmlMoral);
this.html.find(`.sommeil-actor-moral a`).click(event => this.onActorMoral(event));
}
}