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";
|
2021-05-19 23:04:34 +02:00
|
|
|
import { RdDDice } from "./rdd-dice.js";
|
2021-06-09 00:00:15 +02:00
|
|
|
import { Misc } from "./misc.js";
|
2022-01-29 22:49:34 +01:00
|
|
|
import { HIDE_DICE, SHOW_DICE, SYSTEM_RDD, SYSTEM_SOCKET_ID } from "./constants.js";
|
2022-11-04 20:41:16 +01:00
|
|
|
import { DialogChronologie } from "./dialog-chronologie.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 = {
|
2022-11-17 01:18:06 +01:00
|
|
|
"vaisseau": {key: "vaisseau", label: "Vaisseau", lettreFont: 'v', saison: "printemps", heure: 0, icon: 'hd01.svg' },
|
2022-11-04 20:41:16 +01:00
|
|
|
"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' }
|
2021-03-14 16:02:31 +01:00
|
|
|
};
|
|
|
|
const saisonsDef = {
|
|
|
|
"printemps": { label: "Printemps" },
|
|
|
|
"ete": { label: "Eté" },
|
|
|
|
"automne": { label: "Automne" },
|
|
|
|
"hiver": { label: "Hiver" }
|
|
|
|
};
|
2021-06-09 00:00:15 +02:00
|
|
|
|
|
|
|
const RDD_MOIS_PAR_AN = 12;
|
|
|
|
export const RDD_JOUR_PAR_MOIS = 28;
|
|
|
|
const RDD_HEURES_PAR_JOUR = 12;
|
|
|
|
const RDD_MINUTES_PAR_HEURES = 120;
|
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-06-08 14:11:23 +02:00
|
|
|
static createCalendrierPos() {
|
|
|
|
return { top: 200, left: 200 };
|
|
|
|
}
|
2021-06-08 14:09:40 +02:00
|
|
|
|
2021-07-09 01:01:12 +02:00
|
|
|
static getDefSigne(chiffre) {
|
|
|
|
chiffre = chiffre % RDD_MOIS_PAR_AN;
|
|
|
|
return Object.values(heuresDef).find(h => h.heure == chiffre);
|
|
|
|
}
|
|
|
|
|
2022-11-04 20:41:16 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
2021-07-09 01:01:12 +02:00
|
|
|
static getChiffreFromSigne(signe) {
|
|
|
|
return heuresList.indexOf(signe);
|
2021-06-09 00:00:15 +02:00
|
|
|
}
|
|
|
|
|
2022-11-04 20:41:16 +01:00
|
|
|
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();
|
2022-11-07 00:04:43 +01:00
|
|
|
const mois = Math.floor(index / RDD_JOUR_PAR_MOIS) % RDD_MOIS_PAR_AN;
|
2022-11-04 20:41:16 +01:00
|
|
|
return {
|
2021-06-09 00:00:15 +02:00
|
|
|
heureRdD: 0, // Index dans heuresList / heuresDef[x].heure
|
2021-05-27 01:08:17 +02:00
|
|
|
minutesRelative: 0,
|
2021-06-08 14:09:40 +02:00
|
|
|
indexJour: index,
|
2021-06-09 00:00:15 +02:00
|
|
|
annee: Math.floor(index / (RDD_JOUR_PAR_MOIS * RDD_MOIS_PAR_AN)),
|
2022-11-17 01:25:40 +01:00
|
|
|
moisRdD: RdDCalendrier.getDefSigne(mois).heure,
|
2022-11-07 00:04:43 +01:00
|
|
|
moisLabel: RdDCalendrier.getDefSigne(mois).label,
|
2021-06-09 00:00:15 +02:00
|
|
|
jour: (index % RDD_JOUR_PAR_MOIS) // Le calendrier stocke le jour en 0-27, mais en 1-28 à l'affichage
|
2021-05-27 01:08:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-09 01:01:12 +02:00
|
|
|
constructor() {
|
|
|
|
super();
|
2020-12-08 21:40:41 +01:00
|
|
|
// position
|
2021-11-11 02:43:38 +01:00
|
|
|
this.calendrierPos = duplicate(game.settings.get(SYSTEM_RDD, "calendrier-pos"));
|
2021-03-14 16:02:31 +01:00
|
|
|
if (this.calendrierPos == undefined || this.calendrierPos.top == undefined) {
|
2021-06-08 14:11:23 +02:00
|
|
|
this.calendrierPos = RdDCalendrier.createCalendrierPos();
|
2021-11-11 02:43:38 +01:00
|
|
|
game.settings.set(SYSTEM_RDD, "calendrier-pos", this.calendrierPos);
|
2021-07-09 01:01:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calendrier
|
2022-11-04 20:41:16 +01:00
|
|
|
this.calendrier = duplicate(game.settings.get(SYSTEM_RDD, "calendrier") ?? RdDCalendrier.createCalendrierInitial());
|
2021-07-09 01:01:12 +02:00
|
|
|
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;
|
|
|
|
|
2021-11-26 00:45:21 +01:00
|
|
|
if (Misc.isUniqueConnectedGM()) { // Uniquement si GM
|
2021-11-11 02:43:38 +01:00
|
|
|
game.settings.set(SYSTEM_RDD, "calendrier", this.calendrier);
|
2021-07-09 01:01:12 +02:00
|
|
|
|
|
|
|
this.listeNombreAstral = this.getListeNombreAstral();
|
2022-11-25 03:17:07 +01:00
|
|
|
this.rebuildListeNombreAstral(HIDE_DICE); // Ensure always up-to-date
|
2020-12-08 23:12:43 +01:00
|
|
|
}
|
2022-11-18 23:00:37 +01:00
|
|
|
console.log('RdDCalendrier.constructor()', 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
|
|
|
/* -------------------------------------------- */
|
2021-07-09 01:01:12 +02:00
|
|
|
getListeNombreAstral() {
|
2021-11-11 02:43:38 +01:00
|
|
|
return game.settings.get(SYSTEM_RDD, "liste-nombre-astral") ?? [];
|
2020-12-17 19:42:25 +01:00
|
|
|
}
|
|
|
|
|
2020-12-08 23:12:43 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-08 21:40:41 +01:00
|
|
|
static get defaultOptions() {
|
2021-07-09 01:01:12 +02:00
|
|
|
return mergeObject(super.defaultOptions, {
|
|
|
|
template: "systems/foundryvtt-reve-de-dragon/templates/calendar-template.html",
|
|
|
|
popOut: false,
|
|
|
|
resizable: false
|
|
|
|
});
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
2020-12-08 23:28:29 +01:00
|
|
|
|
2020-12-10 20:14:35 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-05-27 01:08:17 +02:00
|
|
|
getDateFromIndex(index) {
|
2022-11-04 20:41:16 +01:00
|
|
|
const dateRdD = this.getCalendrier(index);
|
2022-11-07 00:04:43 +01:00
|
|
|
return (dateRdD.jour + 1) + ' ' + dateRdD.moisLabel;
|
2020-12-10 20:14:35 +01:00
|
|
|
}
|
|
|
|
|
2021-04-04 18:37:16 +02:00
|
|
|
/* -------------------------------------------- */
|
2022-11-04 20:41:16 +01:00
|
|
|
getDayMonthFromIndex(index = undefined) {
|
|
|
|
const dateRdD = this.getCalendrier(index);
|
2021-05-19 23:04:34 +02:00
|
|
|
return {
|
2021-06-08 14:09:40 +02:00
|
|
|
day: dateRdD.jour + 1,
|
2021-06-09 00:05:41 +02:00
|
|
|
month: heuresList[dateRdD.moisRdD]
|
2021-05-19 23:04:34 +02:00
|
|
|
}
|
2021-04-04 18:37:16 +02:00
|
|
|
}
|
|
|
|
|
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() {
|
2021-06-09 00:00:15 +02:00
|
|
|
return (((this.calendrier.annee ?? 0) * RDD_MOIS_PAR_AN + (this.calendrier.moisRdD ?? 0)) * RDD_JOUR_PAR_MOIS) + (this.calendrier.jour ?? 0);
|
2020-12-09 00:01:02 +01:00
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2021-04-04 18:37:16 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
getIndexFromDate(jour, mois) {
|
2021-06-09 00:00:15 +02:00
|
|
|
return (heuresDef[mois].heure * RDD_JOUR_PAR_MOIS) + jour - 1;
|
2021-04-04 18:37:16 +02:00
|
|
|
}
|
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++) {
|
2021-06-09 00:00:15 +02:00
|
|
|
jours[i] = { label: this.getDateFromIndex(index + i), index: index + i };
|
2020-12-12 23:31:19 +01:00
|
|
|
}
|
|
|
|
return jours;
|
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2020-12-08 23:28:29 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-12-04 23:02:08 +01:00
|
|
|
async ajouterNombreAstral(index, showDice = SHOW_DICE) {
|
2021-12-03 22:53:38 +01:00
|
|
|
const nombreAstral = await RdDDice.rollTotal("1dh", { showDice: showDice, rollMode: "selfroll" });
|
2021-05-27 01:08:17 +02:00
|
|
|
const dateFuture = this.getDateFromIndex(index);
|
2021-12-03 22:53:38 +01:00
|
|
|
if (showDice != HIDE_DICE) {
|
2021-07-09 01:01:12 +02:00
|
|
|
ChatMessage.create({
|
2021-06-25 14:40:25 +02:00
|
|
|
whisper: ChatMessage.getWhisperRecipients("GM"),
|
|
|
|
content: `Le chiffre astrologique du ${dateFuture} sera le ${nombreAstral}`
|
|
|
|
});
|
|
|
|
}
|
2020-12-08 23:28:29 +01:00
|
|
|
return {
|
2021-05-19 23:04:34 +02:00
|
|
|
nombreAstral: nombreAstral,
|
2020-12-08 23:28:29 +01:00
|
|
|
valeursFausses: [],
|
|
|
|
index: index
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-09 00:01:02 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-05-27 01:08:17 +02:00
|
|
|
getCurrentNombreAstral() {
|
2021-02-04 01:00:17 +01:00
|
|
|
let indexDate = this.getCurrentDayIndex();
|
2021-05-27 01:08:17 +02:00
|
|
|
return this.getNombreAstral(indexDate);
|
2020-12-09 00:01:02 +01:00
|
|
|
}
|
|
|
|
|
2021-04-25 10:08:40 +02:00
|
|
|
/* -------------------------------------------- */
|
2021-05-19 23:04:34 +02:00
|
|
|
resetNombreAstral() {
|
2021-04-25 10:08:40 +02:00
|
|
|
this.listeNombreAstral = [];
|
2021-11-11 02:43:38 +01:00
|
|
|
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", this.listeNombreAstral);
|
2021-06-01 21:58:40 +02:00
|
|
|
|
2022-01-29 22:49:34 +01:00
|
|
|
game.socket.emit(SYSTEM_SOCKET_ID, {
|
2021-06-01 21:58:40 +02:00
|
|
|
msg: "msg_reset_nombre_astral",
|
|
|
|
data: {}
|
|
|
|
});
|
2021-04-25 10:08:40 +02:00
|
|
|
}
|
|
|
|
|
2021-06-09 00:00:15 +02:00
|
|
|
/* -------------------------------------------- */
|
2021-05-27 01:08:17 +02:00
|
|
|
getNombreAstral(indexDate) {
|
2022-11-25 03:17:07 +01:00
|
|
|
const listNombreAstral = this.getListeNombreAstral();
|
|
|
|
let astralData = listNombreAstral.find((nombreAstral, i) => nombreAstral.index == indexDate);
|
2021-05-27 01:08:17 +02:00
|
|
|
return astralData?.nombreAstral;
|
2020-12-12 23:31:19 +01:00
|
|
|
}
|
2021-02-04 01:00:17 +01:00
|
|
|
|
2020-12-08 23:28:29 +01:00
|
|
|
/* -------------------------------------------- */
|
2022-11-25 03:17:07 +01:00
|
|
|
async rebuildListeNombreAstral(showDice = HIDE_DICE) {
|
2021-11-26 00:45:21 +01:00
|
|
|
if (Misc.isUniqueConnectedGM()) {
|
2021-05-20 21:36:20 +02:00
|
|
|
let jourCourant = this.getCurrentDayIndex();
|
|
|
|
let newList = [];
|
2021-06-09 00:00:15 +02:00
|
|
|
for (let i = 0; i < MAX_NOMBRE_ASTRAL; i++) {
|
2021-06-07 22:52:42 +02:00
|
|
|
let dayIndex = jourCourant + i;
|
2021-06-09 00:00:15 +02:00
|
|
|
let na = this.listeNombreAstral.find(n => n.index == dayIndex);
|
|
|
|
if (na) {
|
2021-07-09 01:01:12 +02:00
|
|
|
newList[i] = na;
|
2021-06-07 22:52:42 +02:00
|
|
|
} else {
|
2021-07-09 01:01:12 +02:00
|
|
|
newList[i] = await this.ajouterNombreAstral(dayIndex, showDice);
|
2021-05-20 21:36:20 +02:00
|
|
|
}
|
|
|
|
}
|
2022-11-25 03:17:07 +01:00
|
|
|
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", newList);
|
2021-05-20 21:36:20 +02:00
|
|
|
this.listeNombreAstral = newList;
|
2020-12-08 23:28:29 +01:00
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
}
|
2021-06-09 16:38:52 +02:00
|
|
|
|
2021-03-14 16:02:31 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-05-19 23:04:34 +02:00
|
|
|
async onCalendarButton(ev) {
|
2021-03-14 16:02:31 +01:00
|
|
|
ev.preventDefault();
|
|
|
|
const calendarAvance = ev.currentTarget.attributes['data-calendar-avance'];
|
|
|
|
const calendarSet = ev.currentTarget.attributes['data-calendar-set'];
|
|
|
|
if (calendarAvance) {
|
2021-05-19 23:04:34 +02:00
|
|
|
await this.incrementTime(Number(calendarAvance.value));
|
2021-03-14 16:02:31 +01:00
|
|
|
}
|
|
|
|
else if (calendarSet) {
|
|
|
|
this.positionnerHeure(Number(calendarSet.value));
|
|
|
|
}
|
2021-06-05 20:53:43 +02:00
|
|
|
this.updateDisplay();
|
2020-12-08 23:28:29 +01:00
|
|
|
}
|
|
|
|
|
2021-10-29 20:58:57 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
checkMaladie( periode) {
|
|
|
|
for (let actor of game.actors) {
|
|
|
|
if (actor.type == 'personnage') {
|
2022-09-23 00:46:45 +02:00
|
|
|
let maladies = actor.items.filter( item => (item.type == 'maladie' || (item.type == 'poison' && item.system.active) ) && item.system.periodicite.toLowerCase().includes(periode) );
|
2021-10-29 20:58:57 +02:00
|
|
|
for (let maladie of maladies) {
|
2022-09-23 00:46:45 +02:00
|
|
|
if ( maladie.system.identifie) {
|
2021-10-29 21:31:58 +02:00
|
|
|
ChatMessage.create({ content: `${actor.name} souffre de ${maladie.name} (${maladie.type}): vérifiez que les effets ne se sont pas aggravés !` });
|
|
|
|
} else {
|
|
|
|
ChatMessage.create({ content: `${actor.name} souffre d'un mal inconnu (${maladie.type}): vérifiez que les effets ne se sont pas aggravés !` });
|
|
|
|
}
|
|
|
|
let itemMaladie = actor.getObjet(maladie.id)
|
|
|
|
itemMaladie.postItem( 'gmroll');
|
2021-10-29 20:58:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-05-19 23:04:34 +02:00
|
|
|
async incrementTime(minutes = 0) {
|
2021-03-14 16:02:31 +01:00
|
|
|
this.calendrier.minutesRelative += minutes;
|
2021-10-29 20:58:57 +02:00
|
|
|
this.checkMaladie("round");
|
|
|
|
this.checkMaladie("minute");
|
2021-06-09 00:00:15 +02:00
|
|
|
if (this.calendrier.minutesRelative >= RDD_MINUTES_PAR_HEURES) {
|
|
|
|
this.calendrier.minutesRelative -= RDD_MINUTES_PAR_HEURES;
|
2020-12-08 21:40:41 +01:00
|
|
|
this.calendrier.heureRdD += 1;
|
2021-10-29 20:58:57 +02:00
|
|
|
this.checkMaladie("heure");
|
|
|
|
}
|
2021-06-09 00:00:15 +02:00
|
|
|
if (this.calendrier.heureRdD >= RDD_HEURES_PAR_JOUR) {
|
|
|
|
this.calendrier.heureRdD -= RDD_HEURES_PAR_JOUR;
|
2021-07-09 01:01:12 +02:00
|
|
|
await this.incrementerJour();
|
2021-10-29 20:58:57 +02:00
|
|
|
this.checkMaladie("heure");
|
|
|
|
this.checkMaladie("jour");
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
2021-11-11 02:43:38 +01:00
|
|
|
game.settings.set(SYSTEM_RDD, "calendrier", duplicate(this.calendrier));
|
2022-01-29 22:49:34 +01:00
|
|
|
// Notification aux joueurs // TODO: replace with Hook on game settings update
|
|
|
|
game.socket.emit(SYSTEM_SOCKET_ID, {
|
2020-12-08 21:40:41 +01:00
|
|
|
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-07-09 01:01:12 +02:00
|
|
|
async incrementerJour() {
|
2021-06-08 14:09:40 +02:00
|
|
|
const index = this.getCurrentDayIndex() + 1;
|
2022-11-04 20:41:16 +01:00
|
|
|
this.calendrier = this.getCalendrier(index);
|
2021-07-09 01:01:12 +02:00
|
|
|
await this.rebuildListeNombreAstral();
|
2020-12-08 23:28:29 +01:00
|
|
|
}
|
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-05-27 01:08:17 +02:00
|
|
|
syncPlayerTime(calendrier) {
|
2020-12-08 21:40:41 +01:00
|
|
|
this.calendrier = duplicate(calendrier); // Local copy update
|
2021-05-27 01:08:17 +02:00
|
|
|
this.updateDisplay();
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-05-19 23:04:34 +02:00
|
|
|
async positionnerHeure(indexHeure) {
|
2021-05-20 21:36:20 +02:00
|
|
|
if (indexHeure <= this.calendrier.heureRdD) {
|
2021-07-09 01:01:12 +02:00
|
|
|
await this.incrementerJour();
|
2021-05-19 23:04:34 +02:00
|
|
|
}
|
2020-12-08 21:40:41 +01:00
|
|
|
this.calendrier.heureRdD = indexHeure;
|
|
|
|
this.calendrier.minutesRelative = 0;
|
2021-11-11 02:43:38 +01:00
|
|
|
game.settings.set(SYSTEM_RDD, "calendrier", duplicate(this.calendrier));
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-03-16 22:56:57 +01:00
|
|
|
fillCalendrierData(formData = {}) {
|
2022-11-17 01:25:40 +01:00
|
|
|
const mois = RdDCalendrier.getDefSigne(this.calendrier.moisRdD);
|
|
|
|
const heure = RdDCalendrier.getDefSigne(this.calendrier.heureRdD);
|
|
|
|
console.log('fillCalendrierData', this.calendrier, mois, heure);
|
2020-12-11 02:20:41 +01:00
|
|
|
|
2022-11-17 01:25:40 +01:00
|
|
|
formData.heureKey = heure.key;
|
|
|
|
formData.moisKey = mois.key;
|
2021-03-16 22:56:57 +01:00
|
|
|
formData.jourMois = this.calendrier.jour + 1;
|
|
|
|
formData.nomMois = mois.label; // heures et mois nommés identiques
|
2022-11-25 03:17:07 +01:00
|
|
|
formData.annee = this.calendrier.annee;
|
2021-03-16 22:56:57 +01:00
|
|
|
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) {
|
2021-11-26 00:45:21 +01:00
|
|
|
if (Misc.isUniqueConnectedGM()) { // Only once
|
2021-03-14 16:02:31 +01:00
|
|
|
console.log(request);
|
|
|
|
let jourDiff = this.getLectureAstrologieDifficulte(request.date);
|
2022-06-12 12:14:55 +02:00
|
|
|
let niveau = Number(request.astrologie.system.niveau) + Number(request.conditions) + Number(jourDiff) + Number(request.etat);
|
2021-05-19 23:04:34 +02:00
|
|
|
let rollData = {
|
2020-12-17 00:05:32 +01:00
|
|
|
caracValue: request.carac_vue,
|
|
|
|
finalLevel: niveau,
|
2021-12-03 22:53:38 +01:00
|
|
|
showDice: HIDE_DICE,
|
2021-06-13 21:56:01 +02:00
|
|
|
rollMode: "blindroll"
|
2021-04-01 00:01:37 +02:00
|
|
|
};
|
|
|
|
await RdDResolutionTable.rollData(rollData);
|
2021-05-27 01:08:17 +02: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-12-03 22:53:38 +01:00
|
|
|
nbAstral = await RdDDice.rollTotal("1dhr" + nbAstral, { rollMode: "selfroll" });
|
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);
|
2021-05-11 21:45:43 +02:00
|
|
|
astralData.valeursFausses.push({ actorId: request.id, nombreAstral: nbAstral });
|
2021-11-11 02:43:38 +01:00
|
|
|
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", this.listeNombreAstral);
|
2020-12-12 23:31:19 +01:00
|
|
|
}
|
|
|
|
request.nbAstral = nbAstral;
|
2021-11-26 00:45:21 +01:00
|
|
|
if (Misc.getActiveUser(request.userId)?.isGM) {
|
2021-03-14 16:02:31 +01:00
|
|
|
RdDUtility.responseNombreAstral(request);
|
|
|
|
} else {
|
2022-01-29 22:49:34 +01:00
|
|
|
game.socket.emit(SYSTEM_SOCKET_ID, {
|
2020-12-12 23:31:19 +01:00
|
|
|
msg: "msg_response_nombre_astral",
|
2021-03-14 16:02:31 +01:00
|
|
|
data: request
|
|
|
|
});
|
2020-12-12 23:31:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-05 21:35:43 +02:00
|
|
|
/* -------------------------------------------- */
|
2021-06-04 18:30:06 +02:00
|
|
|
findHeure(heure) {
|
2021-06-08 14:49:32 +02:00
|
|
|
heure = Grammar.toLowerCaseNoAccentNoSpace(heure);
|
2021-06-09 00:00:15 +02:00
|
|
|
let parHeureOuLabel = Object.values(heuresDef).filter(it => (it.heure + 1) == parseInt(heure) || Grammar.toLowerCaseNoAccentNoSpace(it.label) == heure);
|
2021-06-04 18:30:06 +02:00
|
|
|
if (parHeureOuLabel.length == 1) {
|
|
|
|
return parHeureOuLabel[0];
|
|
|
|
}
|
2021-06-05 21:35:43 +02:00
|
|
|
let parLabelPartiel = Object.values(heuresDef).filter(it => Grammar.toLowerCaseNoAccentNoSpace(it.label).includes(heure));
|
2021-06-09 00:00:15 +02:00
|
|
|
if (parLabelPartiel.length > 0) {
|
|
|
|
parLabelPartiel.sort(Misc.ascending(h => h.label.length));
|
2021-06-04 18:30:06 +02:00
|
|
|
return parLabelPartiel[0];
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
2021-10-11 11:09:30 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
getHeureNumber( hNum) {
|
|
|
|
let heure = Object.values(heuresDef).find(it => (it.heure) == hNum);
|
|
|
|
return heure
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
getHeuresChanceMalchance(heureNaissance) {
|
|
|
|
let heuresChancesMalchances = [];
|
|
|
|
let defHeure = this.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 ]};
|
|
|
|
}
|
|
|
|
return heuresChancesMalchances;
|
|
|
|
}
|
2021-06-04 18:30:06 +02:00
|
|
|
|
2020-12-11 16:19:19 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-06-04 18:30:06 +02:00
|
|
|
getAjustementAstrologique(heureNaissance, name = undefined) {
|
|
|
|
let defHeure = this.findHeure(heureNaissance);
|
|
|
|
if (defHeure) {
|
|
|
|
let hn = defHeure.heure;
|
2021-05-27 01:08:17 +02:00
|
|
|
let chiffreAstral = this.getCurrentNombreAstral() ?? 0;
|
2020-12-15 23:28:59 +01:00
|
|
|
let heureCourante = this.calendrier.heureRdD;
|
2021-06-09 00:00:15 +02:00
|
|
|
let ecartChance = (hn + chiffreAstral - heureCourante) % RDD_HEURES_PAR_JOUR;
|
2021-03-14 16:02:31 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2021-06-04 18:30:06 +02:00
|
|
|
else if (name) {
|
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
|
|
|
}
|
2021-06-09 00:00:15 +02:00
|
|
|
else {
|
|
|
|
ui.notifications.warn(heureNaissance + " ne correspond pas à une heure de naissance");
|
2021-06-04 18:30:06 +02:00
|
|
|
}
|
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) {
|
2022-11-05 18:06:30 +01:00
|
|
|
elmnt.style.bottom = undefined;
|
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-05-27 01:08:17 +02:00
|
|
|
updateDisplay() {
|
2022-09-07 18:47:56 +02:00
|
|
|
let calendrier = this.fillCalendrierData();
|
|
|
|
// Rebuild text du calendrier
|
2022-11-25 03:17:07 +01:00
|
|
|
let dateHTML = `${calendrier.jourMois} ${calendrier.nomMois} ${calendrier.annee} (${calendrier.nomSaison})`
|
2020-12-21 20:54:24 +01:00
|
|
|
if (game.user.isGM) {
|
2021-05-27 01:08:17 +02:00
|
|
|
dateHTML = dateHTML + " - NA: " + (this.getCurrentNombreAstral() ?? "indéterminé");
|
2021-03-14 16:02:31 +01:00
|
|
|
}
|
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")) {
|
2022-09-07 18:47:56 +02:00
|
|
|
heure.innerHTML = calendrier.nomHeure;
|
2021-03-14 16:02:31 +01:00
|
|
|
}
|
|
|
|
for (const minute of document.getElementsByClassName("calendar-time-disp")) {
|
2022-09-07 18:47:56 +02:00
|
|
|
minute.innerHTML = `${calendrier.minutesRelative} minutes`;
|
2021-03-14 16:02:31 +01:00
|
|
|
}
|
|
|
|
for (const heureImg of document.getElementsByClassName("calendar-heure-img")) {
|
2022-09-07 18:47:56 +02:00
|
|
|
heureImg.src = calendrier.iconHeure;
|
2020-12-21 20:54:24 +01:00
|
|
|
}
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-05-19 23:04:34 +02:00
|
|
|
async 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;
|
2021-07-09 01:01:12 +02:00
|
|
|
this.calendrier.moisRdD = RdDCalendrier.getChiffreFromSigne(calendrierData.moisKey);
|
2022-11-25 03:17:07 +01:00
|
|
|
this.calendrier.annee = Number(calendrierData.annee);
|
2021-07-09 01:01:12 +02:00
|
|
|
this.calendrier.heureRdD = RdDCalendrier.getChiffreFromSigne(calendrierData.heureKey);
|
2021-11-11 02:43:38 +01:00
|
|
|
game.settings.set(SYSTEM_RDD, "calendrier", duplicate(this.calendrier));
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2021-06-25 14:17:58 +02:00
|
|
|
await this.rebuildListeNombreAstral();
|
2021-06-09 00:00:15 +02:00
|
|
|
|
2022-01-29 22:49:34 +01:00
|
|
|
game.socket.emit(SYSTEM_SOCKET_ID, {
|
2021-06-01 20:54:27 +02:00
|
|
|
msg: "msg_sync_time",
|
|
|
|
data: duplicate(this.calendrier)
|
|
|
|
});
|
2020-12-08 21:40:41 +01:00
|
|
|
|
2021-05-27 01:08:17 +02:00
|
|
|
this.updateDisplay();
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
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) {
|
2021-07-09 01:01:12 +02:00
|
|
|
calendrierData.jourMoisOptions = RdDCalendrier.buildJoursMois();
|
2021-03-14 16:02:31 +01:00
|
|
|
calendrierData.heuresOptions = [0, 1];
|
2021-06-09 00:00:15 +02:00
|
|
|
calendrierData.minutesOptions = Array(RDD_MINUTES_PAR_HEURES).fill().map((item, index) => 0 + index);
|
2021-03-14 16:02:31 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-06-09 00:00:15 +02:00
|
|
|
static buildJoursMois() {
|
|
|
|
return Array(RDD_JOUR_PAR_MOIS).fill().map((item, index) => 1 + index);
|
|
|
|
}
|
|
|
|
|
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 = [];
|
2021-12-18 09:45:36 +01:00
|
|
|
this.listeNombreAstral = this.listeNombreAstral || [];
|
2021-03-14 16:02:31 +01:00
|
|
|
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);
|
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
|
|
|
}
|
2021-10-11 11:09:30 +02:00
|
|
|
let heuresParActeur = {};
|
|
|
|
for (let actor of game.actors) {
|
|
|
|
let heureNaissance = actor.getHeureNaissance();
|
|
|
|
if ( heureNaissance) {
|
|
|
|
heuresParActeur[actor.name] = this.getHeuresChanceMalchance(heureNaissance);
|
|
|
|
}
|
|
|
|
}
|
2020-12-11 08:29:24 +01:00
|
|
|
//console.log("ASTRO", astrologieArray);
|
|
|
|
calendrierData.astrologieData = astrologieArray;
|
2021-10-11 11:09:30 +02:00
|
|
|
calendrierData.heuresParActeur = heuresParActeur;
|
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-05-19 23:04:34 +02:00
|
|
|
async activateListeners(html) {
|
2020-12-08 21:40:41 +01:00
|
|
|
super.activateListeners(html);
|
|
|
|
|
2022-10-05 19:29:16 +02:00
|
|
|
this.updateDisplay();
|
2020-12-08 21:40:41 +01:00
|
|
|
|
2022-11-04 20:41:16 +01:00
|
|
|
html.find('.ajout-chronologie').click(ev => DialogChronologie.create());
|
|
|
|
|
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:
|
2022-11-05 18:06:30 +01:00
|
|
|
elmnt.style.bottom = undefined
|
2020-12-08 21:40:41 +01:00
|
|
|
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:
|
2022-11-05 18:06:30 +01:00
|
|
|
elmnt.onmousedown = undefined;
|
|
|
|
document.onmouseup = undefined;
|
|
|
|
document.onmousemove = undefined;
|
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) {
|
2021-11-11 02:43:38 +01:00
|
|
|
game.settings.set(SYSTEM_RDD, "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) {
|
2021-11-11 02:43:38 +01:00
|
|
|
game.settings.set(SYSTEM_RDD, "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
|
|
|
}
|