85 lines
3.6 KiB
JavaScript
85 lines
3.6 KiB
JavaScript
import TravelDistanceV2 from './TravelDistanceV2.js';
|
|
|
|
/**
|
|
* Initialisation du module TravelV2
|
|
*/
|
|
export function initTravelV2() {
|
|
console.log("TravelV2: Initialisation du module de voyage");
|
|
|
|
// Hook pour charger les données au démarrage
|
|
Hooks.once('ready', async () => {
|
|
console.log("TravelV2: Chargement des données de voyage");
|
|
|
|
// Exposer la classe globalement pour accès depuis la console
|
|
game.wfrp4e = game.wfrp4e || {};
|
|
game.wfrp4e.travelv2 = TravelDistanceV2;
|
|
|
|
await TravelDistanceV2.loadTravelData();
|
|
|
|
console.log("TravelV2: Classe accessible via game.wfrp4e.travelv2");
|
|
|
|
// Enregistrer la commande dans le système WFRP4e si disponible
|
|
if (game.wfrp4e?.commands) {
|
|
// Patch warhammer-lib 3.0.2 bug: parseArgs crashes when no args provided
|
|
// (already applied by inn-init if it ran first, but safe to apply again)
|
|
if (game.wfrp4e.commands.parseArgs && !game.wfrp4e.commands._parseArgsPatched) {
|
|
const _origParseArgs = game.wfrp4e.commands.parseArgs.bind(game.wfrp4e.commands);
|
|
game.wfrp4e.commands.parseArgs = function(command, text) {
|
|
return _origParseArgs(command, text ?? "");
|
|
};
|
|
game.wfrp4e.commands._parseArgsPatched = true;
|
|
}
|
|
game.wfrp4e.commands.add({
|
|
voyage: {
|
|
description: "Outil de calcul de distances de voyage (FR)",
|
|
args: ["from", "to"],
|
|
defaultArg: "from",
|
|
callback: (from, to) => {
|
|
// Vérifier que l'utilisateur est GM
|
|
if (!game.user.isGM) {
|
|
ui.notifications.warn("La commande /voyage est réservée au MJ.");
|
|
return;
|
|
}
|
|
|
|
console.log(`TravelV2: Commande /voyage exécutée`);
|
|
console.log(`TravelV2: from =`, from, `(type: ${typeof from})`);
|
|
console.log(`TravelV2: to =`, to, `(type: ${typeof to})`);
|
|
console.log(`TravelV2: from === null ?`, from === null);
|
|
console.log(`TravelV2: to === null ?`, to === null);
|
|
|
|
// Convertir null en undefined pour que la logique fonctionne
|
|
from = from || undefined;
|
|
to = to || undefined;
|
|
|
|
TravelDistanceV2.displayTravelDistance(from, to);
|
|
}
|
|
}
|
|
});
|
|
console.log("TravelV2: Commande /voyage enregistrée avec succès");
|
|
} else {
|
|
console.warn("TravelV2: game.wfrp4e.commands non disponible");
|
|
}
|
|
});
|
|
|
|
// Hook pour ajouter un gestionnaire de clics sur les liens de voyage
|
|
Hooks.on('renderChatMessage', (message, html, data) => {
|
|
// Ajouter un listener pour les clics sur les liens de voyage
|
|
html.find('a[data-action="clickVoyage"]').click((event) => {
|
|
event.preventDefault();
|
|
const target = event.currentTarget;
|
|
TravelDistanceV2.handleTravelClick(event, target);
|
|
});
|
|
|
|
// Bouton "Enregistrer dans le journal"
|
|
html.find('button[data-action="saveVoyageToJournal"]').click(async (event) => {
|
|
event.preventDefault();
|
|
const btn = event.currentTarget;
|
|
const from = btn.dataset.from;
|
|
const to = btn.dataset.to;
|
|
await TravelDistanceV2.saveVoyageToJournal(from, to, message.content);
|
|
});
|
|
});
|
|
|
|
console.log("TravelV2: Module de voyage initialisé");
|
|
}
|