Table d'astrologie avec toutes les heures

This commit is contained in:
Vincent Vandemeulebrouck 2023-01-09 23:20:51 +01:00
parent 7e75715d88
commit f4f2db68e0
3 changed files with 92 additions and 68 deletions

View File

@ -210,15 +210,10 @@ export class RdDCalendrier extends Application {
}
}
/* -------------------------------------------- */
getCurrentNombreAstral() {
return this.getNombreAstral(this.timestamp.indexDate);
}
/* -------------------------------------------- */
resetNombreAstral() {
this.listeNombreAstral = [];
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", this.listeNombreAstral);
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", []);
game.socket.emit(SYSTEM_SOCKET_ID, {
msg: "msg_reset_nombre_astral",
@ -227,10 +222,19 @@ export class RdDCalendrier extends Application {
}
/* -------------------------------------------- */
getNombreAstral(indexDate) {
/**
*
* @param {*} indexDate la date pour laquelle obtenir le nombre astral. Si undefined, on prend la date du jour
* @returns le nombre astral pour la date, ou pour la date du jour si la date n'est pas fournie.
* Si aucun nombre astral n'est trouvé, retourne 0 (cas où l'on demanderait un nombre astral en dehors des 12 jours courant et à venir)
*/
getNombreAstral(indexDate = undefined) {
if (indexDate == undefined) {
indexDate = this.timestamp.indexDate;
}
const listNombreAstral = this.getListeNombreAstral();
let astralData = listNombreAstral.find((nombreAstral, i) => nombreAstral.index == indexDate);
return astralData?.nombreAstral;
return astralData?.nombreAstral ?? 0;
}
/* -------------------------------------------- */
@ -289,8 +293,9 @@ export class RdDCalendrier extends Application {
const indexDate = this.timestamp.indexDate;
const addDay = this.timestamp.heure < heure ? 0 : 1;
await this.setNewTimestamp(new RdDTimestamp({
indexDate: indexDate + addDay, indexHeure: 0 })
.addHeures(heure))
indexDate: indexDate + addDay, indexHeure: 0
})
.addHeures(heure))
}
/* -------------------------------------------- */
@ -358,38 +363,15 @@ export class RdDCalendrier extends Application {
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", this.listeNombreAstral);
}
getHeureChance(heure) {
return heure + (this.getCurrentNombreAstral() ?? 0);
}
/* -------------------------------------------- */
getHeuresChanceMalchance(heureNaissance) {
let defHeure = RdDTimestamp.findHeure(heureNaissance);
if (defHeure) {
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 [];
static ecartHeureChance(heureNaissance, nombreAstral, heure) {
return (heureNaissance + nombreAstral - heure) % RDD_HEURES_PAR_JOUR;
}
/* -------------------------------------------- */
getAjustementAstrologique(heureNaissance, name = undefined) {
let defHeure = RdDTimestamp.findHeure(heureNaissance);
if (defHeure) {
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;
case 6: return -4;
case 3: case 9: return -2;
}
return RdDCalendrier.ajustementAstrologiqueHeure(defHeure.heure, this.getNombreAstral(), this.timestamp.heure);
}
else if (name) {
ui.notifications.warn(name + " n'a pas d'heure de naissance, ou elle est incorrecte : " + heureNaissance);
@ -400,6 +382,16 @@ export class RdDCalendrier extends Application {
return 0;
}
static ajustementAstrologiqueHeure(hn, nbAstral, heure) {
switch (RdDCalendrier.ecartHeureChance(hn, nbAstral, heure)) {
case 0: return 4;
case 4: case 8: return 2;
case 6: return -4;
case 3: case 9: return -2;
}
return 0;
}
/* -------------------------------------------- */
getData() {
let formData = super.getData();
@ -434,7 +426,7 @@ export class RdDCalendrier extends Application {
// Rebuild text du calendrier
let dateHTML = `${calendrier.jourDuMois} ${calendrier.mois.label} (${calendrier.mois.saison}) de l'année ${calendrier.annee}`
if (game.user.isGM) {
dateHTML = dateHTML + "<br>Nombre Astral: " + (this.getCurrentNombreAstral() ?? "?");
dateHTML = dateHTML + "<br>Nombre Astral: " + (this.getNombreAstral() ?? "?");
}
for (let handle of document.getElementsByClassName("calendar-date-rdd")) {
handle.innerHTML = dateHTML;
@ -490,13 +482,21 @@ export class RdDCalendrier extends Application {
return astro;
});
calendrierData.heuresParActeur = {};
game.actors.filter(it => it.isPersonnage() && it.hasPlayerOwner).forEach(actor => {
let heureNaissance = actor.getHeureNaissance();
if (heureNaissance) {
calendrierData.heuresParActeur[actor.name] = this.getHeuresChanceMalchance(heureNaissance);
const nbAstral = this.getNombreAstral()
calendrierData.heures = Array.from(Array(RDD_HEURES_PAR_JOUR).keys());
calendrierData.ajustementsActeur = game.actors.filter(it => it.isPersonnage() && it.hasPlayerOwner).map(actor => {
return {
actor,
ajustements: calendrierData.heures.map(heure => {
const hn = RdDTimestamp.findHeure(actor.getHeureNaissance())?.heure;
return {
heure,
ajustement: RdDCalendrier.ajustementAstrologiqueHeure(hn, nbAstral, heure)
}
})
}
})
});
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);

View File

@ -482,6 +482,9 @@ input:is(.blessure-premiers_soins, .blessure-soins_complets) {
max-height: 1.5em;
border-width: 0;
}
div.dimmed .img-signe-heure {
opacity: 50%;
}
.button-effect-img {
vertical-align: baseline;
max-width: 16px;
@ -1199,15 +1202,25 @@ div.competence-column div.categorie-competence{
}
/* ======================================== */
.table-nombres-astraux {
border:1;
table.table-nombres-astraux {
border: 2px solid rgba(0, 0, 0, 0.8);
}
table.table-nombres-astraux th >td {
font-size: 1rem;
}
table.table-nombres-astraux tr >td {
font-size: 0.8rem;
}
.table-nombres-astraux td {
border: 1px solid black;
table.table-nombres-astraux :is(tr, th, td) {
border-style: solid;
border-width: 1px;
border-color: rgba(102, 95, 122, 0.2);
text-align: center;
vertical-align: top;
}
table.table-nombres-astraux tr:hover {
background-color: hsla(38, 20%, 50%, 0.5);
}
/* ======================================== */
.tokenhudext {

View File

@ -8,16 +8,16 @@
<section class="sheet-body">
<div class="form-group">
<table class='table-nombres-astraux'>
<tr class='table-nombres-astraux-td'>
<tr>
<th>Date</th>
{{#each astrologieData as |nombreData key|}}
<td class='table-nombres-astraux-td'>{{nombreData.date.jour}}{{timestamp-imgSigneHeure nombreData.date.mois}}</td>
<th>{{nombreData.date.jour}}{{timestamp-imgSigneHeure nombreData.date.mois}}</th>
{{/each}}
</tr>
<tr class='table-nombres-astraux-td'>
<tr>
<th>Nombre astral</th>
{{#each astrologieData as |nombreData key|}}
<td class='table-nombres-astraux-td'>
<td>
<ol>
<b>{{nombreData.nombreAstral}}</b>
{{#each nombreData.valeursFausses as |fausseVal key|}}
@ -30,24 +30,35 @@
</table>
</div>
<div>
<ul class="alterne-list">
{{#each heuresParActeur as |heuresDef name|}}
<li class="list-item flexrow">
<span><strong>{{name}}</strong>:</span>
<span class="flex-grow-2">
|{{#each heuresDef as |ajustement|}}
<span>
<strong>{{ajustement.ajustement}}</strong>
{{#each ajustement.heures as |heure|}}
{{timestamp-imgSigneHeure heure}}
{{/each}}
|
</span>
{{/each}}
</span>
</li>
<table class='table-nombres-astraux'>
<tr>
<th></th>
{{#each heures as |heure|}}
<th>
{{timestamp-imgSigneHeure heure}}
</th>
{{/each}}
</tr>
{{#each ajustementsActeur as |ajustementActeur|}}
<tr>
<td>
<img class="img-signe-heure" src="{{actor.img}}" title="{{actor.name}}" />
{{actor.name}}
</td>
{{#each ajustementActeur.ajustements as |ajustement|}}
<td>{{#if (ne ajustement.ajustement 0)}}
<strong>
{{numberFormat ajustement.ajustement decimals=0 sign=true}}
</strong>
{{else}}
<div class="dimmed">
{{timestamp-imgSigneHeure ajustement.heure}}
</div>
{{/if}}</td>
{{/each}}
</tr>
{{/each}}
</ul>
</table>
</div>
</section>
</form>