This commit is contained in:
sladecraven 2020-12-11 08:29:24 +01:00
parent e74031be0b
commit 349f8fc875
13 changed files with 165 additions and 47 deletions

View File

@ -271,6 +271,10 @@ export class RdDActorSheet extends ActorSheet {
this.actor.rollAppelChance(); this.actor.rollAppelChance();
}); });
html.find('#jet-astrologie').click((event) => {
this.actor.astrologieNombresAstraux();
});
// Roll Skill // Roll Skill
html.find('.competence-label a').click((event) => { html.find('.competence-label a').click((event) => {
let compName = event.currentTarget.text; let compName = event.currentTarget.text;

View File

@ -10,7 +10,7 @@ import { RdDRollDialogEthylisme } from "./rdd-roll-ethylisme.js";
import { RdDRoll } from "./rdd-roll.js"; import { RdDRoll } from "./rdd-roll.js";
import { RdDTMRDialog } from "./rdd-tmr-dialog.js"; import { RdDTMRDialog } from "./rdd-tmr-dialog.js";
import { Misc } from "./misc.js"; import { Misc } from "./misc.js";
import { RdDAstrologieJoueur } from "./rdd-astrologie-joueur.js";
import { RdDResolutionTable } from "./rdd-resolution-table.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js";
import { RdDDice } from "./rdd-dice.js"; import { RdDDice } from "./rdd-dice.js";
import { RdDRollTables } from "./rdd-rolltables.js"; import { RdDRollTables } from "./rdd-rolltables.js";
@ -1257,6 +1257,7 @@ export class RdDActor extends Actor {
}; };
} }
/* -------------------------------------------- */
async _appliquerAjoutExperience(rollData) { async _appliquerAjoutExperience(rollData) {
// TODO: si pas de compétence, minimum 1 pour carac // TODO: si pas de compétence, minimum 1 pour carac
// TODO: appliquer l'expérience automatiquement // TODO: appliquer l'expérience automatiquement
@ -1441,20 +1442,18 @@ export class RdDActor extends Actor {
} }
console.log("rollCompetence !!!", rollData.competence); console.log("rollCompetence !!!", rollData.competence);
const dialog = await RdDRoll.create(this, rollData, const dialog = await RdDRoll.create(this, rollData, {html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html'}, {
{html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html'},
{
name: 'jet-competence', name: 'jet-competence',
label: 'Jet ' +Grammar.apostrophe('de', name), label: 'Jet ' +Grammar.apostrophe('de', name),
callbacks: [ callbacks: [
this._createCallbackExperience(), this._createCallbackExperience(),
{ action: this._competenceResult } { action: this._competenceResult }
] ]
} } );
);
dialog.render(true); dialog.render(true);
} }
/* -------------------------------------------- */
_competenceResult(rollData) { _competenceResult(rollData) {
ChatUtility.chatWithRollMode({ ChatUtility.chatWithRollMode({
content: "<strong>Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong>" content: "<strong>Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong>"
@ -1486,6 +1485,7 @@ export class RdDActor extends Actor {
dialog.render(true); dialog.render(true);
} }
/* -------------------------------------------- */
_appelChanceResult(rollData) { _appelChanceResult(rollData) {
const message = { const message = {
user: game.user._id, user: game.user._id,
@ -1512,6 +1512,13 @@ export class RdDActor extends Actor {
return 0; return 0;
} }
/* -------------------------------------------- */
astrologieNombresAstraux( ) {
// Afficher l'interface spéciale
const myDialog = RdDAstrologieJoueur.create( this, {} );
myDialog.render(true);
}
/* -------------------------------------------- */ /* -------------------------------------------- */
getCaracByName(caracName) { getCaracByName(caracName) {
switch (caracName) switch (caracName)
@ -1580,6 +1587,7 @@ export class RdDActor extends Actor {
} }
/* -------------------------------------------- */
async rollCompetenceCreature( compName ) { async rollCompetenceCreature( compName ) {
let competence = RdDUtility.findCompetence( this.data.items, compName); let competence = RdDUtility.findCompetence( this.data.items, compName);

View File

@ -9,6 +9,7 @@ export class ChatUtility {
ChatUtility.createChatMessage(chatOptions, rollMode, name); ChatUtility.createChatMessage(chatOptions, rollMode, name);
} }
/* -------------------------------------------- */
static createChatMessage( chatOptions, rollMode, name) { static createChatMessage( chatOptions, rollMode, name) {
switch (rollMode) { switch (rollMode) {
case "blindroll": // GM only case "blindroll": // GM only
@ -29,6 +30,7 @@ export class ChatUtility {
ChatMessage.create(chatOptions); ChatMessage.create(chatOptions);
} }
/* -------------------------------------------- */
static prepareChatMessage( rollMode, name) { static prepareChatMessage( rollMode, name) {
return { return {
user: game.user._id, user: game.user._id,
@ -36,6 +38,7 @@ export class ChatUtility {
} }
} }
/* -------------------------------------------- */
static getWhisperRecipients( rollMode, name) { static getWhisperRecipients( rollMode, name) {
switch (rollMode) { switch (rollMode) {
case "blindroll": return ChatUtility.getUsers(user => user.isGM); case "blindroll": return ChatUtility.getUsers(user => user.isGM);
@ -45,15 +48,18 @@ export class ChatUtility {
return undefined; return undefined;
} }
/* -------------------------------------------- */
static getWhisperRecipientsAndGMs(name) { static getWhisperRecipientsAndGMs(name) {
return ChatMessage.getWhisperRecipients(name) return ChatMessage.getWhisperRecipients(name)
.concat(this.getUsers(user => user.isGM)); .concat(this.getUsers(user => user.isGM));
} }
/* -------------------------------------------- */
static getUsers(filter) { static getUsers(filter) {
return game.users.filter(filter).map(user => user.data._id); return game.users.filter(filter).map(user => user.data._id);
} }
/* -------------------------------------------- */
static blindMessageToGM(chatOptions) { static blindMessageToGM(chatOptions) {
let chatGM = duplicate(chatOptions); let chatGM = duplicate(chatOptions);
chatGM.whisper = ChatUtility.getUsers(user => user.isGM); chatGM.whisper = ChatUtility.getUsers(user => user.isGM);
@ -62,6 +68,7 @@ export class ChatUtility {
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_gm_chat_message", data: chatGM }); game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_gm_chat_message", data: chatGM });
} }
/* -------------------------------------------- */
static handleGMChatMessage(data) { static handleGMChatMessage(data) {
console.log("blindMessageToGM", data); console.log("blindMessageToGM", data);
if (game.user.isGM) { // message privé pour GM only if (game.user.isGM) { // message privé pour GM only

View File

@ -10,12 +10,12 @@ export class RdDAstrologieEditeur extends Dialog {
constructor(html, calendrier, calendrierData) { constructor(html, calendrier, calendrierData) {
let myButtons = { let myButtons = {
saveButton: { label: "Enregistrer", callback: html => this.fillData() } saveButton: { label: "Fermer", callback: html => this.fillData() }
}; };
// Common conf // Common conf
let dialogConf = { content: html, title: "Editeur d'Astrologie", buttons: myButtons, default: "saveButton" }; let dialogConf = { content: html, title: "Editeur d'Astrologie", buttons: myButtons, default: "saveButton" };
let dialogOptions = { classes: ["rdddialog"], width: 800, height: 300, 'z-index': 99999 } let dialogOptions = { classes: ["rdddialog"], width: 600, height: 300, 'z-index': 99999 }
super(dialogConf, dialogOptions) super(dialogConf, dialogOptions)
this.calendrier = calendrier; this.calendrier = calendrier;

View File

@ -0,0 +1,53 @@
import { Misc } from "./misc.js";
/**
* Extend the base Dialog entity by defining a custom window to perform roll.
* @extends {Dialog}
*/
export class RdDAstrologieJoueur extends Dialog {
/* -------------------------------------------- */
static async create(actor, dialogConfig) {
let data = { nombres: actor.data.items.filter( (item) => item.type == 'nombreastral')
}
const html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-astrologie-joueur.html', data);
let options = { classes: ["rdddialog"], width: 600, height: 500, 'z-index': 99999 };
if (dialogConfig.options) {
mergeObject(options, dialogConfig.options, { overwrite: true })
}
return new RdDAstrologieJoueur(html, actor, data);
}
/* -------------------------------------------- */
constructor(html, actor, data ) {
let myButtons = {
saveButton: { label: "Fermer", callback: html => this.fillData() }
};
// Get all n
// Common conf
let dialogConf = { content: html, title: "Nombres Astraux", buttons: myButtons, default: "saveButton" };
let dialogOptions = { classes: ["rdddialog"], width: 600, height: 300, 'z-index': 99999 } ;
super(dialogConf, dialogOptions);
this.actor = actor;
this.dataNombreAstral = duplicate(data);
}
/* -------------------------------------------- */
fillData() {
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
$(function () {
});
}
}

View File

@ -23,7 +23,7 @@ const saisonsDef = { "printemps": { label: "Printemps"},
"hiver": { label: "Hiver"} "hiver": { label: "Hiver"}
}; };
const RDD_JOUR_PAR_MOIS = 28; const RDD_JOUR_PAR_MOIS = 28;
const MAX_NOMBRE_ASTRAL = 30; const MAX_NOMBRE_ASTRAL = 12;
/* -------------------------------------------- */ /* -------------------------------------------- */
export class RdDCalendrier extends Application { export class RdDCalendrier extends Application {
@ -38,7 +38,7 @@ export class RdDCalendrier extends Application {
this.calendrier.heuresRelative = 0; this.calendrier.heuresRelative = 0;
this.calendrier.minutesRelative = 0; this.calendrier.minutesRelative = 0;
this.calendrier.moisRdD = 0; // Index dans heuresList this.calendrier.moisRdD = 0; // Index dans heuresList
this.calendrier.jour = 1; this.calendrier.jour = 0;
if ( game.user.isGM) { // Uniquement si GM if ( game.user.isGM) { // Uniquement si GM
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", this.calendrier ); game.settings.set("foundryvtt-reve-de-dragon", "calendrier", this.calendrier );
} }
@ -72,9 +72,9 @@ export class RdDCalendrier extends Application {
/* -------------------------------------------- */ /* -------------------------------------------- */
getDateFromIndex( index ) { getDateFromIndex( index ) {
let month = Math.ceil(index / 28); let month = Math.floor(index / 28);
let day = index - (month*28); let day = (index - (month*28)) + 1;
return day+"/"+heuresList[month]; return day+" "+heuresList[month];
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -94,29 +94,34 @@ export class RdDCalendrier extends Application {
/* -------------------------------------------- */ /* -------------------------------------------- */
getCurrentNombreAstral() { getCurrentNombreAstral() {
let index = this.getCurrentDayIndex(); let index = this.getCurrentDayIndex();
return this.listeNombreAstral[index].nombreAstral; let astralData = this.listeNombreAstral.find( (nombreAstral, i) => nombreAstral.index == index );
return astralData.nombreAstral || "N/A";
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
rebuildListeNombreAstral() { rebuildListeNombreAstral() {
// Auto-create if needed // Auto-create if needed
if ( this.listeNombreAstral == undefined) if ( this.listeNombreAstral == undefined)
this.listeNombreAstral = {}; this.listeNombreAstral = [];
// Nettoyage des nombres astraux anciens // Nettoyage des nombres astraux anciens
let jourCourant = this.getCurrentDayIndex(); let jourCourant = this.getCurrentDayIndex();
let keys = Object.keys(this.listeNombreAstral); let newList = this.listeNombreAstral.filter( (nombreAstral, i) => nombreAstral.index >= jourCourant );
for ( let jourIndex of keys) { //console.log("LSTES", this.listeNombreAstral, newList );
if ( Number(jourIndex) < jourCourant) {
this.listeNombreAstral[jourIndex] = undefined; let lastDay = jourCourant;
} for (let i=0; i < MAX_NOMBRE_ASTRAL; i++) {
} let nombreAstral = newList[i];
// A partir du jour courant, génération des nombres avec gestion des trous potentiels if ( nombreAstral ) {
for (let jourIndex = jourCourant; jourIndex<jourCourant+MAX_NOMBRE_ASTRAL; jourIndex++) { lastDay = nombreAstral.index + 1;
if ( this.listeNombreAstral[jourIndex] == undefined) { } else {
this.listeNombreAstral[jourIndex] = this.ajouterNombreAstral(jourIndex); newList.push( this.ajouterNombreAstral( lastDay) );
lastDay += 1;
} }
} }
this.listeNombreAstral = newList;
game.settings.set("foundryvtt-reve-de-dragon", "liste-nombre-astral", this.listeNombreAstral ); game.settings.set("foundryvtt-reve-de-dragon", "liste-nombre-astral", this.listeNombreAstral );
} }
@ -147,14 +152,14 @@ export class RdDCalendrier extends Application {
/* -------------------------------------------- */ /* -------------------------------------------- */
incrementerJour( ) { incrementerJour( ) {
this.calendrier.jour += 1; this.calendrier.jour += 1;
if ( this.calendrier.jour > RDD_JOUR_PAR_MOIS) { if ( this.calendrier.jour >= RDD_JOUR_PAR_MOIS) {
this.calendrier.jour -= RDD_JOUR_PAR_MOIS; this.calendrier.jour -= RDD_JOUR_PAR_MOIS;
if ( this.calendrier.jour <= 0) if ( this.calendrier.jour <= 0)
this.calendrier.jour = 1; this.calendrier.jour = 0;
this.calendrier.moisRdD += 1; this.calendrier.moisRdD += 1;
// Reconstruire les nombres astraux // Reconstruire les nombres astraux
this.rebuildListeNombreAstral();
} }
this.rebuildListeNombreAstral();
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -181,7 +186,7 @@ export class RdDCalendrier extends Application {
data.heureKey = heureKey; data.heureKey = heureKey;
data.moisKey = moisKey; data.moisKey = moisKey;
data.nomMois = heuresDef[moisKey].label; // heures et mois nommés identiques data.nomMois = heuresDef[moisKey].label; // heures et mois nommés identiques
data.jourMois = this.calendrier.jour; data.jourMois = this.calendrier.jour + 1;
data.nomHeure = heuresDef[heureKey].label; data.nomHeure = heuresDef[heureKey].label;
data.nomSaison = saisonsDef[heuresDef[moisKey].saison].label; data.nomSaison = saisonsDef[heuresDef[moisKey].saison].label;
data.heuresRelative = this.calendrier.heuresRelative; data.heuresRelative = this.calendrier.heuresRelative;
@ -238,7 +243,7 @@ export class RdDCalendrier extends Application {
saveEditeur( calendrierData ) { saveEditeur( calendrierData ) {
this.calendrier.heuresRelative = Number(calendrierData.heuresRelative); this.calendrier.heuresRelative = Number(calendrierData.heuresRelative);
this.calendrier.minutesRelative = Number(calendrierData.minutesRelative); this.calendrier.minutesRelative = Number(calendrierData.minutesRelative);
this.calendrier.jour = Number(calendrierData.jourMois); this.calendrier.jour = Number(calendrierData.jourMois) - 1;
this.calendrier.moisRdD = heuresList.findIndex(mois => mois === calendrierData.moisKey); this.calendrier.moisRdD = heuresList.findIndex(mois => mois === calendrierData.moisKey);
this.calendrier.heureRdD = heuresList.findIndex(heure => heure === calendrierData.heureKey);; // Index dans heuresList this.calendrier.heureRdD = heuresList.findIndex(heure => heure === calendrierData.heureKey);; // Index dans heuresList
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier) ); game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier) );
@ -264,18 +269,18 @@ export class RdDCalendrier extends Application {
/* -------------------------------------------- */ /* -------------------------------------------- */
async showAstrologieEditor() { async showAstrologieEditor() {
let calendrierData = duplicate( this.fillCalendrierData( ) ); let calendrierData = duplicate( this.fillCalendrierData( ) );
calendrierData.astrologieData = duplicate( this.listeNombreAstral ); let astrologieArray = [];
for (let index in calendrierData.astrologieData ) { for (let astralData of this.listeNombreAstral ) {
let astralData = calendrierData.astrologieData[index]; astralData.humanDate = this.getDateFromIndex( astralData.index );
astralData.humanDate = this.getDateFromIndex( index ); astrologieArray.push( duplicate(astralData ) );
} }
if ( this.astrologieEditeur == undefined ) { //console.log("ASTRO", astrologieArray);
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/calendar-astrologie-template.html', calendrierData ); calendrierData.astrologieData = astrologieArray;
this.astrologieEditeur = new RdDAstrologieEditeur(html, this, calendrierData ) let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/calendar-astrologie-template.html', calendrierData );
} let astrologieEditeur = new RdDAstrologieEditeur(html, this, calendrierData )
this.astrologieEditeur.updateData( calendrierData ); astrologieEditeur.updateData( calendrierData );
this.astrologieEditeur.render(true); astrologieEditeur.render(true);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -7,9 +7,10 @@ import { RdDResolutionTable } from "./rdd-resolution-table.js";
* Extend the base Dialog entity to select roll parameters * Extend the base Dialog entity to select roll parameters
* @extends {Dialog} * @extends {Dialog}
*/ */
/* -------------------------------------------- */
export class RdDRoll extends Dialog { export class RdDRoll extends Dialog {
/* -------------------------------------------- */
static async create(actor, rollData, dialogConfig, ...actions) { static async create(actor, rollData, dialogConfig, ...actions) {
RdDRoll._ensureCorrectActions(actions); RdDRoll._ensureCorrectActions(actions);
@ -24,6 +25,7 @@ export class RdDRoll extends Dialog {
return new RdDRoll(actor, rollData, html, options, actions); return new RdDRoll(actor, rollData, html, options, actions);
} }
/* -------------------------------------------- */
static _setDefaultOptions(actor, rollData) { static _setDefaultOptions(actor, rollData) {
mergeObject(rollData, mergeObject(rollData,
@ -45,6 +47,7 @@ export class RdDRoll extends Dialog {
{ overwrite: false }); { overwrite: false });
} }
/* -------------------------------------------- */
static _ensureCorrectActions(actions) { static _ensureCorrectActions(actions) {
if (actions.length == 0) { if (actions.length == 0) {
throw 'No action defined'; throw 'No action defined';
@ -56,6 +59,7 @@ export class RdDRoll extends Dialog {
}); });
} }
/* -------------------------------------------- */
constructor(actor, rollData, html, options, actions) { constructor(actor, rollData, html, options, actions) {
let conf = { let conf = {
title: actions[0].label, title: actions[0].label,
@ -73,9 +77,9 @@ export class RdDRoll extends Dialog {
this.rollData = rollData; this.rollData = rollData;
} }
/* -------------------------------------------- */
async onAction(action, html) { async onAction(action, html) {
await RdDResolutionTable.rollData(this.rollData); await RdDResolutionTable.rollData(this.rollData);
console.log("RdDRoll -=>", this.rollData, this.rollData.rolled); console.log("RdDRoll -=>", this.rollData, this.rollData.rolled);
if (action.callbacks) if (action.callbacks)

View File

@ -178,6 +178,7 @@ export class RdDUtility {
'systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html',
'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-surenc.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-surenc.html',
'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-natation.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-natation.html',
'systems/foundryvtt-reve-de-dragon/templates/dialog-astrologie-joueur.html',
// Calendrier // Calendrier
'systems/foundryvtt-reve-de-dragon/templates/calendar-template.html', 'systems/foundryvtt-reve-de-dragon/templates/calendar-template.html',
'systems/foundryvtt-reve-de-dragon/templates/calendar-editor-template.html', 'systems/foundryvtt-reve-de-dragon/templates/calendar-editor-template.html',

View File

@ -687,6 +687,7 @@
}, },
"nombreastral": { "nombreastral": {
"value": 0, "value": 0,
"istrue": false,
"jourindex": 1 "jourindex": 1
}, },
"monnaie": { "monnaie": {

View File

@ -540,6 +540,9 @@
{{/if}} {{/if}}
</span> </span>
</li> </li>
<li class="item flexrow" >
<span class="competence-label"><a id="jet-astrologie">Astrologie : Nombres Astraux</a></span>
</li>
</ul> </ul>
</div> </div>
<div> <div>

View File

@ -9,13 +9,18 @@
<section class="sheet-body"> <section class="sheet-body">
<div class="form-group"> <div class="form-group">
<label for="astralList">Nombres Astraux</label> <label for="astralList">Nombres Astraux</label>
<table> <table border=1>
<tr> <tr>
{{#each astrologieData as |nombreData key|}} {{#each astrologieData as |nombreData key|}}
<td>{{nombreData.humanDate}} - {{nombreData.nombreAstral}}</td> <td align="center">{{nombreData.humanDate}}</td>
{{/each}} {{/each}}
</tr> </tr>
</table> <tr>
{{#each astrologieData as |nombreData key|}}
<td align="center">{{nombreData.nombreAstral}}</td>
{{/each}}
</tr>
</table>
</div> </div>
</section> </section>

View File

@ -0,0 +1,27 @@
<form class="{{cssClass}}" autocomplete="off">
<header class="sheet-header">
<div class="header-fields">
<h1 class="charname">Astrologie</h1>
</div>
</header>
{{!-- Sheet Body --}}
<section class="sheet-body">
<div class="form-group">
<label for="astralList">Nombres Astraux</label>
<table border=1>
<tr>
{{#each astrologieData as |nombreData key|}}
<td align="center">{{nombreData.humanDate}}</td>
{{/each}}
</tr>
<tr>
{{#each astrologieData as |nombreData key|}}
<td align="center">{{nombreData.nombreAstral}}</td>
{{/each}}
</tr>
</table>
</div>
</section>
</form>