FIx pour Babele 2.8.X
Validation JSON / validate (push) Successful in 17s
Release Creation / build (release) Successful in 58s

This commit is contained in:
2026-04-27 23:58:55 +02:00
parent df1e0b9952
commit 0d20d76db0
53 changed files with 9322 additions and 9028 deletions
+61
View File
@@ -148,6 +148,9 @@ export default class TravelDistanceV2 {
}
}
}
// Bouton pour enregistrer dans le journal
message += this.formatJournalButton(originalFrom, originalTo);
} else if (fromTown && fromTown == "help") {
console.log("TravelV2: Branche: Affichage de l'aide");
// Afficher l'aide
@@ -222,6 +225,64 @@ export default class TravelDistanceV2 {
TravelDistanceV2.displayTravelDistance(fromTown, toTown);
}
/**
* Retourne le HTML du bouton "Enregistrer dans le journal"
* @param {String} from - Ville de départ
* @param {String} to - Ville d'arrivée
* @returns {String} HTML du bouton
*/
static formatJournalButton(from, to) {
return `<div class="voyage-journal-action" style="margin-top:8px;text-align:right">
<button type="button" class="voyage-journal-btn" data-action="saveVoyageToJournal"
data-from="${from}" data-to="${to}">
<i class="fas fa-book"></i> Enregistrer dans le journal "Voyages"
</button>
</div>`;
}
/**
* Enregistre le contenu d'un voyage dans le journal FoundryVTT "Voyages"
* @param {String} from - Ville de départ
* @param {String} to - Ville d'arrivée
* @param {String} content - HTML complet du message de tchat
*/
static async saveVoyageToJournal(from, to, content) {
if (!game.user.isGM) {
ui.notifications.warn("Seul le MJ peut enregistrer dans le journal.");
return;
}
const journalName = "Voyages";
let journal = game.journal.find(j => j.name === journalName);
if (!journal) {
journal = await JournalEntry.create({ name: journalName });
}
// Supprimer le bouton du contenu avant de l'enregistrer
const parser = new DOMParser();
const doc = parser.parseFromString(content, 'text/html');
doc.querySelectorAll('.voyage-journal-action').forEach(el => el.remove());
const cleanContent = doc.body.innerHTML;
const now = new Date();
const dateStr = now.toLocaleDateString('fr-FR');
const pageName = `${from}${to} (${dateStr})`;
await journal.createEmbeddedDocuments("JournalEntryPage", [{
name: pageName,
type: "text",
text: {
content: cleanContent,
format: CONST.JOURNAL_ENTRY_PAGE_FORMATS.HTML
}
}]);
// Ouvrir le journal sur la nouvelle page
const page = journal.pages.find(p => p.name === pageName);
journal.sheet.render(true, { pageId: page?.id });
ui.notifications.info(`Voyage "${from}${to}" enregistré dans le journal.`);
}
/**
* Formate l'affichage d'une route directe
* @param {Object} travel - Données de la route
+18 -1
View File
@@ -20,7 +20,15 @@ export function initTravelV2() {
// Enregistrer la commande dans le système WFRP4e si disponible
if (game.wfrp4e?.commands) {
console.log("TravelV2: Enregistrement de la commande /voyage");
// 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)",
@@ -61,6 +69,15 @@ export function initTravelV2() {
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é");