Ajout de la fenêtre de thème astral

Accessible par macro/depuis les fenêtres d'astrologie
This commit is contained in:
2023-03-07 02:28:10 +01:00
parent a810e20eca
commit 80579032ea
13 changed files with 290 additions and 48 deletions

View File

@ -1,3 +1,4 @@
import { ThemeAstral } from "./sommeil/theme-astral.js";
/**
* Extend the base Dialog entity by defining a custom window to perform roll.
@ -7,16 +8,17 @@ export class RdDAstrologieEditeur extends Dialog {
/* -------------------------------------------- */
constructor(html, calendrier, calendrierData) {
let myButtons = {
resetButton: { label: "Re-tirer les nombres astraux", callback: html => this.resetNombreAstraux() },
saveButton: { label: "Fermer", callback: html => {} }
let dialogConf = {
title: "Editeur d'Astrologie",
content: html,
default: "fermer",
buttons: {
fermer: { label: "Fermer", callback: html => { } }
}
};
// Common conf
let dialogConf = { content: html, title: "Editeur d'Astrologie", buttons: myButtons, default: "saveButton" };
let dialogOptions = {
classes: ["rdd-roll-dialog"], width: 600,
classes: ["rdd-roll-dialog"],
width: 600,
height: 'fit-content',
'max-height': 800,
'z-index': 99999
@ -30,6 +32,8 @@ export class RdDAstrologieEditeur extends Dialog {
activateListeners(html) {
super.activateListeners(html);
this.html = html;
this.html.find('[name="theme-astral"]').click(event => ThemeAstral.create());
this.html.find('[name="reset-nombres-astraux"]').click(event => this.resetNombreAstraux());
}
@ -39,6 +43,7 @@ export class RdDAstrologieEditeur extends Dialog {
await game.system.rdd.calendrier.rebuildListeNombreAstral();
game.system.rdd.calendrier.showAstrologieEditor();
this.close()
}
/* -------------------------------------------- */

View File

@ -1,6 +1,7 @@
import { RdDItemCompetence } from "./item-competence.js";
import { Misc } from "./misc.js";
import { SYSTEM_SOCKET_ID } from "./constants.js";
import { ThemeAstral } from "./sommeil/theme-astral.js";
/**
@ -49,9 +50,12 @@ export class RdDAstrologieJoueur extends Dialog {
this.html.find("[name='diffConditions']").val(0);
this.html.find('[name="jet-astrologie"]').click((event) => {
this.html.find('[name="jet-astrologie"]').click(event => {
this.requestJetAstrologie();
});
this.html.find('[name="theme-astral"]').click(event => {
ThemeAstral.create();
});
}
/* -------------------------------------------- */

View File

@ -257,6 +257,7 @@ export class RdDCalendrier extends Application {
}
this.listeNombreAstral = newList;
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", newList);
game.actors.forEach(actor => actor.deleteEmbeddedDocuments("Item", actor.listItems('nombreastral').map(it => it.id)));
}
}
@ -301,7 +302,7 @@ export class RdDCalendrier extends Application {
async positionnerHeure(heure) {
const indexDate = this.timestamp.indexDate;
const addDay = this.timestamp.heure < heure ? 0 : 1;
const newTimestamp = new RdDTimestamp({ indexDate: indexDate + addDay}).addHeures(heure);
const newTimestamp = new RdDTimestamp({ indexDate: indexDate + addDay }).addHeures(heure);
await this.setNewTimestamp(newTimestamp)
}
@ -370,10 +371,6 @@ export class RdDCalendrier extends Application {
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", this.listeNombreAstral);
}
static ecartHeureChance(heureNaissance, nombreAstral, heure) {
return (heureNaissance + nombreAstral - heure) % RDD_HEURES_PAR_JOUR;
}
/* -------------------------------------------- */
getAjustementAstrologique(heureNaissance, name = undefined) {
let defHeure = RdDTimestamp.findHeure(heureNaissance);
@ -399,6 +396,10 @@ export class RdDCalendrier extends Application {
return 0;
}
static ecartHeureChance(heureNaissance, nombreAstral, heure) {
return ((heureNaissance + nombreAstral - heure) % RDD_HEURES_PAR_JOUR + RDD_HEURES_PAR_JOUR) % RDD_HEURES_PAR_JOUR;
}
/* -------------------------------------------- */
getData() {
let formData = super.getData();

View File

@ -55,6 +55,7 @@ import { RdDFauneItemSheet } from "./item/sheet-faune.js";
import { RdDConteneurItemSheet } from "./item/sheet-conteneur.js";
import { RdDSigneDraconiqueItemSheet } from "./item/sheet-signedraconique.js";
import { RdDItemInventaireSheet } from "./item/sheet-base-inventaire.js";
import { ThemeAstral } from "./sommeil/theme-astral.js";
/**
* RdD system
@ -96,6 +97,8 @@ export class SystemReveDeDragon {
/* -------------------------------------------- */
async onInit() {
game.system.rdd = this;
this.ThemeAstral = ThemeAstral;
console.log(`Initializing Reve de Dragon System`);

View File

@ -195,17 +195,6 @@ export class RdDResolutionTable {
return Math.max(Math.floor(carac * (diff + 10) / 2), 1);
}
/* -------------------------------------------- */
static isAjustementAstrologique(rollData) {
if (rollData.selectedCarac?.label.toLowerCase().includes('chance')) {
return true;
}
if (rollData.selectedSort?.system.isrituel) {
return true;
}
return false;
}
/* -------------------------------------------- */
static isEchec(rollData) {
switch (rollData.surprise) {

View File

@ -48,8 +48,12 @@ const FORMULES_PERIODE = [
export class RdDTimestamp {
static hh(heure) {
return heure < 9 ? `0${heure + 1}` : `${heure + 1}`;
}
static iconeHeure(heure) {
return `systems/foundryvtt-reve-de-dragon/icons/heures/hd${heure < 9 ? '0' : ''}${heure + 1}.svg`;
return `systems/foundryvtt-reve-de-dragon/icons/heures/hd${RdDTimestamp.hh(heure)}.svg`;
}
static init() {
@ -63,6 +67,7 @@ export class RdDTimestamp {
for (let i = 0; i < DEFINITION_HEURES.length; i++) {
DEFINITION_HEURES[i].heure = i;
DEFINITION_HEURES[i].hh = RdDTimestamp.hh(i);
DEFINITION_HEURES[i].icon = RdDTimestamp.iconeHeure(i);
DEFINITION_HEURES[i].webp = DEFINITION_HEURES[i].icon.replace(".svg", ".webp");
}
@ -86,6 +91,9 @@ export class RdDTimestamp {
return definition
}
static definitions() {
return DEFINITION_HEURES
}
static formulesDuree() {
return FORMULES_DUREE
}

View File

@ -0,0 +1,58 @@
import { Misc } from "../misc.js";
import { RdDCalendrier } from "../rdd-calendrier.js";
import { RdDTimestamp } from "../rdd-timestamp.js";
export class ThemeAstral extends Application {
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
template: "systems/foundryvtt-reve-de-dragon/templates/sommeil/theme-astral.hbs",
title: "Thème astral",
width: 'fit-content',
height: 'fit-content',
popOut: true,
resizable: false
});
}
static async create() {
new ThemeAstral().render(true);
}
constructor() {
super({});
}
activateListeners(html) {
super.activateListeners(html);
this.html = html;
this.html.find('select[name="signe-astral"]').change(event => {
this.onCalculThemeAstral();
})
this.html.find('select[name="signe-naissance"]').change(event => {
this.onCalculThemeAstral();
})
this.onCalculThemeAstral();
}
onCalculThemeAstral() {
const signeAstral = RdDTimestamp.definition(this.html.find('select[name="signe-astral"]').val())
const chiffreAstral = signeAstral.heure + 1;
const signeNaissance = RdDTimestamp.definition(this.html.find('select[name="signe-naissance"]').val())
const heureNaissance = signeNaissance.heure + 1;
const heureChance = (chiffreAstral + heureNaissance) % 12 + 1
RdDTimestamp.definitions().forEach(dh => {
const ajustement = RdDCalendrier.ajustementAstrologiqueHeure(heureNaissance, chiffreAstral, dh.heure + 1);
const txtAjustement = ajustement == 0 ? '' : Misc.toSignedString(ajustement);
this.html.find(`div.astro-ajustement.ajustement-${dh.hh}`).text(txtAjustement)
});
const angle = (heureChance * 30 + 330) % 360;
const rotation = `rotate(${angle}deg)`;
this.html.find(`div.astro-roue div.astro-disque img`).css({
'transform': rotation,
'-ms-transform': rotation,
'-moz-transform': rotation,
'-webkit-transform': rotation,
'-o-transform': rotation
});
}
}