2023-02-10 02:01:43 +01:00
|
|
|
|
2023-02-07 18:06:45 +01:00
|
|
|
export class DialogChateauDormant extends Dialog {
|
|
|
|
|
|
|
|
static async create() {
|
|
|
|
const date = game.system.rdd.calendrier.dateCourante();
|
2023-02-10 02:01:43 +01:00
|
|
|
const actors = game.actors.filter(actor => actor.hasPlayerOwner && actor.isPersonnage());
|
2023-02-07 18:06:45 +01:00
|
|
|
|
|
|
|
const dialogData = {
|
2023-02-10 02:01:43 +01:00
|
|
|
actors: actors,
|
2023-02-07 18:06:45 +01:00
|
|
|
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');
|
2023-02-10 02:01:43 +01:00
|
|
|
const actor = this.getActor(actorId);
|
|
|
|
actor.system.sommeil.moral = selected.data('moral');
|
|
|
|
const htmlMoral = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/sommeil/sommeil-actor-moral.hbs', actor.system.sommeil)
|
|
|
|
actorRow.find('.sommeil-actor-moral').html(htmlMoral);
|
|
|
|
// re-attach listeners for actor row
|
|
|
|
this._activateListenerOnActorMoral(actorRow);
|
2023-02-07 18:06:45 +01:00
|
|
|
}
|
|
|
|
|
2023-02-10 02:01:43 +01:00
|
|
|
getActor(actorId) {
|
|
|
|
return this.dialogData.actors.find(it => it.id == actorId);
|
2023-02-07 18:06:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async onChateauDormant() {
|
|
|
|
const motifStress = this.html.find("form input[name='motifStress']").val();
|
2023-02-17 01:29:21 +01:00
|
|
|
jQuery.map(
|
|
|
|
this.html.find('li.set-sommeil-actor'),
|
|
|
|
it => this.extractConsigneActor(this.html.find(it), motifStress)
|
|
|
|
).forEach(async consigne => await consigne.actor.prepareChateauDormant(consigne))
|
2023-02-07 18:06:45 +01:00
|
|
|
}
|
|
|
|
|
2023-02-17 01:29:21 +01:00
|
|
|
|
|
|
|
extractConsigneActor(actorRow, motifStress) {
|
|
|
|
const actorId = actorRow.data('actor-id');
|
|
|
|
const actor = this.getActor(actorId);
|
|
|
|
const insomnie = actorRow.find('input.sommeil-insomnie').is(':checked');
|
|
|
|
return {
|
|
|
|
actor,
|
|
|
|
ignorer: actorRow.find('input.sommeil-ignorer').is(':checked'),
|
|
|
|
stress: {
|
|
|
|
motif: motifStress,
|
|
|
|
valeur: Number.parseInt(actorRow.find('input.sommeil-stress').val()),
|
|
|
|
},
|
|
|
|
sommeil: {
|
|
|
|
nouveaujour: true,
|
|
|
|
date: this.dialogData.finChateauDormant,
|
|
|
|
insomnie: insomnie,
|
|
|
|
heures: insomnie ? 0 : Number.parseInt(actorRow.find('input.sommeil-heures').val()),
|
|
|
|
moral: actor.system.sommeil.moral ?? 'neutre',
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2023-02-07 18:06:45 +01:00
|
|
|
}
|