From 90d46c6a78f8d54d9ff7489fd6d6a9d91e6b2c5d Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Mon, 14 Oct 2024 03:46:09 +0200 Subject: [PATCH] Init settings before sheets Eviter que le chargement d'acteurs ait lieu avant le chargement des settings --- module/dialog-chronologie.js | 2 +- module/environnement.js | 2 +- module/rdd-hotbar-drop.js | 3 +- module/rdd-main.js | 60 +++++++++++++------------- module/rdd-tmr-dialog.js | 2 +- module/settings/options-avancees.js | 2 +- module/settings/regles-optionnelles.js | 2 +- module/settings/system-compendiums.js | 2 +- module/time/auto-adjust-darkness.js | 2 +- module/time/rdd-calendrier.js | 2 +- module/time/rdd-timestamp.js | 2 +- 11 files changed, 40 insertions(+), 41 deletions(-) diff --git a/module/dialog-chronologie.js b/module/dialog-chronologie.js index 781e31d1..5168870d 100644 --- a/module/dialog-chronologie.js +++ b/module/dialog-chronologie.js @@ -8,7 +8,7 @@ const LATEST_USED_JOURNAL_ID = "chronologie-dernier-journal"; export class DialogChronologie extends Dialog { - static init() { + static initSettings() { game.settings.register(SYSTEM_RDD, LATEST_USED_JOURNAL_ID, { name: "Dernier article de journal utilisé pour enregistrer la chronologie", scope: "client", diff --git a/module/environnement.js b/module/environnement.js index 2cb70e9c..c9071b45 100644 --- a/module/environnement.js +++ b/module/environnement.js @@ -7,7 +7,7 @@ import { CompendiumTableHelpers, CompendiumTable, SystemCompendiums } from "./se const COMPENDIUMS_RECHERCHE = 'compendiums-recherche'; export class Environnement { - static init() { + static initSettings() { game.settings.register(SYSTEM_RDD, COMPENDIUMS_RECHERCHE, { name: COMPENDIUMS_RECHERCHE, default: [ diff --git a/module/rdd-hotbar-drop.js b/module/rdd-hotbar-drop.js index 7bb6db05..979c2a08 100644 --- a/module/rdd-hotbar-drop.js +++ b/module/rdd-hotbar-drop.js @@ -79,8 +79,7 @@ export class RdDHotbar { * Actor - open actor sheet * Journal - open journal sheet */ - static init() { - + static initHooks() { Hooks.on('hotbarDrop', (bar, documentData, slot) => { // Create item macro if rollable item - weapon, spell, prayer, trait, or skill diff --git a/module/rdd-main.js b/module/rdd-main.js index 7dca3faa..ca9b5fc4 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -61,7 +61,7 @@ import { RdDSigneDraconiqueItemSheet } from "./item/sheet-signedraconique.js" import { RdDItemInventaireSheet } from "./item/sheet-base-inventaire.js" import { AppAstrologie } from "./sommeil/app-astrologie.js" import { RdDItemArmure } from "./item/armure.js" -import { AutoAdjustDarkness as AutoAdjustDarkness } from "./time/auto-adjust-darkness.js" +import { AutoAdjustDarkness } from "./time/auto-adjust-darkness.js" import { RdDCreature } from "./actor/creature.js" import { RdDTMRDialog } from "./rdd-tmr-dialog.js" import { OptionsAvancees } from "./settings/options-avancees.js" @@ -80,7 +80,7 @@ export class SystemReveDeDragon { const system = new SystemReveDeDragon() Hooks.once('init', async () => await system.onInit()) Hooks.once('diceSoNiceReady', (dice3d) => RdDDice.diceSoNiceReady(dice3d)) - Hooks.once('ready', () => system.onReady()) + Hooks.once('ready', async () => await system.onReady()) } constructor() { @@ -115,24 +115,31 @@ export class SystemReveDeDragon { game.system.rdd = this this.AppAstrologie = AppAstrologie - - console.log(`Initializing Reve de Dragon System`) - + console.log(`Initializing Reve de Dragon System Settings`) + // preload handlebars templates RdDUtility.preloadHandlebarsTemplates() AppPersonnageAleatoire.preloadHandlebars() - + /* -------------------------------------------- */ - this.initSystemSettings() - + ReglesOptionnelles.initSettings() + OptionsAvancees.initSettings() + AutoAdjustDarkness.initSettings() + RdDTimestamp.initSettings() + RdDCalendrier.initSettings() + SystemCompendiums.initSettings() + DialogChronologie.initSettings() + RdDTMRDialog.initSettings() + Environnement.initSettings() + + this.initSettings() + /* -------------------------------------------- */ // Set an initiative formula for the system - CONFIG.Combat.initiative = { - formula: "1+(1d6/10)", - decimals: 2 - } - + CONFIG.Combat.initiative = { formula: "1+(1d6/10)", decimals: 2 } + /* -------------------------------------------- */ + console.log(`Initializing Reve de Dragon Socket handlers`) game.socket.on(SYSTEM_SOCKET_ID, async (sockmsg) => { console.log(">>>>> MSG RECV", sockmsg) try { @@ -144,9 +151,10 @@ export class SystemReveDeDragon { console.error('game.socket.on(SYSTEM_SOCKET_ID) Exception: ', sockmsg, ' => ', e) } }) - + /* -------------------------------------------- */ // Define custom Entity classes + console.log(`Initializing Reve de Dragon Documents`) CONFIG.Actor.documentClass = RdDBaseActor CONFIG.Item.documentClass = RdDItem CONFIG.RDD = { @@ -155,7 +163,7 @@ export class SystemReveDeDragon { ajustementsConditions: RdDUtility.getAjustementsConditions(), difficultesLibres: RdDUtility.getDifficultesLibres() } - + /* -------------------------------------------- */ // Register sheet application classes Actors.unregisterSheet("core", ActorSheet) @@ -166,7 +174,7 @@ export class SystemReveDeDragon { Actors.registerSheet(SYSTEM_RDD, RdDActorEntiteSheet, { types: ["entite"], makeDefault: true }) Items.unregisterSheet("core", ItemSheet) await RdDActorExportSheet.init() - + RdDItemSheet.register(RdDSigneDraconiqueItemSheet) RdDItemSheet.register(RdDRencontreItemSheet) RdDItemSheet.register(RdDConteneurItemSheet) @@ -176,7 +184,7 @@ export class SystemReveDeDragon { RdDItemSheet.register(RdDIngredientItemSheet) RdDItemSheet.register(RdDServiceItemSheet) RdDItemSheet.register(RdDBlessureItemSheet) - + Items.registerSheet(SYSTEM_RDD, RdDItemInventaireSheet, { types: [ "objet", "arme", "armure", "livre", "potion", "munition", @@ -192,16 +200,10 @@ export class SystemReveDeDragon { "tarot", "extraitpoetique", "empoignade" ], makeDefault: true }) - CONFIG.Combat.documentClass = RdDCombatManager // préparation des différents modules - AutoAdjustDarkness.init() - RdDTimestamp.init() - RdDCalendrier.init() - SystemCompendiums.init() - DialogChronologie.init() - ReglesOptionnelles.init() - OptionsAvancees.init() + console.log(`Initializing Reve de Dragon Hooks and handlers`) + CONFIG.Combat.documentClass = RdDCombatManager RdDUtility.init() RdDDice.init() RdDCommands.init() @@ -211,15 +213,14 @@ export class SystemReveDeDragon { RdDCompendiumOrganiser.init() EffetsDraconiques.init() TMRUtility.init() - await RdDTMRDialog.init() - RdDHotbar.init() + RdDHotbar.initHooks() RdDPossession.init() TMRRencontres.init() - Environnement.init() ExportScriptarium.init() } - initSystemSettings() { + initSettings() { + // TODO: déplacer vers les modules correspondants game.settings.register(SYSTEM_RDD, "accorder-entite-cauchemar", { name: "Accorder le rêve aux entités", hint: "A quel moment les personnages doivent accorder leur rêve aux entités de cauchemar", @@ -318,4 +319,3 @@ export class SystemReveDeDragon { } SystemReveDeDragon.start() - diff --git a/module/rdd-tmr-dialog.js b/module/rdd-tmr-dialog.js index 5b388e2b..eab55338 100644 --- a/module/rdd-tmr-dialog.js +++ b/module/rdd-tmr-dialog.js @@ -34,7 +34,7 @@ const TMR_DISPLAY_SIZE = { /* -------------------------------------------- */ export class RdDTMRDialog extends Dialog { - static async init() { + static initSettings() { game.settings.register(SYSTEM_RDD, TMR_DISPLAY_SIZE.code, { name: 'Taille des cases des TMR', hint: "Taille en pixel des cases des TMR (réglable directement dans la fenêtre des TMR)", diff --git a/module/settings/options-avancees.js b/module/settings/options-avancees.js index a524bb01..c09c745b 100644 --- a/module/settings/options-avancees.js +++ b/module/settings/options-avancees.js @@ -8,7 +8,7 @@ const OPTIONS_AVANCEES = [ ] export class OptionsAvancees extends FormApplication { - static init() { + static initSettings() { for (const regle of OPTIONS_AVANCEES) { const name = regle.name const id = OptionsAvancees._getId(name) diff --git a/module/settings/regles-optionnelles.js b/module/settings/regles-optionnelles.js index bbb53638..3eac1e2d 100644 --- a/module/settings/regles-optionnelles.js +++ b/module/settings/regles-optionnelles.js @@ -46,7 +46,7 @@ const listeReglesOptionnelles = [ const uniquementJoueur = listeReglesOptionnelles.filter(it => it.uniquementJoueur).map(it=>it.name); export class ReglesOptionnelles extends FormApplication { - static init() { + static initSettings() { for (const regle of listeReglesOptionnelles) { const name = regle.name; const id = ReglesOptionnelles._getIdRegle(name); diff --git a/module/settings/system-compendiums.js b/module/settings/system-compendiums.js index bdff885f..31321d6d 100644 --- a/module/settings/system-compendiums.js +++ b/module/settings/system-compendiums.js @@ -25,7 +25,7 @@ const CONFIGURABLE_COMPENDIUMS = { * ======= Gestion des accès aux compendiums systèmes (ou surchargés) ======= */ export class SystemCompendiums extends FormApplication { - static init() { + static initSettings() { Object.keys(CONFIGURABLE_COMPENDIUMS).forEach(compendium => { const definition = CONFIGURABLE_COMPENDIUMS[compendium]; foundry.utils.mergeObject(definition, { diff --git a/module/time/auto-adjust-darkness.js b/module/time/auto-adjust-darkness.js index 1d851cf1..c7b320e8 100644 --- a/module/time/auto-adjust-darkness.js +++ b/module/time/auto-adjust-darkness.js @@ -4,7 +4,7 @@ export const AUTO_ADJUST_DARKNESS = "auto-adjust-darkness"; export class AutoAdjustDarkness { - static init() { + static initSettings() { game.settings.register(SYSTEM_RDD, AUTO_ADJUST_DARKNESS, { name: AUTO_ADJUST_DARKNESS, scope: "world", diff --git a/module/time/rdd-calendrier.js b/module/time/rdd-calendrier.js index b5b41088..b2a4129d 100644 --- a/module/time/rdd-calendrier.js +++ b/module/time/rdd-calendrier.js @@ -15,7 +15,7 @@ const TEMPLATE_CALENDRIER = "systems/foundryvtt-reve-de-dragon/templates/time/ca const INITIAL_CALENDAR_POS = { top: 200, left: 200, horlogeAnalogique: true }; /* -------------------------------------------- */ export class RdDCalendrier extends Application { - static init() { + static initSettings() { game.settings.register(SYSTEM_RDD, "liste-nombre-astral", { name: "liste-nombre-astral", scope: "world", diff --git a/module/time/rdd-timestamp.js b/module/time/rdd-timestamp.js index c10d55f6..27a5a80f 100644 --- a/module/time/rdd-timestamp.js +++ b/module/time/rdd-timestamp.js @@ -49,7 +49,7 @@ const FORMULES_PERIODE = [ export class RdDTimestamp { - static init() { + static initSettings() { game.settings.register(SYSTEM_RDD, WORLD_TIMESTAMP_SETTING, { name: WORLD_TIMESTAMP_SETTING, scope: "world",