Dialog chateau-dormant
Pour permettre de pré-remplir les infos de chateau dormant
This commit is contained in:
108
module/sommeil/dialog-chateau-dormant.js
Normal file
108
module/sommeil/dialog-chateau-dormant.js
Normal file
@ -0,0 +1,108 @@
|
||||
export class DialogChateauDormant extends Dialog {
|
||||
|
||||
static async create() {
|
||||
const date = game.system.rdd.calendrier.dateCourante();
|
||||
const actorsSettings = game.actors.filter(actor => actor.hasPlayerOwner && actor.isPersonnage())
|
||||
.map(actor => ({
|
||||
actor: actor,
|
||||
insomnie: actor.system.sommeil?.insomnie,
|
||||
moral: 'neutre'
|
||||
}));
|
||||
|
||||
const dialogData = {
|
||||
actorsSettings,
|
||||
date: date,
|
||||
motifStress: `Nuit du ${date}`,
|
||||
finChateauDormant: game.system.rdd.calendrier.getTimestampFinChateauDormant()
|
||||
};
|
||||
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/sommeil/dialog-chateau-dormant.hbs",
|
||||
dialogData);
|
||||
|
||||
new DialogChateauDormant(dialogData, html)
|
||||
.render(true);
|
||||
}
|
||||
|
||||
constructor(dialogData, html) {
|
||||
const options = {
|
||||
classes: ["rdd-dialog-chateau-dormant"],
|
||||
width: 600,
|
||||
height: 'fit-content',
|
||||
'z-index': 99999
|
||||
};
|
||||
const conf = {
|
||||
title: "De Chateau dormant à Vaisseau",
|
||||
content: html,
|
||||
buttons: {
|
||||
chateauDormant: { label: "Passer à Vaisseau!", callback: it => { this.onChateauDormant(); } }
|
||||
}
|
||||
};
|
||||
super(conf, options);
|
||||
this.dialogData = dialogData;
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
this.html = html;
|
||||
this.html.find('input.sommeil-insomnie').change(event => this.onInsomnie(event));
|
||||
this._activateListenerOnActorMoral(this.html);
|
||||
}
|
||||
|
||||
_activateListenerOnActorMoral(html) {
|
||||
html.find(`span.sommeil-actor-moral a`).click(event => this.onActorMoral(event));
|
||||
}
|
||||
|
||||
onInsomnie(event) {
|
||||
const sommeilInsomnie = this.html.find(event.currentTarget);
|
||||
const isInsomnie = sommeilInsomnie.is(':checked');
|
||||
const sommeilHeures = sommeilInsomnie.parents('.set-sommeil-actor').find('input.sommeil-heures');
|
||||
sommeilHeures.prop('disabled', isInsomnie);
|
||||
if (isInsomnie) {
|
||||
sommeilHeures.val('0');
|
||||
}
|
||||
}
|
||||
|
||||
async onActorMoral(event) {
|
||||
const selected = this.html.find(event.currentTarget);
|
||||
const actorRow = selected.parents('.set-sommeil-actor');
|
||||
const actorId = actorRow.data('actor-id');
|
||||
const actorSetting = this.getActorSetting(actorId);
|
||||
if (actorSetting) {
|
||||
actorSetting.moral = selected.data('moral');
|
||||
const htmlMoral = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/sommeil/sommeil-actor-moral.hbs', actorSetting)
|
||||
actorRow.find('.sommeil-actor-moral').html(htmlMoral);
|
||||
// re-attach listeners for actor row
|
||||
this._activateListenerOnActorMoral(actorRow);
|
||||
}
|
||||
}
|
||||
|
||||
getActorSetting(actorId) {
|
||||
return this.dialogData.actorsSettings.find(it => it.actor.id == actorId);
|
||||
}
|
||||
|
||||
async onChateauDormant() {
|
||||
const motifStress = this.html.find("form input[name='motifStress']").val();
|
||||
const sommeilActors = jQuery.map(this.html.find('li.set-sommeil-actor'), it => {
|
||||
const actorRow = this.html.find(it);
|
||||
const actorId = actorRow.data('actor-id');
|
||||
const actorSetting = this.getActorSetting(actorId);
|
||||
return {
|
||||
actorId,
|
||||
ignorer: actorRow.find('input.sommeil-ignorer').is(':checked'),
|
||||
stress: {
|
||||
motif: motifStress,
|
||||
valeur: Number.parseInt(actorRow.find('input.sommeil-stress').val()),
|
||||
},
|
||||
sommeil: {
|
||||
insomnie: actorRow.find('input.sommeil-insomnie').is(':checked'),
|
||||
heures: Number.parseInt(actorRow.find('input.sommeil-heures').val()),
|
||||
moral: actorSetting.moral,
|
||||
}
|
||||
}
|
||||
});
|
||||
await Promise.all(
|
||||
sommeilActors.filter(it => !it.ignorer)
|
||||
.map(async it => await game.actors.get(it.actorId)?.prepareChateauDormant(this.dialogData.finChateauDormant, it))
|
||||
)
|
||||
}
|
||||
|
||||
}
|
82
module/sommeil/dialog-repos.js
Normal file
82
module/sommeil/dialog-repos.js
Normal file
@ -0,0 +1,82 @@
|
||||
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));
|
||||
}
|
||||
}
|
63
module/sommeil/dialog-stress.js
Normal file
63
module/sommeil/dialog-stress.js
Normal file
@ -0,0 +1,63 @@
|
||||
|
||||
export class DialogStress extends Dialog {
|
||||
|
||||
static async distribuerStress() {
|
||||
const dialogData = {
|
||||
motif: "Motif",
|
||||
stress: 10,
|
||||
immediat: false,
|
||||
actors: game.actors.filter(actor => actor.hasPlayerOwner && actor.isPersonnage())
|
||||
.map(actor => ({
|
||||
id: actor.id,
|
||||
name: actor.name,
|
||||
selected: true
|
||||
})
|
||||
)
|
||||
};
|
||||
|
||||
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/sommeil/dialog-stress.html", dialogData);
|
||||
new DialogStress(dialogData, html)
|
||||
.render(true);
|
||||
}
|
||||
|
||||
constructor(dialogData, html) {
|
||||
const options = { classes: ["DialogStress"],
|
||||
width: 400,
|
||||
height: 'fit-content',
|
||||
'z-index': 99999
|
||||
};
|
||||
const conf = {
|
||||
title: "Donner du stress",
|
||||
content: html,
|
||||
buttons: {
|
||||
stress: { label: "Stress !", callback: it => { this.onStress(); } }
|
||||
}
|
||||
};
|
||||
super(conf, options);
|
||||
this.dialogData = dialogData;
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
this.html = html;
|
||||
this.html.find("input.select-actor").change((event) => this.onSelectActor(event));
|
||||
}
|
||||
|
||||
async onStress() {
|
||||
const motif = this.html.find("form.rdddialogstress input[name='motif']").val();
|
||||
const stress = Number(this.html.find("form.rdddialogstress input[name='stress']").val());
|
||||
const compteur = (this.html.find("form.rdddialogstress input[name='immediat']").prop("checked")) ? 'experience' : 'stress';
|
||||
|
||||
this.dialogData.actors.filter(it => it.selected)
|
||||
.map(it => game.actors.get(it.id))
|
||||
.forEach(async actor => await actor.distribuerStress(compteur, stress, motif));
|
||||
}
|
||||
|
||||
async onSelectActor(event) {
|
||||
const actorId = this.html.find(event.currentTarget)?.data("actor-id");
|
||||
const actor = this.dialogData.actors.find(it => it.id == actorId);
|
||||
if (actor) {
|
||||
actor.selected = event.currentTarget.checked;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user