2020-09-20 16:36:39 +02:00
|
|
|
/* -------------------------------------------- */
|
2020-12-08 21:40:41 +01:00
|
|
|
import { RdDCalendrierEditeur } from "./rdd-calendrier-editeur.js";
|
2020-12-10 20:14:35 +01:00
|
|
|
import { RdDAstrologieEditeur } from "./rdd-astrologie-editeur.js";
|
2020-12-11 02:20:41 +01:00
|
|
|
import { HtmlUtility } from "./html-utility.js";
|
2020-12-12 23:31:19 +01:00
|
|
|
import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
|
|
|
import { RdDUtility } from "./rdd-utility.js";
|
2021-01-26 19:47:18 +01:00
|
|
|
import { Grammar } from "./grammar.js";
|
2020-12-08 21:40:41 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-12-11 02:20:41 +01:00
|
|
|
const dossierIconesHeures = 'systems/foundryvtt-reve-de-dragon/icons/heures/'
|
2021-03-14 16:02:31 +01:00
|
|
|
const heuresList = ["vaisseau", "sirene", "faucon", "couronne", "dragon", "epees", "lyre", "serpent", "poissonacrobate", "araignee", "roseau", "chateaudormant"];
|
|
|
|
const heuresDef = {
|
|
|
|
"vaisseau": { label: "Vaisseau", lettreFont: 'v', saison: "printemps", heure: 0, icon: 'hd01.svg' },
|
|
|
|
"sirene": { label: "Sirène", lettreFont: 'S', saison: "printemps", heure: 1, icon: 'hd02.svg' },
|
|
|
|
"faucon": { label: "Faucon", lettreFont: 'f', saison: "printemps", heure: 2, icon: 'hd03.svg' },
|
|
|
|
"couronne": { label: "Couronne", lettreFont: 'C', saison: "ete", heure: 3, icon: 'hd04.svg' },
|
|
|
|
"dragon": { label: "Dragon", lettreFont: 'd', saison: "ete", heure: 4, icon: 'hd05.svg' },
|
|
|
|
"epees": { label: "Epées", lettreFont: 'e', saison: "ete", heure: 5, icon: 'hd06.svg' },
|
|
|
|
"lyre": { label: "Lyre", lettreFont: 'l', saison: "automne", heure: 6, icon: 'hd07.svg' },
|
|
|
|
"serpent": { label: "Serpent", lettreFont: 's', saison: "automne", heure: 7, icon: 'hd08.svg' },
|
|
|
|
"poissonacrobate": { label: "Poisson Acrobate", lettreFont: 'p', saison: "automne", heure: 8, icon: 'hd09.svg' },
|
|
|
|
"araignee": { label: "Araignée", lettreFont: 'a', saison: "hiver", heure: 9, icon: 'hd10.svg' },
|
|
|
|
"roseau": { label: "Roseau", lettreFont: 'r', saison: "hiver", heure: 10, icon: 'hd11.svg' },
|
|
|
|
"chateaudormant": { label: "Château Dormant", lettreFont: 'c', saison: "hiver", heure: 11, icon: 'hd12.svg' }
|
|
|
|
};
|
|
|
|
const saisonsDef = {
|
|
|
|
"printemps": { label: "Printemps" },
|
|
|
|
"ete": { label: "Eté" },
|
|
|
|
"automne": { label: "Automne" },
|
|
|
|
"hiver": { label: "Hiver" }
|
|
|
|
};
|
2020-12-08 21:40:41 +01:00
|
|
|
const RDD_JOUR_PAR_MOIS = 28;
|
2020-12-11 08:29:24 +01:00
|
|
|
const MAX_NOMBRE_ASTRAL = 12;
|
2020-09-20 16:36:39 +02:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
export class RdDCalendrier extends Application {
|
2020-12-08 21:40:41 +01:00
|
|
|
|
2021-03-14 16:02:31 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-08 21:40:41 +01:00
|
|
|
async initCalendrier() {
|
|
|
|
// Calendrier
|
|
|
|
this.calendrier = duplicate(game.settings.get("foundryvtt-reve-de-dragon", "calendrier"));
|
2021-04-04 18:37:16 +02:00
|
|
|
//console.log("CALENDRIER", this.calendrier);
|
2021-03-14 16:02:31 +01:00
|
|
|
if (this.calendrier == undefined || this.calendrier.moisRdD == undefined) {
|
|
|
|
this.calendrier.heureRdD = 0; // Index dans heuresList
|
2020-12-08 21:40:41 +01:00
|
|
|
this.calendrier.minutesRelative = 0;
|
2021-03-14 16:02:31 +01:00
|
|
|
this.calendrier.moisRdD = 0; // Index dans heuresList
|
|
|
|
this.calendrier.jour = 0;
|
|
|
|
if (game.user.isGM) { // Uniquement si GM
|
|
|
|
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", this.calendrier);
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// position
|
|
|
|
this.calendrierPos = duplicate(game.settings.get("foundryvtt-reve-de-dragon", "calendrier-pos"));
|
2021-03-14 16:02:31 +01:00
|
|
|
if (this.calendrierPos == undefined || this.calendrierPos.top == undefined) {
|
|
|
|
this.calendrierPos.top = 200;
|
|
|
|
this.calendrierPos.left = 200;
|
|
|
|
if (game.user.isGM) { // Uniquement si GM
|
|
|
|
game.settings.set("foundryvtt-reve-de-dragon", "calendrier-pos", this.calendrierPos);
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
|
|
|
}
|
2020-12-08 23:12:43 +01:00
|
|
|
// nombre astral
|
2021-03-14 16:02:31 +01:00
|
|
|
if (game.user.isGM) {
|
|
|
|
this.listeNombreAstral = this._loadListNombreAstral();
|
2020-12-09 00:01:02 +01:00
|
|
|
this.rebuildListeNombreAstral(); // Ensure always up-to-date
|
2020-12-08 23:12:43 +01:00
|
|
|
}
|
2020-12-08 23:35:44 +01:00
|
|
|
console.log(this.calendrier, this.calendrierPos, this.listeNombreAstral);
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2020-12-21 15:14:49 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-17 19:42:25 +01:00
|
|
|
_loadListNombreAstral() {
|
|
|
|
return Object.values(game.settings.get("foundryvtt-reve-de-dragon", "liste-nombre-astral"));
|
|
|
|
}
|
|
|
|
|
2020-12-08 23:12:43 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-08 21:40:41 +01:00
|
|
|
static get defaultOptions() {
|
|
|
|
const options = super.defaultOptions;
|
|
|
|
options.template = "systems/foundryvtt-reve-de-dragon/templates/calendar-template.html";
|
|
|
|
options.popOut = false;
|
|
|
|
options.resizable = false;
|
|
|
|
return options;
|
|
|
|
}
|
2020-12-08 23:28:29 +01:00
|
|
|
|
2020-12-10 20:14:35 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
getDateFromIndex(index = undefined) {
|
|
|
|
if (!index) index = this.getCurrentDayIndex();
|
2020-12-11 08:29:24 +01:00
|
|
|
let month = Math.floor(index / 28);
|
2021-03-14 16:02:31 +01:00
|
|
|
let day = (index - (month * 28)) + 1;
|
|
|
|
return day + " " + heuresList[month];
|
2020-12-10 20:14:35 +01:00
|
|
|
}
|
|
|
|
|
2021-04-04 18:37:16 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
getNumericDateFromIndex(index = undefined) {
|
|
|
|
if (!index) index = this.getCurrentDayIndex();
|
|
|
|
let month = Math.floor(index / 28)
|
|
|
|
return { month: heuresList[month],
|
|
|
|
day: (index - (month * 28)) + 1 }
|
|
|
|
}
|
|
|
|
|
2021-01-16 18:54:07 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
getCurrentHeure() {
|
|
|
|
return heuresList[this.calendrier.heureRdD];
|
|
|
|
}
|
|
|
|
|
2020-12-09 00:01:02 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
getCurrentDayIndex() {
|
2020-12-09 00:01:02 +01:00
|
|
|
return (this.calendrier.moisRdD * 28) + this.calendrier.jour;
|
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2021-04-04 18:37:16 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
getIndexFromDate(jour, mois) {
|
|
|
|
return (heuresDef[mois].heure * 28) + (jour-1);
|
|
|
|
}
|
2020-12-12 23:31:19 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
getJoursSuivants(num) {
|
2020-12-12 23:31:19 +01:00
|
|
|
let jours = [];
|
|
|
|
let index = this.getCurrentDayIndex();
|
2021-03-14 16:02:31 +01:00
|
|
|
for (let i = 0; i < num; i++) {
|
2020-12-12 23:31:19 +01:00
|
|
|
jours[i] = { label: this.getDateFromIndex(index), index: index };
|
|
|
|
index += 1;
|
|
|
|
}
|
|
|
|
return jours;
|
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2020-12-08 23:28:29 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-11 03:23:34 +01:00
|
|
|
ajouterNombreAstral(index) {
|
2020-12-08 23:28:29 +01:00
|
|
|
return {
|
2021-03-28 09:41:14 +02:00
|
|
|
nombreAstral: new Roll("1d12").evaluate( {async:false} ).total,
|
2020-12-08 23:28:29 +01:00
|
|
|
valeursFausses: [],
|
|
|
|
index: index
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-09 00:01:02 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
getCurrentNombreAstral() {
|
2021-02-04 01:00:17 +01:00
|
|
|
let indexDate = this.getCurrentDayIndex();
|
|
|
|
return this.getNombreAstral(indexDate);
|
2020-12-09 00:01:02 +01:00
|
|
|
}
|
|
|
|
|
2021-04-25 10:08:40 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
resetNombreAstral( ) {
|
|
|
|
this.listeNombreAstral = [];
|
|
|
|
game.settings.set("foundryvtt-reve-de-dragon", "liste-nombre-astral", this.listeNombreAstral);
|
|
|
|
}
|
|
|
|
|
2020-12-12 23:31:19 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
getNombreAstral(indexDate) {
|
2021-02-04 01:00:17 +01:00
|
|
|
const liste = this.listeNombreAstral ?? this._loadListNombreAstral();
|
2021-03-14 16:02:31 +01:00
|
|
|
let astralData = liste.find((nombreAstral, i) => nombreAstral.index == indexDate);
|
|
|
|
if (!astralData?.nombreAstral) {
|
2020-12-21 15:14:49 +01:00
|
|
|
this.rebuildListeNombreAstral();
|
2021-03-14 16:02:31 +01:00
|
|
|
astralData = liste.find((nombreAstral, i) => nombreAstral.index == indexDate);
|
2020-12-21 15:14:49 +01:00
|
|
|
}
|
2021-02-04 01:00:17 +01:00
|
|
|
return astralData?.nombreAstral ?? "N/A";
|
2020-12-12 23:31:19 +01:00
|
|
|
}
|
2021-02-04 01:00:17 +01:00
|
|
|
|
2020-12-08 23:28:29 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
rebuildListeNombreAstral() {
|
|
|
|
let jourCourant = this.getCurrentDayIndex();
|
2020-12-21 15:14:49 +01:00
|
|
|
let jourFin = jourCourant + 12;
|
2021-03-14 16:02:31 +01:00
|
|
|
let newList = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map(i => this.ajouterNombreAstral(jourCourant + i));
|
2021-02-04 01:00:17 +01:00
|
|
|
if (this.listeNombreAstral) {
|
|
|
|
for (const na of this.listeNombreAstral) {
|
|
|
|
if (na && na.index >= jourCourant && na.index < jourFin) {
|
|
|
|
newList[na.index - jourCourant] = na;
|
|
|
|
}
|
2020-12-08 23:28:29 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-20 14:36:36 +01:00
|
|
|
this.listeNombreAstral = newList;
|
2021-03-14 16:02:31 +01:00
|
|
|
game.settings.set("foundryvtt-reve-de-dragon", "liste-nombre-astral", this.listeNombreAstral);
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
onCalendarButton(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
const calendarAvance = ev.currentTarget.attributes['data-calendar-avance'];
|
|
|
|
const calendarSet = ev.currentTarget.attributes['data-calendar-set'];
|
|
|
|
if (calendarAvance) {
|
|
|
|
this.incrementTime(Number(calendarAvance.value));
|
|
|
|
}
|
|
|
|
else if (calendarSet) {
|
|
|
|
this.positionnerHeure(Number(calendarSet.value));
|
|
|
|
}
|
|
|
|
this.updateDisplay();
|
2020-12-08 23:28:29 +01:00
|
|
|
}
|
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
incrementTime(minutes = 0) {
|
|
|
|
this.calendrier.minutesRelative += minutes;
|
|
|
|
if (this.calendrier.minutesRelative >= 120) {
|
2020-12-31 12:02:38 +01:00
|
|
|
this.calendrier.minutesRelative -= 120;
|
2020-12-08 21:40:41 +01:00
|
|
|
this.calendrier.heureRdD += 1;
|
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
if (this.calendrier.heureRdD > 11) {
|
2020-12-17 22:59:55 +01:00
|
|
|
this.calendrier.heureRdD -= 12;
|
2020-12-08 23:28:29 +01:00
|
|
|
this.incrementerJour();
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier));
|
2020-12-08 21:40:41 +01:00
|
|
|
// Notification aux joueurs
|
|
|
|
game.socket.emit("system.foundryvtt-reve-de-dragon", {
|
|
|
|
msg: "msg_sync_time",
|
|
|
|
data: duplicate(this.calendrier)
|
2021-03-14 16:02:31 +01:00
|
|
|
});
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2020-12-08 23:28:29 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
incrementerJour() {
|
2020-12-08 23:28:29 +01:00
|
|
|
this.calendrier.jour += 1;
|
2021-03-14 16:02:31 +01:00
|
|
|
if (this.calendrier.jour >= RDD_JOUR_PAR_MOIS) {
|
2020-12-08 23:28:29 +01:00
|
|
|
this.calendrier.jour -= RDD_JOUR_PAR_MOIS;
|
2021-03-14 16:02:31 +01:00
|
|
|
if (this.calendrier.jour <= 0)
|
2020-12-11 08:29:24 +01:00
|
|
|
this.calendrier.jour = 0;
|
2020-12-08 23:28:29 +01:00
|
|
|
this.calendrier.moisRdD += 1;
|
|
|
|
// Reconstruire les nombres astraux
|
|
|
|
}
|
2020-12-11 08:29:24 +01:00
|
|
|
this.rebuildListeNombreAstral();
|
2020-12-08 23:28:29 +01:00
|
|
|
}
|
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
syncPlayerTime(calendrier) {
|
2020-12-08 21:40:41 +01:00
|
|
|
this.calendrier = duplicate(calendrier); // Local copy update
|
2021-03-31 23:59:31 +02:00
|
|
|
this.updateDisplay();
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
positionnerHeure(indexHeure) {
|
|
|
|
if (indexHeure <= this.calendrier.heureRdD)
|
2020-12-08 23:28:29 +01:00
|
|
|
this.incrementerJour();
|
2020-12-08 21:40:41 +01:00
|
|
|
this.calendrier.heureRdD = indexHeure;
|
|
|
|
this.calendrier.minutesRelative = 0;
|
2021-03-14 16:02:31 +01:00
|
|
|
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier));
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-03-16 22:56:57 +01:00
|
|
|
fillCalendrierData(formData = {}) {
|
2021-03-14 16:02:31 +01:00
|
|
|
let moisKey = heuresList[this.calendrier.moisRdD];
|
2020-12-08 21:40:41 +01:00
|
|
|
let heureKey = heuresList[this.calendrier.heureRdD];
|
2020-12-11 02:20:41 +01:00
|
|
|
|
|
|
|
const mois = heuresDef[moisKey];
|
|
|
|
const heure = heuresDef[heureKey];
|
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
//console.log(moisKey, heureKey);
|
2021-03-16 22:56:57 +01:00
|
|
|
formData.heureKey = heureKey;
|
|
|
|
formData.moisKey = moisKey;
|
|
|
|
formData.jourMois = this.calendrier.jour + 1;
|
|
|
|
formData.nomMois = mois.label; // heures et mois nommés identiques
|
|
|
|
formData.iconMois = dossierIconesHeures + mois.icon;
|
|
|
|
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.isGM = game.user.isGM;
|
|
|
|
return formData;
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
|
|
|
|
2020-12-12 23:31:19 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
getLectureAstrologieDifficulte(dateIndex) {
|
2020-12-12 23:31:19 +01:00
|
|
|
let indexNow = this.getCurrentDayIndex();
|
|
|
|
let diffDay = dateIndex - indexNow;
|
|
|
|
return - Math.floor(diffDay / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
async requestNombreAstral(request) {
|
|
|
|
if (game.user.isGM) { // Only GM
|
|
|
|
console.log(request);
|
|
|
|
let jourDiff = this.getLectureAstrologieDifficulte(request.date);
|
2020-12-13 23:11:58 +01:00
|
|
|
let niveau = Number(request.astrologie.data.niveau) + Number(request.conditions) + Number(jourDiff) + Number(request.etat);
|
2021-04-01 00:01:37 +02:00
|
|
|
let rollData= {
|
2020-12-17 00:05:32 +01:00
|
|
|
caracValue: request.carac_vue,
|
|
|
|
finalLevel: niveau,
|
2021-03-14 16:02:31 +01:00
|
|
|
showDice: false
|
2021-04-01 00:01:37 +02:00
|
|
|
};
|
|
|
|
await RdDResolutionTable.rollData(rollData);
|
2021-03-14 16:02:31 +01:00
|
|
|
let nbAstral = this.getNombreAstral(request.date);
|
2021-04-01 00:01:37 +02:00
|
|
|
request.rolled = rollData.rolled;
|
2020-12-12 23:31:19 +01:00
|
|
|
request.isValid = true;
|
2021-04-01 00:01:37 +02:00
|
|
|
if (!request.rolled.isSuccess) {
|
2020-12-12 23:31:19 +01:00
|
|
|
request.isValid = false;
|
2021-04-01 00:01:37 +02:00
|
|
|
let nbAstralFaux = new Roll("1d11").evaluate( { async: false} ).total;
|
|
|
|
nbAstral = nbAstral==nbAstralFaux ? 12 : nbAstralFaux;
|
2020-12-12 23:41:04 +01:00
|
|
|
// Mise à jour des nombres astraux du joueur
|
2021-03-14 16:02:31 +01:00
|
|
|
let astralData = this.listeNombreAstral.find((nombreAstral, i) => nombreAstral.index == request.date);
|
|
|
|
astralData.valeursFausses.push({ actorId: request.id, nombreAstral: nbAstralFaux });
|
|
|
|
game.settings.set("foundryvtt-reve-de-dragon", "liste-nombre-astral", this.listeNombreAstral);
|
2020-12-12 23:31:19 +01:00
|
|
|
}
|
|
|
|
request.nbAstral = nbAstral;
|
2021-03-14 16:02:31 +01:00
|
|
|
if (game.user.isGM) {
|
|
|
|
RdDUtility.responseNombreAstral(request);
|
|
|
|
} else {
|
2020-12-12 23:31:19 +01:00
|
|
|
game.socket.emit("system.foundryvtt-reve-de-dragon", {
|
|
|
|
msg: "msg_response_nombre_astral",
|
2021-03-14 16:02:31 +01:00
|
|
|
data: request
|
|
|
|
});
|
2020-12-12 23:31:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-11 16:19:19 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
getAjustementAstrologique(heureNaissance, name = 'inconnu') {
|
2021-01-26 19:47:18 +01:00
|
|
|
let heure = Grammar.toLowerCaseNoAccent(heureNaissance);
|
|
|
|
if (heure && heuresDef[heure]) {
|
|
|
|
let hn = heuresDef[heure].heure;
|
2020-12-15 23:28:59 +01:00
|
|
|
let chiffreAstral = this.getCurrentNombreAstral();
|
|
|
|
let heureCourante = this.calendrier.heureRdD;
|
2021-03-14 16:02:31 +01:00
|
|
|
let ecartChance = (hn + chiffreAstral - heureCourante) % 12;
|
|
|
|
switch (ecartChance) {
|
2020-12-15 23:28:59 +01:00
|
|
|
case 0: return 4;
|
|
|
|
case 4: case 8: return 2;
|
|
|
|
case 6: return -4;
|
|
|
|
case 3: case 9: return -2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2021-01-16 18:54:07 +01:00
|
|
|
ui.notifications.warn(name + " n'a pas d'heure de naissance, ou elle est incorrecte : " + heureNaissance);
|
2020-12-11 03:23:34 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
getData() {
|
2021-03-16 22:56:57 +01:00
|
|
|
let formData = super.getData();
|
2020-12-08 21:40:41 +01:00
|
|
|
|
2021-03-16 22:56:57 +01:00
|
|
|
this.fillCalendrierData(formData);
|
2020-12-08 21:40:41 +01:00
|
|
|
|
2021-03-14 16:02:31 +01:00
|
|
|
this.setPos(this.calendrierPos);
|
2021-03-16 22:56:57 +01:00
|
|
|
return formData;
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
setPos(pos) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
function check() {
|
|
|
|
let elmnt = document.getElementById("calendar-time-container");
|
|
|
|
if (elmnt) {
|
|
|
|
elmnt.style.bottom = null;
|
2021-03-14 16:02:31 +01:00
|
|
|
let xPos = (pos.left) > window.innerWidth ? window.innerWidth - 200 : pos.left;
|
|
|
|
let yPos = (pos.top) > window.innerHeight - 20 ? window.innerHeight - 100 : pos.top;
|
2020-12-08 21:40:41 +01:00
|
|
|
elmnt.style.top = (yPos) + "px";
|
|
|
|
elmnt.style.left = (xPos) + "px";
|
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
setTimeout(check, 30);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
check();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
updateDisplay() {
|
|
|
|
let data = this.fillCalendrierData();
|
|
|
|
// Rebuild data
|
2020-12-21 20:54:24 +01:00
|
|
|
let dateHTML = `Jour ${data.jourMois} de ${data.nomMois} (${data.nomSaison})`;
|
|
|
|
if (game.user.isGM) {
|
2021-03-14 16:02:31 +01:00
|
|
|
dateHTML = dateHTML + " - NA: " + this.getCurrentNombreAstral();
|
|
|
|
}
|
2021-03-31 23:59:31 +02:00
|
|
|
for (let handle of document.getElementsByClassName("calendar-date-rdd")) {
|
2021-03-14 16:02:31 +01:00
|
|
|
handle.innerHTML = dateHTML;
|
|
|
|
}
|
|
|
|
for (let heure of document.getElementsByClassName("calendar-heure-texte")) {
|
|
|
|
heure.innerHTML = data.nomHeure;
|
|
|
|
}
|
|
|
|
for (const minute of document.getElementsByClassName("calendar-time-disp")) {
|
|
|
|
minute.innerHTML = `${data.minutesRelative} minutes`;
|
|
|
|
}
|
|
|
|
for (const heureImg of document.getElementsByClassName("calendar-heure-img")) {
|
|
|
|
heureImg.src = data.iconHeure;
|
2020-12-21 20:54:24 +01:00
|
|
|
}
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
saveEditeur(calendrierData) {
|
2020-12-08 21:40:41 +01:00
|
|
|
this.calendrier.minutesRelative = Number(calendrierData.minutesRelative);
|
2021-03-14 16:02:31 +01:00
|
|
|
this.calendrier.jour = Number(calendrierData.jourMois) - 1;
|
|
|
|
this.calendrier.moisRdD = heuresList.findIndex(mois => mois === calendrierData.moisKey);
|
|
|
|
this.calendrier.heureRdD = heuresList.findIndex(heure => heure === calendrierData.heureKey);; // Index dans heuresList
|
|
|
|
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier));
|
|
|
|
|
2020-12-08 23:28:29 +01:00
|
|
|
this.rebuildListeNombreAstral();
|
2020-12-08 21:40:41 +01:00
|
|
|
|
|
|
|
this.updateDisplay();
|
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
async showCalendarEditor() {
|
|
|
|
let calendrierData = duplicate(this.fillCalendrierData());
|
|
|
|
if (this.editeur == undefined) {
|
2020-12-08 21:40:41 +01:00
|
|
|
calendrierData.jourMoisOptions = Array(28).fill().map((item, index) => 1 + index);
|
2021-03-14 16:02:31 +01:00
|
|
|
calendrierData.heuresOptions = [0, 1];
|
|
|
|
calendrierData.minutesOptions = Array(120).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)
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
this.editeur.updateData(calendrierData);
|
2020-12-08 21:40:41 +01:00
|
|
|
this.editeur.render(true);
|
|
|
|
}
|
|
|
|
|
2020-12-10 20:14:35 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
async showAstrologieEditor() {
|
2021-03-14 16:02:31 +01:00
|
|
|
let calendrierData = duplicate(this.fillCalendrierData());
|
|
|
|
let astrologieArray = [];
|
|
|
|
for (let astralData of this.listeNombreAstral) {
|
|
|
|
astralData.humanDate = this.getDateFromIndex(astralData.index);
|
2020-12-13 23:11:58 +01:00
|
|
|
for (let vf of astralData.valeursFausses) {
|
2021-03-14 16:02:31 +01:00
|
|
|
let actor = game.actors.get(vf.actorId);
|
|
|
|
console.log(vf.actorId, actor);
|
2020-12-13 23:11:58 +01:00
|
|
|
vf.actorName = (actor) ? actor.name : "Inconnu";
|
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
astrologieArray.push(duplicate(astralData));
|
2020-12-10 20:14:35 +01:00
|
|
|
}
|
2020-12-11 08:29:24 +01:00
|
|
|
//console.log("ASTRO", astrologieArray);
|
|
|
|
calendrierData.astrologieData = astrologieArray;
|
2021-03-14 16:02:31 +01:00
|
|
|
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);
|
2020-12-11 08:29:24 +01:00
|
|
|
astrologieEditeur.render(true);
|
2020-12-10 20:14:35 +01:00
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
2021-03-14 16:02:31 +01:00
|
|
|
activateListeners(html) {
|
2020-12-08 21:40:41 +01:00
|
|
|
super.activateListeners(html);
|
|
|
|
|
2020-12-20 02:05:47 +01:00
|
|
|
HtmlUtility._showControlWhen($(".gm-only"), game.user.isGM);
|
2020-12-11 02:20:41 +01:00
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
this.updateDisplay();
|
|
|
|
|
2021-03-14 16:02:31 +01:00
|
|
|
html.find('.calendar-btn').click(ev => this.onCalendarButton(ev));
|
|
|
|
|
|
|
|
html.find('.calendar-btn-edit').click(ev => {
|
2020-12-08 21:40:41 +01:00
|
|
|
ev.preventDefault();
|
|
|
|
this.showCalendarEditor();
|
|
|
|
});
|
2021-03-14 16:02:31 +01:00
|
|
|
|
|
|
|
html.find('.astrologie-btn-edit').click(ev => {
|
2020-12-10 20:14:35 +01:00
|
|
|
ev.preventDefault();
|
|
|
|
this.showAstrologieEditor();
|
|
|
|
});
|
2020-12-08 21:40:41 +01:00
|
|
|
|
2021-03-14 16:02:31 +01:00
|
|
|
html.find('#calendar-move-handle').mousedown(ev => {
|
2020-12-08 21:40:41 +01:00
|
|
|
ev.preventDefault();
|
|
|
|
ev = ev || window.event;
|
|
|
|
let isRightMB = false;
|
|
|
|
if ("which" in ev) { // Gecko (Firefox), WebKit (Safari/Chrome) & Opera
|
|
|
|
isRightMB = ev.which == 3;
|
|
|
|
} else if ("button" in ev) { // IE, Opera
|
|
|
|
isRightMB = ev.button == 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isRightMB) {
|
|
|
|
dragElement(document.getElementById("calendar-time-container"));
|
|
|
|
let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
|
2020-09-20 16:36:39 +02:00
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
function dragElement(elmnt) {
|
|
|
|
elmnt.onmousedown = dragMouseDown;
|
|
|
|
function dragMouseDown(e) {
|
|
|
|
e = e || window.event;
|
|
|
|
e.preventDefault();
|
|
|
|
pos3 = e.clientX;
|
|
|
|
pos4 = e.clientY;
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
document.onmouseup = closeDragElement;
|
|
|
|
document.onmousemove = elementDrag;
|
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
function elementDrag(e) {
|
|
|
|
e = e || window.event;
|
|
|
|
e.preventDefault();
|
|
|
|
// calculate the new cursor position:
|
|
|
|
pos1 = pos3 - e.clientX;
|
|
|
|
pos2 = pos4 - e.clientY;
|
|
|
|
pos3 = e.clientX;
|
|
|
|
pos4 = e.clientY;
|
|
|
|
// set the element's new position:
|
|
|
|
elmnt.style.bottom = null
|
|
|
|
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
|
|
|
|
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
|
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
function closeDragElement() {
|
|
|
|
// stop moving when mouse button is released:
|
|
|
|
elmnt.onmousedown = null;
|
|
|
|
document.onmouseup = null;
|
|
|
|
document.onmousemove = null;
|
2021-03-14 16:02:31 +01:00
|
|
|
let xPos = (elmnt.offsetLeft - pos1) > window.innerWidth ? window.innerWidth - 200 : (elmnt.offsetLeft - pos1);
|
|
|
|
let yPos = (elmnt.offsetTop - pos2) > window.innerHeight - 20 ? window.innerHeight - 100 : (elmnt.offsetTop - pos2)
|
2020-12-08 21:40:41 +01:00
|
|
|
xPos = xPos < 0 ? 0 : xPos;
|
|
|
|
yPos = yPos < 0 ? 0 : yPos;
|
2021-03-14 16:02:31 +01:00
|
|
|
if (xPos != (elmnt.offsetLeft - pos1) || yPos != (elmnt.offsetTop - pos2)) {
|
2020-12-08 21:40:41 +01:00
|
|
|
elmnt.style.top = (yPos) + "px";
|
|
|
|
elmnt.style.left = (xPos) + "px";
|
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
game.system.rdd.calendrier.calendrierPos.top = yPos;
|
|
|
|
game.system.rdd.calendrier.calendrierPos.left = xPos;
|
|
|
|
if (game.user.isGM) {
|
|
|
|
game.settings.set("foundryvtt-reve-de-dragon", "calendrier-pos", duplicate(game.system.rdd.calendrier.calendrierPos));
|
2021-03-09 23:28:21 +01:00
|
|
|
}
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
} else if (isRightMB) {
|
|
|
|
game.system.rdd.calendrier.calendrierPos.top = 200;
|
|
|
|
game.system.rdd.calendrier.calendrierPos.left = 200;
|
|
|
|
if (game.user.isGM) {
|
|
|
|
game.settings.set("foundryvtt-reve-de-dragon", "calendrier-pos", duplicate(game.system.rdd.calendrier.calendrierPos));
|
2021-03-09 23:28:21 +01:00
|
|
|
}
|
2020-12-08 21:40:41 +01:00
|
|
|
this.setPos(game.system.rdd.calendrier.calendrierPos);
|
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
});
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2020-09-20 16:36:39 +02:00
|
|
|
}
|