From 4159b6b1813fd0907fa81b6251f364262f605add Mon Sep 17 00:00:00 2001 From: sladecraven Date: Sat, 21 May 2022 17:56:52 +0200 Subject: [PATCH] Fix files --- module/system/bol-commands.js | 108 +++++++++++++++++++++++ templates/chat/chat-adventure-result.hbs | 33 +++++++ 2 files changed, 141 insertions(+) create mode 100644 module/system/bol-commands.js create mode 100644 templates/chat/chat-adventure-result.hbs diff --git a/module/system/bol-commands.js b/module/system/bol-commands.js new file mode 100644 index 0000000..c5fe9bb --- /dev/null +++ b/module/system/bol-commands.js @@ -0,0 +1,108 @@ +/* -------------------------------------------- */ +import { BoLAdventureGenerator } from "./bol-adventure-generator.js" + +/* -------------------------------------------- */ +export class BoLCommands { + + static init() { + if (!game.bol.commands) { + const bolCommands = new BoLCommands() + bolCommands.registerCommand({ path: ["/adventure"], func: (content, msg, params) => BoLAdventureGenerator.createAdventure(), descr: "Nouvelle idée d'aventure!" }); + game.bol.commands = bolCommands + } + + Hooks.on("chatMessage", (html, content, msg) => { + if (content[0] == '/') { + let regExp = /(\S+)/g; + let commands = content.match(regExp); + if (game.bol.commands.processChatCommand(commands, content, msg)) { + return false; + } + } + return true + }) + + } + constructor() { + this.commandsTable = {} + } + + /* -------------------------------------------- */ + registerCommand(command) { + this._addCommand(this.commandsTable, command.path, '', command); + } + + /* -------------------------------------------- */ + _addCommand(targetTable, path, fullPath, command) { + if (!this._validateCommand(targetTable, path, command)) { + return; + } + const term = path[0]; + fullPath = fullPath + term + ' ' + if (path.length == 1) { + command.descr = `${fullPath}: ${command.descr}`; + targetTable[term] = command; + } + else { + if (!targetTable[term]) { + targetTable[term] = { subTable: {} }; + } + this._addCommand(targetTable[term].subTable, path.slice(1), fullPath, command) + } + } + + /* -------------------------------------------- */ + _validateCommand(targetTable, path, command) { + if (path.length > 0 && path[0] && command.descr && (path.length != 1 || targetTable[path[0]] == undefined)) { + return true; + } + console.warn("bolCommands._validateCommand failed ", targetTable, path, command); + return false; + } + + + /* -------------------------------------------- */ + /* Manage chat commands */ + processChatCommand(commandLine, content = '', msg = {}) { + // Setup new message's visibility + let rollMode = game.settings.get("core", "rollMode"); + if (["gmroll", "blindroll"].includes(rollMode)) msg["whisper"] = ChatMessage.getWhisperRecipients("GM"); + if (rollMode === "blindroll") msg["blind"] = true; + msg["type"] = 0; + + let command = commandLine[0].toLowerCase(); + let params = commandLine.slice(1); + + return this.process(command, params, content, msg); + } + + /* -------------------------------------------- */ + process(command, params, content, msg) { + return this._processCommand(this.commandsTable, command, params, content, msg); + } + + /* -------------------------------------------- */ + _processCommand(commandsTable, name, params, content = '', msg = {}, path = "") { + console.log("===> Processing command") + let command = commandsTable[name]; + path = path + name + " "; + if (command && command.subTable) { + if (params[0]) { + return this._processCommand(command.subTable, params[0], params.slice(1), content, msg, path) + } + else { + this.help(msg, command.subTable); + return true; + } + } + if (command && command.func) { + const result = command.func(content, msg, params); + if (result == false) { + BoLCommands._chatAnswer(msg, command.descr); + } + return true; + } + return false; + } + +} \ No newline at end of file diff --git a/templates/chat/chat-adventure-result.hbs b/templates/chat/chat-adventure-result.hbs new file mode 100644 index 0000000..345afe0 --- /dev/null +++ b/templates/chat/chat-adventure-result.hbs @@ -0,0 +1,33 @@ +
+ {{name}} +

{{story.title}}

+
+ +
+ +
{{story.mission}} + {{#if story.carriere}} +
{{story.carriere}} + {{/if}} + {{#if story.lieu}} +
{{story.lieu}} + {{/if}} + {{#if story.objet}} +
{{story.objet}} + {{/if}} +
{{story.motivation}} + {{#if story.rival}} +
{{story.rival}} + {{/if}} + {{#if story.dieu}} +
{{story.dieu}} + {{/if}} + {{#if story.complication}} +
{{story.complication}} + {{/if}} + {{#if story.retournement}} +
{{story.retournement}} + {{/if}} +
{{story.recompense}} +
+