Fixes mineurs #583
@ -22,7 +22,20 @@ const rddRollNumeric = /^(\d+)\s*([\+\-]?\d+)?\s*(s)?/;
|
||||
export class RdDCommands {
|
||||
|
||||
static init() {
|
||||
game.system.rdd.commands = new RdDCommands();
|
||||
const rddCommands = new RdDCommands();
|
||||
|
||||
Hooks.on("chatMessage", (html, content, msg) => {
|
||||
if (content[0] == '/') {
|
||||
let regExp = /(\S+)/g;
|
||||
let commands = content.match(regExp);
|
||||
if (rddCommands.processChatCommand(commands, content, msg)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
game.system.rdd.commands = rddCommands;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
@ -154,14 +167,7 @@ export class RdDCommands {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
registerCommand(command) {
|
||||
this._addCommand(this.getCommands(), command.path, '', command);
|
||||
}
|
||||
|
||||
getCommands() {
|
||||
if (!this.commandsTable){
|
||||
this._registerCommands();
|
||||
}
|
||||
return this.commandsTable;
|
||||
this._addCommand(this.commandsTable, command.path, '', command);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -198,18 +204,29 @@ export class RdDCommands {
|
||||
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;
|
||||
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);
|
||||
if (!this.commandsTable) {
|
||||
this._registerCommands();
|
||||
}
|
||||
|
||||
process(command, params, content, msg) {
|
||||
return this._processCommand(this.getCommands(), command, params, content, msg);
|
||||
let command = commandLine[0].toLowerCase();
|
||||
if (this._isCommandHandled(command)) {
|
||||
let params = commandLine.slice(1);
|
||||
this._processCommand(this.commandsTable, command, params, content, msg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
_isCommandHandled(command){
|
||||
return this.commandsTable[command] != undefined;
|
||||
}
|
||||
|
||||
async _processCommand(commandsTable, name, params, content = '', msg = {}, path = "") {
|
||||
@ -217,18 +234,20 @@ export class RdDCommands {
|
||||
path = path + name + " ";
|
||||
if (command && command.subTable) {
|
||||
if (params[0]) {
|
||||
return this._processCommand(command.subTable, params[0], params.slice(1), content, msg, path)
|
||||
this._processCommand(command.subTable, params[0], params.slice(1), content, msg, path)
|
||||
}
|
||||
else {
|
||||
this.help(msg, command.subTable);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (command && command.func) {
|
||||
new Promise(async () => {
|
||||
const result = await command.func(content, msg, params);
|
||||
if (result == false) {
|
||||
RdDCommands._chatAnswer(msg, command.descr);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -240,7 +259,7 @@ export class RdDCommands {
|
||||
}
|
||||
async help(msg, table) {
|
||||
let commands = []
|
||||
this._buildSubTableHelp(commands, table ?? this.getCommands());
|
||||
this._buildSubTableHelp(commands, table ?? this.commandsTable);
|
||||
|
||||
let html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/settings/dialog-aide-commands.html", { commands: commands });
|
||||
let d = new Dialog(
|
||||
|
@ -345,17 +345,3 @@ async function migrationPngWebp_1_5_34() {
|
||||
/* -------------------------------------------- */
|
||||
Hooks.once('diceSoNiceReady', (dice3d) => RdDDice.diceSoNiceReady(dice3d));
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Foundry VTT chat message */
|
||||
/* -------------------------------------------- */
|
||||
Hooks.on("chatMessage", (html, content, msg) => {
|
||||
if (content[0] == '/') {
|
||||
let regExp = /(\S+)/g;
|
||||
let commands = content.match(regExp);
|
||||
if (game.system.rdd.commands.processChatCommand(commands, content, msg)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user