Calendrier/timestamp, suite

Correction autour des éditeurs/affichages
Migration de la date du monde dans les settings
This commit is contained in:
2023-01-07 20:06:04 +01:00
parent 19b3adc222
commit 739fcbdf09
13 changed files with 136 additions and 182 deletions

View File

@ -6,15 +6,7 @@ import { RdDDice } from "./rdd-dice.js";
import { Misc } from "./misc.js";
import { HIDE_DICE, SHOW_DICE, SYSTEM_RDD, SYSTEM_SOCKET_ID } from "./constants.js";
import { DialogChronologie } from "./dialog-chronologie.js";
import { RdDTimestamp } from "./rdd-timestamp.js";
/* -------------------------------------------- */
const saisonsDef = {
"printemps": { label: "Printemps" },
"ete": { label: "Eté" },
"automne": { label: "Automne" },
"hiver": { label: "Hiver" }
};
import { RdDTimestamp, WORLD_TIMESTAMP_SETTING } from "./rdd-timestamp.js";
const RDD_JOUR_PAR_MOIS = 28;
const RDD_HEURES_PAR_JOUR = 12;
@ -45,7 +37,7 @@ export class RdDCalendrier extends Application {
game.settings.set(SYSTEM_RDD, "calendrier-pos", this.calendrierPos);
}
// Calendrier
this.timestamp = new RdDTimestamp({});
this.timestamp = RdDTimestamp.getWorldTime();
if (Misc.isUniqueConnectedGM()) { // Uniquement si GM
RdDTimestamp.setWorldTime(this.timestamp);
@ -53,10 +45,14 @@ export class RdDCalendrier extends Application {
this.rebuildListeNombreAstral(HIDE_DICE); // Ensure always up-to-date
}
console.log('RdDCalendrier.constructor()', this.timestamp, this.timestamp.toOldCalendrier(), this.calendrierPos, this.listeNombreAstral);
Hooks.on('updateSetting', async (setting, update, options, id) => this.onUpdateSetting(setting, update, options, id));
}
getCalendrier() {
return this.timestamp.toOldCalendrier();
async onUpdateSetting(setting, update, options, id) {
if (setting.key == SYSTEM_RDD + '.' + WORLD_TIMESTAMP_SETTING) {
this.timestamp = RdDTimestamp.getWorldTime();
this.updateDisplay();
}
}
/* -------------------------------------------- */
@ -162,6 +158,7 @@ export class RdDCalendrier extends Application {
}
isAfterIndexDate(indexDate) {
// TODO: standardize
return indexDate < this.timestamp.indexDate;
}
@ -339,12 +336,6 @@ export class RdDCalendrier extends Application {
await this.setNewTimestamp(this.timestamp.nouveauJour());
}
/* -------------------------------------------- */
syncPlayerTime(timestamp) {
this.timestamp = new RdDTimestamp(timestamp);
this.updateDisplay();
}
/* -------------------------------------------- */
async positionnerHeure(indexHeure) {
await this.setNewTimestamp(new RdDTimestamp({ indexDate: this.timestamp.indexDate + (this.timestamp.heure < indexHeure ? 0 : 1) }).addHeures(indexHeure))
@ -355,21 +346,23 @@ export class RdDCalendrier extends Application {
const mois = RdDTimestamp.definition(this.timestamp.mois);
const heure = RdDTimestamp.definition(this.timestamp.heure);
formData.timestamp = this.timestamp;
formData.annee = this.timestamp.annee;
formData.mois = mois;
formData.jourDuMois = this.timestamp.jour + 1;
formData.jour = this.timestamp.jour;
formData.heure = heure;
formData.minute = this.timestamp.minute;
formData.moisKey = mois.key;
formData.nomMois = mois.label; // heures et mois nommés identiques
formData.iconMois = mois.icon;
formData.nomSaison = saisonsDef[mois.saison].label;
// formData.nomMois = mois.label; // heures et mois nommés identiques
// formData.iconMois = mois.icon;
formData.jourMois = this.timestamp.jour + 1;
// formData.heureKey = heure.key;
// formData.heureRdD = formData.heure.heure;
// formData.nomHeure = heure.label;
// formData.iconHeure = heure.icon;
formData.heureKey = heure.key;
formData.heureRdD = this.timestamp.heure;
formData.nomHeure = heure.label;
formData.iconHeure = heure.icon;
formData.minutesRelative = this.timestamp.minute;
// formData.minutes = this.timestamp.minute;
formData.isGM = game.user.isGM;
@ -509,21 +502,21 @@ export class RdDCalendrier extends Application {
updateDisplay() {
let calendrier = this.fillCalendrierData();
// Rebuild text du calendrier
let dateHTML = `${calendrier.jourMois} ${calendrier.nomMois} ${calendrier.annee} (${calendrier.nomSaison})`
let dateHTML = `${calendrier.jourDuMois} ${calendrier.mois.label} ${calendrier.annee} (${calendrier.mois.saison})`
if (game.user.isGM) {
dateHTML = dateHTML + " - NA: " + (this.getCurrentNombreAstral() ?? "indéterminé");
dateHTML = dateHTML + " - NA: " + (this.getCurrentNombreAstral() ?? "?");
}
for (let handle of document.getElementsByClassName("calendar-date-rdd")) {
handle.innerHTML = dateHTML;
}
for (let heure of document.getElementsByClassName("calendar-heure-texte")) {
heure.innerHTML = calendrier.nomHeure;
heure.innerHTML = calendrier.heure.label;
}
for (const minute of document.getElementsByClassName("calendar-time-disp")) {
minute.innerHTML = `${calendrier.minutesRelative} minutes`;
minute.innerHTML = `${calendrier.minute} minutes`;
}
for (const heureImg of document.getElementsByClassName("calendar-heure-img")) {
heureImg.src = calendrier.iconHeure;
heureImg.src = calendrier.heure.icon;
}
}
@ -531,10 +524,10 @@ export class RdDCalendrier extends Application {
async saveEditeur(calendrierData) {
const newTimestamp = RdDTimestamp.timestamp(
Number.parseInt(calendrierData.annee),
RdDTimestamp.definition(calendrierData.moisKey).heure,
calendrierData.mois.heure,
Number.parseInt(calendrierData.jourMois),
RdDTimestamp.definition(calendrierData.heureKey).heure,
Number.parseInt(calendrierData.minutesRelative)
calendrierData.heure.heure,
Number.parseInt(calendrierData.minutes)
);
await this.setNewTimestamp(newTimestamp);
}