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();
});
html.find('#jet-astrologie').click((event) => {
this.actor.astrologieNombresAstraux();
});
// Roll Skill
html.find('.competence-label a').click((event) => {
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 { 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: "<strong>Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong>"
@ -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);

View File

@ -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

View File

@ -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;

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"}
};
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<jourCourant+MAX_NOMBRE_ASTRAL; jourIndex++) {
if ( this.listeNombreAstral[jourIndex] == undefined) {
this.listeNombreAstral[jourIndex] = this.ajouterNombreAstral(jourIndex);
let newList = this.listeNombreAstral.filter( (nombreAstral, i) => 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);
}
/* -------------------------------------------- */

View File

@ -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)

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-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',

View File

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

View File

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

View File

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