diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 6417eb88..70d482bf 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -271,6 +271,10 @@ export class RdDActorSheet extends ActorSheet { this.actor.rollAppelChance(); }); + html.find('#jet-astrologie').click((event) => { + this.actor.astrologieNombresAstraux(); + }); + // Roll Skill html.find('.competence-label a').click((event) => { let compName = event.currentTarget.text; diff --git a/module/actor.js b/module/actor.js index d2419f50..ac3acad8 100644 --- a/module/actor.js +++ b/module/actor.js @@ -10,7 +10,7 @@ import { RdDRollDialogEthylisme } from "./rdd-roll-ethylisme.js"; import { RdDRoll } from "./rdd-roll.js"; import { RdDTMRDialog } from "./rdd-tmr-dialog.js"; import { Misc } from "./misc.js"; - +import { RdDAstrologieJoueur } from "./rdd-astrologie-joueur.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js"; import { RdDDice } from "./rdd-dice.js"; import { RdDRollTables } from "./rdd-rolltables.js"; @@ -1257,6 +1257,7 @@ export class RdDActor extends Actor { }; } + /* -------------------------------------------- */ async _appliquerAjoutExperience(rollData) { // TODO: si pas de compétence, minimum 1 pour carac // TODO: appliquer l'expérience automatiquement @@ -1441,20 +1442,18 @@ export class RdDActor extends Actor { } console.log("rollCompetence !!!", rollData.competence); - const dialog = await RdDRoll.create(this, rollData, - {html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html'}, - { + const dialog = await RdDRoll.create(this, rollData, {html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html'}, { name: 'jet-competence', label: 'Jet ' +Grammar.apostrophe('de', name), callbacks: [ this._createCallbackExperience(), { action: this._competenceResult } ] - } - ); + } ); dialog.render(true); } + /* -------------------------------------------- */ _competenceResult(rollData) { ChatUtility.chatWithRollMode({ content: "Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "" @@ -1486,6 +1485,7 @@ export class RdDActor extends Actor { dialog.render(true); } + /* -------------------------------------------- */ _appelChanceResult(rollData) { const message = { user: game.user._id, @@ -1512,6 +1512,13 @@ export class RdDActor extends Actor { return 0; } + /* -------------------------------------------- */ + astrologieNombresAstraux( ) { + // Afficher l'interface spéciale + const myDialog = RdDAstrologieJoueur.create( this, {} ); + myDialog.render(true); + } + /* -------------------------------------------- */ getCaracByName(caracName) { switch (caracName) @@ -1580,6 +1587,7 @@ export class RdDActor extends Actor { } + /* -------------------------------------------- */ async rollCompetenceCreature( compName ) { let competence = RdDUtility.findCompetence( this.data.items, compName); diff --git a/module/chat-utility.js b/module/chat-utility.js index 0a7c2b50..0836f269 100644 --- a/module/chat-utility.js +++ b/module/chat-utility.js @@ -9,6 +9,7 @@ export class ChatUtility { ChatUtility.createChatMessage(chatOptions, rollMode, name); } + /* -------------------------------------------- */ static createChatMessage( chatOptions, rollMode, name) { switch (rollMode) { case "blindroll": // GM only @@ -29,6 +30,7 @@ export class ChatUtility { ChatMessage.create(chatOptions); } + /* -------------------------------------------- */ static prepareChatMessage( rollMode, name) { return { user: game.user._id, @@ -36,6 +38,7 @@ export class ChatUtility { } } + /* -------------------------------------------- */ static getWhisperRecipients( rollMode, name) { switch (rollMode) { case "blindroll": return ChatUtility.getUsers(user => user.isGM); @@ -45,15 +48,18 @@ export class ChatUtility { return undefined; } + /* -------------------------------------------- */ static getWhisperRecipientsAndGMs(name) { return ChatMessage.getWhisperRecipients(name) .concat(this.getUsers(user => user.isGM)); } + /* -------------------------------------------- */ static getUsers(filter) { return game.users.filter(filter).map(user => user.data._id); } + /* -------------------------------------------- */ static blindMessageToGM(chatOptions) { let chatGM = duplicate(chatOptions); 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 }); } + /* -------------------------------------------- */ static handleGMChatMessage(data) { console.log("blindMessageToGM", data); if (game.user.isGM) { // message privé pour GM only diff --git a/module/rdd-astrologie-editeur.js b/module/rdd-astrologie-editeur.js index 6451ba9e..7b539588 100644 --- a/module/rdd-astrologie-editeur.js +++ b/module/rdd-astrologie-editeur.js @@ -10,12 +10,12 @@ export class RdDAstrologieEditeur extends Dialog { constructor(html, calendrier, calendrierData) { let myButtons = { - saveButton: { label: "Enregistrer", callback: html => this.fillData() } + saveButton: { label: "Fermer", callback: html => this.fillData() } }; // Common conf 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) this.calendrier = calendrier; diff --git a/module/rdd-astrologie-joueur.js b/module/rdd-astrologie-joueur.js new file mode 100644 index 00000000..23aa4c7f --- /dev/null +++ b/module/rdd-astrologie-joueur.js @@ -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 () { + }); + + } + +} diff --git a/module/rdd-calendrier.js b/module/rdd-calendrier.js index 11e1e5a5..78fc3e92 100644 --- a/module/rdd-calendrier.js +++ b/module/rdd-calendrier.js @@ -23,7 +23,7 @@ const saisonsDef = { "printemps": { label: "Printemps"}, "hiver": { label: "Hiver"} }; const RDD_JOUR_PAR_MOIS = 28; -const MAX_NOMBRE_ASTRAL = 30; +const MAX_NOMBRE_ASTRAL = 12; /* -------------------------------------------- */ export class RdDCalendrier extends Application { @@ -38,7 +38,7 @@ export class RdDCalendrier extends Application { this.calendrier.heuresRelative = 0; this.calendrier.minutesRelative = 0; this.calendrier.moisRdD = 0; // Index dans heuresList - this.calendrier.jour = 1; + this.calendrier.jour = 0; if ( game.user.isGM) { // Uniquement si GM game.settings.set("foundryvtt-reve-de-dragon", "calendrier", this.calendrier ); } @@ -72,9 +72,9 @@ export class RdDCalendrier extends Application { /* -------------------------------------------- */ getDateFromIndex( index ) { - let month = Math.ceil(index / 28); - let day = index - (month*28); - return day+"/"+heuresList[month]; + let month = Math.floor(index / 28); + let day = (index - (month*28)) + 1; + return day+" "+heuresList[month]; } /* -------------------------------------------- */ @@ -94,29 +94,34 @@ export class RdDCalendrier extends Application { /* -------------------------------------------- */ getCurrentNombreAstral() { 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() { // Auto-create if needed if ( this.listeNombreAstral == undefined) - this.listeNombreAstral = {}; + this.listeNombreAstral = []; // Nettoyage des nombres astraux anciens let jourCourant = this.getCurrentDayIndex(); - let keys = Object.keys(this.listeNombreAstral); - for ( let jourIndex of keys) { - if ( Number(jourIndex) < jourCourant) { - this.listeNombreAstral[jourIndex] = undefined; - } - } - // A partir du jour courant, génération des nombres avec gestion des trous potentiels - for (let jourIndex = jourCourant; jourIndex nombreAstral.index >= jourCourant ); + //console.log("LSTES", this.listeNombreAstral, newList ); + + let lastDay = jourCourant; + for (let i=0; i < MAX_NOMBRE_ASTRAL; i++) { + let nombreAstral = newList[i]; + if ( nombreAstral ) { + lastDay = nombreAstral.index + 1; + } else { + newList.push( this.ajouterNombreAstral( lastDay) ); + lastDay += 1; } } + this.listeNombreAstral = newList; + game.settings.set("foundryvtt-reve-de-dragon", "liste-nombre-astral", this.listeNombreAstral ); } @@ -147,14 +152,14 @@ export class RdDCalendrier extends Application { /* -------------------------------------------- */ incrementerJour( ) { 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; if ( this.calendrier.jour <= 0) - this.calendrier.jour = 1; + this.calendrier.jour = 0; this.calendrier.moisRdD += 1; // Reconstruire les nombres astraux - this.rebuildListeNombreAstral(); } + this.rebuildListeNombreAstral(); } /* -------------------------------------------- */ @@ -181,7 +186,7 @@ export class RdDCalendrier extends Application { data.heureKey = heureKey; data.moisKey = moisKey; 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.nomSaison = saisonsDef[heuresDef[moisKey].saison].label; data.heuresRelative = this.calendrier.heuresRelative; @@ -238,7 +243,7 @@ export class RdDCalendrier extends Application { saveEditeur( calendrierData ) { this.calendrier.heuresRelative = Number(calendrierData.heuresRelative); 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.heureRdD = heuresList.findIndex(heure => heure === calendrierData.heureKey);; // Index dans heuresList game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier) ); @@ -264,18 +269,18 @@ export class RdDCalendrier extends Application { /* -------------------------------------------- */ async showAstrologieEditor() { - let calendrierData = duplicate( this.fillCalendrierData( ) ); - calendrierData.astrologieData = duplicate( this.listeNombreAstral ); - for (let index in calendrierData.astrologieData ) { - let astralData = calendrierData.astrologieData[index]; - astralData.humanDate = this.getDateFromIndex( index ); + let calendrierData = duplicate( this.fillCalendrierData( ) ); + let astrologieArray = []; + for (let astralData of this.listeNombreAstral ) { + astralData.humanDate = this.getDateFromIndex( astralData.index ); + astrologieArray.push( duplicate(astralData ) ); } - if ( this.astrologieEditeur == undefined ) { - let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/calendar-astrologie-template.html', calendrierData ); - this.astrologieEditeur = new RdDAstrologieEditeur(html, this, calendrierData ) - } - this.astrologieEditeur.updateData( calendrierData ); - this.astrologieEditeur.render(true); + //console.log("ASTRO", astrologieArray); + calendrierData.astrologieData = astrologieArray; + 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 ); + astrologieEditeur.render(true); } /* -------------------------------------------- */ diff --git a/module/rdd-roll-dialog.js b/module/rdd-roll-dialog.js index a73607b2..a8dd5e38 100644 --- a/module/rdd-roll-dialog.js +++ b/module/rdd-roll-dialog.js @@ -22,7 +22,7 @@ export class RdDRollDialog extends Dialog { else { myButtons = { rollButton: { label: "Lancer", callback: html => this.actor.performRoll(this.rollData) } - }; + }; } // Common conf diff --git a/module/rdd-roll.js b/module/rdd-roll.js index 3cc84e04..88cbaaea 100644 --- a/module/rdd-roll.js +++ b/module/rdd-roll.js @@ -7,9 +7,10 @@ import { RdDResolutionTable } from "./rdd-resolution-table.js"; * Extend the base Dialog entity to select roll parameters * @extends {Dialog} */ - +/* -------------------------------------------- */ export class RdDRoll extends Dialog { + /* -------------------------------------------- */ static async create(actor, rollData, dialogConfig, ...actions) { RdDRoll._ensureCorrectActions(actions); @@ -24,6 +25,7 @@ export class RdDRoll extends Dialog { return new RdDRoll(actor, rollData, html, options, actions); } + /* -------------------------------------------- */ static _setDefaultOptions(actor, rollData) { mergeObject(rollData, @@ -45,6 +47,7 @@ export class RdDRoll extends Dialog { { overwrite: false }); } + /* -------------------------------------------- */ static _ensureCorrectActions(actions) { if (actions.length == 0) { throw 'No action defined'; @@ -56,6 +59,7 @@ export class RdDRoll extends Dialog { }); } + /* -------------------------------------------- */ constructor(actor, rollData, html, options, actions) { let conf = { title: actions[0].label, @@ -73,9 +77,9 @@ export class RdDRoll extends Dialog { this.rollData = rollData; } + /* -------------------------------------------- */ async onAction(action, html) { await RdDResolutionTable.rollData(this.rollData); - console.log("RdDRoll -=>", this.rollData, this.rollData.rolled); if (action.callbacks) diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 360f5756..2d89766e 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -178,6 +178,7 @@ export class RdDUtility { '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-natation.html', + 'systems/foundryvtt-reve-de-dragon/templates/dialog-astrologie-joueur.html', // Calendrier 'systems/foundryvtt-reve-de-dragon/templates/calendar-template.html', 'systems/foundryvtt-reve-de-dragon/templates/calendar-editor-template.html', diff --git a/template.json b/template.json index 35a0573e..297d3aab 100644 --- a/template.json +++ b/template.json @@ -687,6 +687,7 @@ }, "nombreastral": { "value": 0, + "istrue": false, "jourindex": 1 }, "monnaie": { diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index f2c722f9..ff9f9886 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -540,6 +540,9 @@ {{/if}} +
  • + Astrologie : Nombres Astraux +
  • diff --git a/templates/calendar-astrologie-template.html b/templates/calendar-astrologie-template.html index 40c35459..274da88b 100644 --- a/templates/calendar-astrologie-template.html +++ b/templates/calendar-astrologie-template.html @@ -9,13 +9,18 @@
    - +
    {{#each astrologieData as |nombreData key|}} - + {{/each}} -
    {{nombreData.humanDate}} - {{nombreData.nombreAstral}}{{nombreData.humanDate}}
    + + {{#each astrologieData as |nombreData key|}} + {{nombreData.nombreAstral}} + {{/each}} + +
    diff --git a/templates/dialog-astrologie-joueur.html b/templates/dialog-astrologie-joueur.html new file mode 100644 index 00000000..274da88b --- /dev/null +++ b/templates/dialog-astrologie-joueur.html @@ -0,0 +1,27 @@ +
    +
    +
    +

    Astrologie

    +
    +
    + + {{!-- Sheet Body --}} +
    +
    + + + + {{#each astrologieData as |nombreData key|}} + + {{/each}} + + + {{#each astrologieData as |nombreData key|}} + + {{/each}} + +
    {{nombreData.humanDate}}
    {{nombreData.nombreAstral}}
    +
    +
    + +