Gestion d'items temporels
- Séparation des timestamp / calendrier Les poisons/maladies/souffles/queues/rencontres/signes peuvent être temporaires. - Ajout de champs pour stocker les timestamps de début et fin - définition de la durée (selon les items) - extraction des classes spécialisées des items - initialisation des dates de début/fin des effets temporaires à l'ajout d'un item temporel - préparation de la suppression automatique - Fix de mauvaise présentations sur les dialog d'astrologie et d'édition du calendrier
This commit is contained in:
@ -1,32 +1,14 @@
|
||||
/* -------------------------------------------- */
|
||||
import { RdDCalendrierEditeur } from "./rdd-calendrier-editeur.js";
|
||||
import { RdDAstrologieEditeur } from "./rdd-astrologie-editeur.js";
|
||||
import { HtmlUtility } from "./html-utility.js";
|
||||
import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
||||
import { RdDUtility } from "./rdd-utility.js";
|
||||
import { Grammar } from "./grammar.js";
|
||||
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 dossierIconesHeures = 'systems/foundryvtt-reve-de-dragon/icons/heures/'
|
||||
const heuresList = ["vaisseau", "sirene", "faucon", "couronne", "dragon", "epees", "lyre", "serpent", "poissonacrobate", "araignee", "roseau", "chateaudormant"];
|
||||
const heuresDef = {
|
||||
"vaisseau": { key: "vaisseau", label: "Vaisseau", lettreFont: 'v', saison: "printemps", heure: 0, icon: 'hd01.svg' },
|
||||
"sirene": { key: "sirene", label: "Sirène", lettreFont: 'i', saison: "printemps", heure: 1, icon: 'hd02.svg' },
|
||||
"faucon": { key: "faucon", label: "Faucon", lettreFont: 'f', saison: "printemps", heure: 2, icon: 'hd03.svg' },
|
||||
"couronne": { key: "couronne", label: "Couronne", lettreFont: '', saison: "ete", heure: 3, icon: 'hd04.svg' },
|
||||
"dragon": { key: "dragon", label: "Dragon", lettreFont: 'd', saison: "ete", heure: 4, icon: 'hd05.svg' },
|
||||
"epees": { key: "epees", label: "Epées", lettreFont: 'e', saison: "ete", heure: 5, icon: 'hd06.svg' },
|
||||
"lyre": { key: "lyre", label: "Lyre", lettreFont: 'l', saison: "automne", heure: 6, icon: 'hd07.svg' },
|
||||
"serpent": { key: "serpent", label: "Serpent", lettreFont: 's', saison: "automne", heure: 7, icon: 'hd08.svg' },
|
||||
"poissonacrobate": { key: "poissonacrobate", label: "Poisson Acrobate", lettreFont: 'p', saison: "automne", heure: 8, icon: 'hd09.svg' },
|
||||
"araignee": { key: "araignee", label: "Araignée", lettreFont: 'a', saison: "hiver", heure: 9, icon: 'hd10.svg' },
|
||||
"roseau": { key: "roseau", label: "Roseau", lettreFont: 'r', saison: "hiver", heure: 10, icon: 'hd11.svg' },
|
||||
"chateaudormant": { key: "chateaudormant", label: "Château Dormant", lettreFont: 'c', saison: "hiver", heure: 11, icon: 'hd12.svg' }
|
||||
};
|
||||
const saisonsDef = {
|
||||
"printemps": { label: "Printemps" },
|
||||
"ete": { label: "Eté" },
|
||||
@ -34,11 +16,10 @@ const saisonsDef = {
|
||||
"hiver": { label: "Hiver" }
|
||||
};
|
||||
|
||||
const RDD_MOIS_PAR_AN = 12;
|
||||
export const RDD_JOUR_PAR_MOIS = 28;
|
||||
const RDD_JOUR_PAR_MOIS = 28;
|
||||
const RDD_HEURES_PAR_JOUR = 12;
|
||||
const RDD_MINUTES_PAR_HEURES = 120;
|
||||
const MAX_NOMBRE_ASTRAL = 12;
|
||||
const JOURS_DU_MOIS = Array(RDD_JOUR_PAR_MOIS).fill().map((item, index) => 1 + index);
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class RdDCalendrier extends Application {
|
||||
@ -55,57 +36,6 @@ export class RdDCalendrier extends Application {
|
||||
return { top: 200, left: 200 };
|
||||
}
|
||||
|
||||
static getDefSigne(chiffre) {
|
||||
chiffre = chiffre % RDD_MOIS_PAR_AN;
|
||||
return Object.values(heuresDef).find(h => h.heure == chiffre);
|
||||
}
|
||||
|
||||
static getSigneAs(key, value) {
|
||||
const heure = (typeof value == 'string' || typeof value == 'number') && Number.isInteger(Number(value))
|
||||
? Number(value)
|
||||
: (typeof value == 'string') ? RdDCalendrier.getChiffreFromSigne(value)
|
||||
: undefined
|
||||
|
||||
if (heure != undefined && ['key', 'label', 'lettreFont', 'saison', 'heure', 'icon'].includes(key)) {
|
||||
return RdDCalendrier.getDefSigne(heure)[key]
|
||||
}
|
||||
if (heure != undefined && ['webp'].includes(key)) {
|
||||
return RdDCalendrier.getDefSigne(heure)['icon'].replace('svg', 'webp');
|
||||
}
|
||||
console.error(`Appel à getSigneAs('${key}', ${value}) avec une clé/heure incorrects`);
|
||||
return value;
|
||||
|
||||
}
|
||||
static getChiffreFromSigne(signe) {
|
||||
return heuresList.indexOf(signe);
|
||||
}
|
||||
|
||||
static createCalendrierInitial() {
|
||||
return {
|
||||
heureRdD: 0,
|
||||
minutesRelative: 0,
|
||||
indexJour: 0,
|
||||
annee: 0,
|
||||
moisRdD: 0,
|
||||
moisLabel: heuresDef["vaisseau"].label,
|
||||
jour: 0
|
||||
}
|
||||
}
|
||||
|
||||
getCalendrier(index) {
|
||||
index = index ?? this.getCurrentDayIndex();
|
||||
const mois = Math.floor(index / RDD_JOUR_PAR_MOIS) % RDD_MOIS_PAR_AN;
|
||||
return {
|
||||
heureRdD: 0, // Index dans heuresList / heuresDef[x].heure
|
||||
minutesRelative: 0,
|
||||
indexJour: index,
|
||||
annee: Math.floor(index / (RDD_JOUR_PAR_MOIS * RDD_MOIS_PAR_AN)),
|
||||
moisRdD: RdDCalendrier.getDefSigne(mois).heure,
|
||||
moisLabel: RdDCalendrier.getDefSigne(mois).label,
|
||||
jour: (index % RDD_JOUR_PAR_MOIS) // Le calendrier stocke le jour en 0-27, mais en 1-28 à l'affichage
|
||||
}
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
// position
|
||||
@ -114,19 +44,19 @@ export class RdDCalendrier extends Application {
|
||||
this.calendrierPos = RdDCalendrier.createCalendrierPos();
|
||||
game.settings.set(SYSTEM_RDD, "calendrier-pos", this.calendrierPos);
|
||||
}
|
||||
|
||||
// Calendrier
|
||||
this.calendrier = duplicate(game.settings.get(SYSTEM_RDD, "calendrier") ?? RdDCalendrier.createCalendrierInitial());
|
||||
this.calendrier.annee = this.calendrier.annee ?? Math.floor((this.calendrier.moisRdD ?? 0) / RDD_MOIS_PAR_AN);
|
||||
this.calendrier.moisRdD = (this.calendrier.moisRdD ?? 0) % RDD_MOIS_PAR_AN;
|
||||
this.timestamp = new RdDTimestamp({});
|
||||
|
||||
if (Misc.isUniqueConnectedGM()) { // Uniquement si GM
|
||||
game.settings.set(SYSTEM_RDD, "calendrier", this.calendrier);
|
||||
|
||||
RdDTimestamp.setWorldTime(this.timestamp);
|
||||
this.listeNombreAstral = this.getListeNombreAstral();
|
||||
this.rebuildListeNombreAstral(HIDE_DICE); // Ensure always up-to-date
|
||||
}
|
||||
console.log('RdDCalendrier.constructor()', this.calendrier, this.calendrierPos, this.listeNombreAstral);
|
||||
console.log('RdDCalendrier.constructor()', this.timestamp, this.timestamp.toOldCalendrier(), this.calendrierPos, this.listeNombreAstral);
|
||||
}
|
||||
|
||||
getCalendrier() {
|
||||
return this.timestamp.toOldCalendrier();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -227,48 +157,49 @@ export class RdDCalendrier extends Application {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getDateFromIndex(index) {
|
||||
const dateRdD = this.getCalendrier(index);
|
||||
return (dateRdD.jour + 1) + ' ' + dateRdD.moisLabel;
|
||||
dateCourante() {
|
||||
return this.timestamp.formatDate();
|
||||
}
|
||||
|
||||
isAfterIndexDate(indexDate) {
|
||||
return indexDate < this.timestamp.indexDate;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getDayMonthFromIndex(index = undefined) {
|
||||
const dateRdD = this.getCalendrier(index);
|
||||
return {
|
||||
day: dateRdD.jour + 1,
|
||||
month: heuresList[dateRdD.moisRdD]
|
||||
}
|
||||
}
|
||||
heureCourante() { return RdDTimestamp.definition(this.timestamp.heure); }
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getCurrentHeure() {
|
||||
return heuresList[this.calendrier.heureRdD];
|
||||
getCurrentMinute() { return this.timestamp.indexMinute; }
|
||||
|
||||
getTimestampFinChateauDormant(nbJours = 0) {
|
||||
return this.timestamp.nouveauJour().addJour(nbJours);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getCurrentDayIndex() {
|
||||
return (((this.calendrier.annee ?? 0) * RDD_MOIS_PAR_AN + (this.calendrier.moisRdD ?? 0)) * RDD_JOUR_PAR_MOIS) + (this.calendrier.jour ?? 0);
|
||||
getTimestampFinHeure(nbHeures = 0) {
|
||||
return this.timestamp.nouvelleHeure().addHeures(nbHeures);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getIndexFromDate(jour, mois) {
|
||||
return (heuresDef[mois].heure * RDD_JOUR_PAR_MOIS) + jour - 1;
|
||||
const addYear = mois < this.timestamp.mois || (mois == this.timestamp.mois && jour < this.timestamp.jour)
|
||||
const time = RdDTimestamp.timestamp(this.timestamp.annee + (addYear ? 1 : 0), mois, jour);
|
||||
return time.indexDate;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getJoursSuivants(num) {
|
||||
getJoursSuivants(count) {
|
||||
let jours = [];
|
||||
let index = this.getCurrentDayIndex();
|
||||
for (let i = 0; i < num; i++) {
|
||||
jours[i] = { label: this.getDateFromIndex(index + i), index: index + i };
|
||||
let indexDate = this.timestamp.indexDate;
|
||||
for (let i = 0; i < count; i++, indexDate++) {
|
||||
jours[i] = { label: RdDTimestamp.formatIndexDate(indexDate), index: indexDate };
|
||||
}
|
||||
return jours;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async ajouterNombreAstral(index, showDice = SHOW_DICE) {
|
||||
async ajouterNombreAstral(indexDate, showDice = SHOW_DICE) {
|
||||
const nombreAstral = await RdDDice.rollTotal("1dh", { showDice: showDice, rollMode: "selfroll" });
|
||||
const dateFuture = this.getDateFromIndex(index);
|
||||
const dateFuture = RdDTimestamp.formatIndexDate(indexDate);
|
||||
if (showDice != HIDE_DICE) {
|
||||
ChatMessage.create({
|
||||
whisper: ChatMessage.getWhisperRecipients("GM"),
|
||||
@ -278,14 +209,13 @@ export class RdDCalendrier extends Application {
|
||||
return {
|
||||
nombreAstral: nombreAstral,
|
||||
valeursFausses: [],
|
||||
index: index
|
||||
index: indexDate
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getCurrentNombreAstral() {
|
||||
let indexDate = this.getCurrentDayIndex();
|
||||
return this.getNombreAstral(indexDate);
|
||||
return this.getNombreAstral(this.timestamp.indexDate);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -309,10 +239,9 @@ export class RdDCalendrier extends Application {
|
||||
/* -------------------------------------------- */
|
||||
async rebuildListeNombreAstral(showDice = HIDE_DICE) {
|
||||
if (Misc.isUniqueConnectedGM()) {
|
||||
let jourCourant = this.getCurrentDayIndex();
|
||||
let newList = [];
|
||||
for (let i = 0; i < MAX_NOMBRE_ASTRAL; i++) {
|
||||
let dayIndex = jourCourant + i;
|
||||
let dayIndex = this.timestamp.indexDate + i;
|
||||
let na = this.listeNombreAstral.find(n => n.index == dayIndex);
|
||||
if (na) {
|
||||
newList[i] = na;
|
||||
@ -320,25 +249,31 @@ export class RdDCalendrier extends Application {
|
||||
newList[i] = await this.ajouterNombreAstral(dayIndex, showDice);
|
||||
}
|
||||
}
|
||||
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", newList);
|
||||
this.listeNombreAstral = newList;
|
||||
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", newList);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async onCalendarButton(ev) {
|
||||
ev.preventDefault();
|
||||
const calendarAvance = ev.currentTarget.attributes['data-calendar-avance'];
|
||||
const calendarSet = ev.currentTarget.attributes['data-calendar-set'];
|
||||
if (calendarAvance) {
|
||||
await this.incrementTime(Number(calendarAvance.value));
|
||||
async setNewTimestamp(newTimestamp) {
|
||||
this.checkMaladiePoison(this.timestamp, newTimestamp);
|
||||
|
||||
this.checkMaladie("round");
|
||||
this.checkMaladie("minute");
|
||||
if (this.timestamp.heure != newTimestamp.heure || this.timestamp.indexDate != newTimestamp.indexDate) {
|
||||
this.checkMaladie("heure");
|
||||
}
|
||||
else if (calendarSet) {
|
||||
this.positionnerHeure(Number(calendarSet.value));
|
||||
if (this.timestamp.indexDate != newTimestamp.indexDate) {
|
||||
this.checkMaladie("jour");
|
||||
}
|
||||
|
||||
RdDTimestamp.setWorldTime(newTimestamp);
|
||||
this.timestamp = newTimestamp;
|
||||
await this.rebuildListeNombreAstral();
|
||||
this.updateDisplay();
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
checkMaladie(periode) {
|
||||
for (let actor of game.actors) {
|
||||
@ -357,77 +292,94 @@ export class RdDCalendrier extends Application {
|
||||
}
|
||||
}
|
||||
|
||||
checkMaladiePoison(oldTimestamp, newTimestamp) {
|
||||
// TODO
|
||||
const isInPeriod = maladie => {
|
||||
//TODO: utiliser les timestamp
|
||||
return false;
|
||||
}
|
||||
|
||||
game.actors.filter(it => it.type == 'personnage')
|
||||
.forEach(actor => {
|
||||
actor.items.filter(it => it.type == 'maladie' || (it.type == 'poison' && it.system.active))
|
||||
.filter(m => isInPeriod(m))
|
||||
.forEach(m => {
|
||||
if (m.system.identifie) {
|
||||
ChatMessage.create({ content: `${actor.name} souffre de ${m.name} (${m.type}): vérifiez que les effets ne se sont pas aggravés !` });
|
||||
} else {
|
||||
ChatMessage.create({ content: `${actor.name} souffre d'un mal inconnu (${m.type}): vérifiez que les effets ne se sont pas aggravés !` });
|
||||
}
|
||||
let itemMaladie = actor.getItem(m.id)
|
||||
itemMaladie.postItemToChat('gmroll');
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async onCalendarButton(ev) {
|
||||
ev.preventDefault();
|
||||
const calendarAvance = ev.currentTarget.attributes['data-calendar-avance'];
|
||||
const calendarSet = ev.currentTarget.attributes['data-calendar-set'];
|
||||
if (calendarAvance) {
|
||||
await this.incrementTime(Number(calendarAvance.value));
|
||||
}
|
||||
else if (calendarSet) {
|
||||
this.positionnerHeure(Number(calendarSet.value));
|
||||
}
|
||||
this.updateDisplay();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async incrementTime(minutes = 0) {
|
||||
this.calendrier.minutesRelative += minutes;
|
||||
this.checkMaladie("round");
|
||||
this.checkMaladie("minute");
|
||||
if (this.calendrier.minutesRelative >= RDD_MINUTES_PAR_HEURES) {
|
||||
this.calendrier.minutesRelative -= RDD_MINUTES_PAR_HEURES;
|
||||
this.calendrier.heureRdD += 1;
|
||||
this.checkMaladie("heure");
|
||||
}
|
||||
if (this.calendrier.heureRdD >= RDD_HEURES_PAR_JOUR) {
|
||||
this.calendrier.heureRdD -= RDD_HEURES_PAR_JOUR;
|
||||
await this.incrementerJour();
|
||||
this.checkMaladie("heure");
|
||||
this.checkMaladie("jour");
|
||||
}
|
||||
game.settings.set(SYSTEM_RDD, "calendrier", duplicate(this.calendrier));
|
||||
// Notification aux joueurs // TODO: replace with Hook on game settings update
|
||||
game.socket.emit(SYSTEM_SOCKET_ID, {
|
||||
msg: "msg_sync_time",
|
||||
data: duplicate(this.calendrier)
|
||||
});
|
||||
await this.setNewTimestamp(this.timestamp.addMinutes(minutes));
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async incrementerJour() {
|
||||
const index = this.getCurrentDayIndex() + 1;
|
||||
this.calendrier = this.getCalendrier(index);
|
||||
await this.rebuildListeNombreAstral();
|
||||
await this.setNewTimestamp(this.timestamp.nouveauJour());
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
syncPlayerTime(calendrier) {
|
||||
this.calendrier = duplicate(calendrier); // Local copy update
|
||||
syncPlayerTime(timestamp) {
|
||||
this.timestamp = new RdDTimestamp(timestamp);
|
||||
this.updateDisplay();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async positionnerHeure(indexHeure) {
|
||||
if (indexHeure <= this.calendrier.heureRdD) {
|
||||
await this.incrementerJour();
|
||||
}
|
||||
this.calendrier.heureRdD = indexHeure;
|
||||
this.calendrier.minutesRelative = 0;
|
||||
game.settings.set(SYSTEM_RDD, "calendrier", duplicate(this.calendrier));
|
||||
await this.setNewTimestamp(new RdDTimestamp({ indexDate: this.timestamp.indexDate + (this.timestamp.heure < indexHeure ? 0 : 1) }).addHeures(indexHeure))
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
fillCalendrierData(formData = {}) {
|
||||
const mois = RdDCalendrier.getDefSigne(this.calendrier.moisRdD);
|
||||
const heure = RdDCalendrier.getDefSigne(this.calendrier.heureRdD);
|
||||
console.log('fillCalendrierData', this.calendrier, mois, heure);
|
||||
const mois = RdDTimestamp.definition(this.timestamp.mois);
|
||||
const heure = RdDTimestamp.definition(this.timestamp.heure);
|
||||
|
||||
formData.annee = this.timestamp.annee;
|
||||
|
||||
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.jourMois = this.timestamp.jour + 1;
|
||||
|
||||
formData.heureKey = heure.key;
|
||||
formData.moisKey = mois.key;
|
||||
formData.jourMois = this.calendrier.jour + 1;
|
||||
formData.nomMois = mois.label; // heures et mois nommés identiques
|
||||
formData.annee = this.calendrier.annee;
|
||||
formData.iconMois = dossierIconesHeures + mois.icon;
|
||||
formData.heureRdD = this.timestamp.heure;
|
||||
formData.nomHeure = heure.label;
|
||||
formData.iconHeure = dossierIconesHeures + heure.icon;
|
||||
formData.nomSaison = saisonsDef[mois.saison].label;
|
||||
formData.heureRdD = this.calendrier.heureRdD;
|
||||
formData.minutesRelative = this.calendrier.minutesRelative;
|
||||
formData.iconHeure = heure.icon;
|
||||
|
||||
formData.minutesRelative = this.timestamp.minute;
|
||||
|
||||
formData.isGM = game.user.isGM;
|
||||
|
||||
console.log('fillCalendrierData', this.timestamp, mois, heure, formData);
|
||||
return formData;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getLectureAstrologieDifficulte(dateIndex) {
|
||||
let indexNow = this.getCurrentDayIndex();
|
||||
let indexNow = this.timestamp.indexDate;
|
||||
let diffDay = dateIndex - indexNow;
|
||||
return - Math.floor(diffDay / 2);
|
||||
}
|
||||
@ -449,9 +401,9 @@ export class RdDCalendrier extends Application {
|
||||
request.rolled = rollData.rolled;
|
||||
request.isValid = request.rolled.isSuccess;
|
||||
request.nbAstral = this.getNombreAstral(request.date);
|
||||
|
||||
|
||||
if (request.rolled.isSuccess) {
|
||||
if (request.rolled.isPart){
|
||||
if (request.rolled.isPart) {
|
||||
// Gestion expérience (si existante)
|
||||
request.competence = actor.getCompetence("astrologie")
|
||||
request.selectedCarac = actor.system.carac["vue"];
|
||||
@ -483,55 +435,32 @@ export class RdDCalendrier extends Application {
|
||||
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", this.listeNombreAstral);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
findHeure(heure) {
|
||||
heure = Grammar.toLowerCaseNoAccentNoSpace(heure);
|
||||
let parHeureOuLabel = Object.values(heuresDef).filter(it => (it.heure + 1) == parseInt(heure) || Grammar.toLowerCaseNoAccentNoSpace(it.label) == heure);
|
||||
if (parHeureOuLabel.length == 1) {
|
||||
return parHeureOuLabel[0];
|
||||
}
|
||||
let parLabelPartiel = Object.values(heuresDef).filter(it => Grammar.toLowerCaseNoAccentNoSpace(it.label).includes(heure));
|
||||
if (parLabelPartiel.length > 0) {
|
||||
parLabelPartiel.sort(Misc.ascending(h => h.label.length));
|
||||
return parLabelPartiel[0];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getHeureNumber(hNum) {
|
||||
let heure = Object.values(heuresDef).find(it => (it.heure) == hNum);
|
||||
return heure
|
||||
getHeureChance(heure) {
|
||||
return heure + (this.getCurrentNombreAstral() ?? 1) - 1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getHeuresChanceMalchance(heureNaissance) {
|
||||
let heuresChancesMalchances = [];
|
||||
let defHeure = this.findHeure(heureNaissance);
|
||||
let defHeure = RdDTimestamp.findHeure(heureNaissance);
|
||||
if (defHeure) {
|
||||
let hn = defHeure.heure;
|
||||
let chiffreAstral = this.getCurrentNombreAstral() ?? 0;
|
||||
heuresChancesMalchances[0] = { value: "+4", heures: [this.getHeureNumber((hn + chiffreAstral) % RDD_HEURES_PAR_JOUR).label] };
|
||||
heuresChancesMalchances[1] = {
|
||||
value: "+2", heures: [this.getHeureNumber((hn + chiffreAstral + 4) % RDD_HEURES_PAR_JOUR).label,
|
||||
this.getHeureNumber((hn + chiffreAstral + 8) % RDD_HEURES_PAR_JOUR).label]
|
||||
};
|
||||
heuresChancesMalchances[2] = { value: "-4", heures: [this.getHeureNumber((hn + chiffreAstral + 6) % RDD_HEURES_PAR_JOUR).label] };
|
||||
heuresChancesMalchances[3] = {
|
||||
value: "-2", heures: [this.getHeureNumber((hn + chiffreAstral + 3) % RDD_HEURES_PAR_JOUR).label,
|
||||
this.getHeureNumber((hn + chiffreAstral + 9) % RDD_HEURES_PAR_JOUR).label]
|
||||
};
|
||||
const signe = h => h % RDD_HEURES_PAR_JOUR;
|
||||
const chance = this.getHeureChance(defHeure.heure);
|
||||
return [
|
||||
{ ajustement: "+4", heures: [signe(chance)] },
|
||||
{ ajustement: "+2", heures: [signe(chance + 4), signe(chance + 8)] },
|
||||
{ ajustement: "-4", heures: [signe(chance + 6)] },
|
||||
{ ajustement: "-2", heures: [signe(chance + 3), signe(chance + 9)] }
|
||||
];
|
||||
}
|
||||
return heuresChancesMalchances;
|
||||
return [];
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getAjustementAstrologique(heureNaissance, name = undefined) {
|
||||
let defHeure = this.findHeure(heureNaissance);
|
||||
let defHeure = RdDTimestamp.findHeure(heureNaissance);
|
||||
if (defHeure) {
|
||||
let hn = defHeure.heure;
|
||||
let chiffreAstral = this.getCurrentNombreAstral() ?? 0;
|
||||
let heureCourante = this.calendrier.heureRdD;
|
||||
let ecartChance = (hn + chiffreAstral - heureCourante) % RDD_HEURES_PAR_JOUR;
|
||||
const chance = this.getHeureChance(defHeure.heure);
|
||||
const ecartChance = (chance - this.timestamp.heure) % RDD_HEURES_PAR_JOUR;
|
||||
switch (ecartChance) {
|
||||
case 0: return 4;
|
||||
case 4: case 8: return 2;
|
||||
@ -551,9 +480,7 @@ export class RdDCalendrier extends Application {
|
||||
/* -------------------------------------------- */
|
||||
getData() {
|
||||
let formData = super.getData();
|
||||
|
||||
this.fillCalendrierData(formData);
|
||||
|
||||
this.setPos(this.calendrierPos);
|
||||
return formData;
|
||||
}
|
||||
@ -602,30 +529,20 @@ export class RdDCalendrier extends Application {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async saveEditeur(calendrierData) {
|
||||
this.calendrier.minutesRelative = Number(calendrierData.minutesRelative);
|
||||
this.calendrier.jour = Number(calendrierData.jourMois) - 1;
|
||||
this.calendrier.moisRdD = RdDCalendrier.getChiffreFromSigne(calendrierData.moisKey);
|
||||
this.calendrier.annee = Number(calendrierData.annee);
|
||||
this.calendrier.heureRdD = RdDCalendrier.getChiffreFromSigne(calendrierData.heureKey);
|
||||
game.settings.set(SYSTEM_RDD, "calendrier", duplicate(this.calendrier));
|
||||
|
||||
await this.rebuildListeNombreAstral();
|
||||
|
||||
game.socket.emit(SYSTEM_SOCKET_ID, {
|
||||
msg: "msg_sync_time",
|
||||
data: duplicate(this.calendrier)
|
||||
});
|
||||
|
||||
this.updateDisplay();
|
||||
const newTimestamp = RdDTimestamp.timestamp(
|
||||
Number.parseInt(calendrierData.annee),
|
||||
RdDTimestamp.definition(calendrierData.moisKey).heure,
|
||||
Number.parseInt(calendrierData.jourMois),
|
||||
RdDTimestamp.definition(calendrierData.heureKey).heure,
|
||||
Number.parseInt(calendrierData.minutesRelative)
|
||||
);
|
||||
await this.setNewTimestamp(newTimestamp);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async showCalendarEditor() {
|
||||
let calendrierData = duplicate(this.fillCalendrierData());
|
||||
let calendrierData = this.fillCalendrierData();
|
||||
if (this.editeur == undefined) {
|
||||
calendrierData.jourMoisOptions = RdDCalendrier.buildJoursMois();
|
||||
calendrierData.heuresOptions = [0, 1];
|
||||
calendrierData.minutesOptions = Array(RDD_MINUTES_PAR_HEURES).fill().map((item, index) => 0 + index);
|
||||
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/calendar-editor-template.html', calendrierData);
|
||||
this.editeur = new RdDCalendrierEditeur(html, this, calendrierData)
|
||||
}
|
||||
@ -633,33 +550,30 @@ export class RdDCalendrier extends Application {
|
||||
this.editeur.render(true);
|
||||
}
|
||||
|
||||
static buildJoursMois() {
|
||||
return Array(RDD_JOUR_PAR_MOIS).fill().map((item, index) => 1 + index);
|
||||
}
|
||||
static buildJoursMois() { return JOURS_DU_MOIS; }
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async showAstrologieEditor() {
|
||||
let calendrierData = duplicate(this.fillCalendrierData());
|
||||
let astrologieArray = [];
|
||||
const calendrierData = duplicate(this.fillCalendrierData());
|
||||
this.listeNombreAstral = this.listeNombreAstral || [];
|
||||
for (let astralData of this.listeNombreAstral) {
|
||||
astralData.humanDate = this.getDateFromIndex(astralData.index);
|
||||
for (let vf of astralData.valeursFausses) {
|
||||
|
||||
calendrierData.astrologieData = this.listeNombreAstral.map(astro => {
|
||||
const timestamp = new RdDTimestamp({ indexDate: astro.index });
|
||||
astro.date = { mois: timestamp.mois, jour: timestamp.jour + 1 }
|
||||
for (let vf of astro.valeursFausses) {
|
||||
let actor = game.actors.get(vf.actorId);
|
||||
vf.actorName = (actor) ? actor.name : "Inconnu";
|
||||
}
|
||||
astrologieArray.push(duplicate(astralData));
|
||||
}
|
||||
let heuresParActeur = {};
|
||||
for (let actor of game.actors) {
|
||||
return astro;
|
||||
});
|
||||
|
||||
calendrierData.heuresParActeur = {};
|
||||
game.actors.filter(it => it.isPersonnage() && it.hasPlayerOwner).forEach(actor => {
|
||||
let heureNaissance = actor.getHeureNaissance();
|
||||
if (heureNaissance) {
|
||||
heuresParActeur[actor.name] = this.getHeuresChanceMalchance(heureNaissance);
|
||||
calendrierData.heuresParActeur[actor.name] = this.getHeuresChanceMalchance(heureNaissance);
|
||||
}
|
||||
}
|
||||
//console.log("ASTRO", astrologieArray);
|
||||
calendrierData.astrologieData = astrologieArray;
|
||||
calendrierData.heuresParActeur = heuresParActeur;
|
||||
})
|
||||
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/calendar-astrologie-template.html', calendrierData);
|
||||
let astrologieEditeur = new RdDAstrologieEditeur(html, this, calendrierData)
|
||||
astrologieEditeur.updateData(calendrierData);
|
||||
|
Reference in New Issue
Block a user