Fix: /roll
Regression sur /roll causée par méthode async: return Promise(false)=>true au lieu de false...
This commit is contained in:
parent
979a48e4d9
commit
e67ac96e93
@ -22,7 +22,20 @@ const rddRollNumeric = /^(\d+)\s*([\+\-]?\d+)?\s*(s)?/;
|
|||||||
export class RdDCommands {
|
export class RdDCommands {
|
||||||
|
|
||||||
static init() {
|
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() {
|
constructor() {
|
||||||
@ -50,8 +63,8 @@ export class RdDCommands {
|
|||||||
<br><strong>/table rencontre deso</strong> affiche la table des rencontres en Désolation
|
<br><strong>/table rencontre deso</strong> affiche la table des rencontres en Désolation
|
||||||
<br><strong>/table rencontre mauvaise</strong> affiche la table des mauvaises rencontres`
|
<br><strong>/table rencontre mauvaise</strong> affiche la table des mauvaises rencontres`
|
||||||
});
|
});
|
||||||
this.registerCommand({ path: ["/table", "milieu"], func: (content, msg, params) => this.tableMilieu(msg, params,'liste'), descr: "Affiche la table des ressource naturelles pour un milieu donné" });
|
this.registerCommand({ path: ["/table", "milieu"], func: (content, msg, params) => this.tableMilieu(msg, params, 'liste'), descr: "Affiche la table des ressource naturelles pour un milieu donné" });
|
||||||
|
|
||||||
this.registerCommand({ path: ["/tirer", "comp"], func: (content, msg, params) => RdDRollTables.getCompetence('chat'), descr: "Tire une compétence au hasard" });
|
this.registerCommand({ path: ["/tirer", "comp"], func: (content, msg, params) => RdDRollTables.getCompetence('chat'), descr: "Tire une compétence au hasard" });
|
||||||
this.registerCommand({ path: ["/tirer", "queue"], func: (content, msg, params) => RdDRollTables.getQueue('chat'), descr: "Tire une Queue de Dragon" });
|
this.registerCommand({ path: ["/tirer", "queue"], func: (content, msg, params) => RdDRollTables.getQueue('chat'), descr: "Tire une Queue de Dragon" });
|
||||||
this.registerCommand({ path: ["/tirer", "ombre"], func: (content, msg, params) => RdDRollTables.getOmbre('chat'), descr: "Tire une Ombre de Thanatos" });
|
this.registerCommand({ path: ["/tirer", "ombre"], func: (content, msg, params) => RdDRollTables.getOmbre('chat'), descr: "Tire une Ombre de Thanatos" });
|
||||||
@ -63,7 +76,7 @@ export class RdDCommands {
|
|||||||
this.registerCommand({ path: ["/tirer", "desir"], func: (content, msg, params) => RdDRollTables.getDesirLancinant('chat'), descr: "Tire un Désir Lancinant" });
|
this.registerCommand({ path: ["/tirer", "desir"], func: (content, msg, params) => RdDRollTables.getDesirLancinant('chat'), descr: "Tire un Désir Lancinant" });
|
||||||
this.registerCommand({ path: ["/tirer", "rencontre"], func: (content, msg, params) => this.getRencontreTMR(params), descr: `Détermine une rencontre dans les TMR (synonyme de "/tmrr")` });
|
this.registerCommand({ path: ["/tirer", "rencontre"], func: (content, msg, params) => this.getRencontreTMR(params), descr: `Détermine une rencontre dans les TMR (synonyme de "/tmrr")` });
|
||||||
this.registerCommand({ path: ["/tirer", "milieu"], func: (content, msg, params) => this.tableMilieu(msg, params, 'chat'), descr: "Effectue un tirage dans la table desressource naturelles pour un milieu donné" });
|
this.registerCommand({ path: ["/tirer", "milieu"], func: (content, msg, params) => this.tableMilieu(msg, params, 'chat'), descr: "Effectue un tirage dans la table desressource naturelles pour un milieu donné" });
|
||||||
|
|
||||||
this.registerCommand({ path: ["/meteo"], func: (content, msg, params) => this.getMeteo(msg, params), descr: "Propose une météo marine" });
|
this.registerCommand({ path: ["/meteo"], func: (content, msg, params) => this.getMeteo(msg, params), descr: "Propose une météo marine" });
|
||||||
this.registerCommand({ path: ["/nom"], func: (content, msg, params) => RdDNameGen.getName(msg, params), descr: "Génère un nom aléatoire" });
|
this.registerCommand({ path: ["/nom"], func: (content, msg, params) => RdDNameGen.getName(msg, params), descr: "Génère un nom aléatoire" });
|
||||||
|
|
||||||
@ -154,14 +167,7 @@ export class RdDCommands {
|
|||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
registerCommand(command) {
|
registerCommand(command) {
|
||||||
this._addCommand(this.getCommands(), command.path, '', command);
|
this._addCommand(this.commandsTable, command.path, '', command);
|
||||||
}
|
|
||||||
|
|
||||||
getCommands() {
|
|
||||||
if (!this.commandsTable){
|
|
||||||
this._registerCommands();
|
|
||||||
}
|
|
||||||
return this.commandsTable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
@ -198,18 +204,29 @@ export class RdDCommands {
|
|||||||
processChatCommand(commandLine, content = '', msg = {}) {
|
processChatCommand(commandLine, content = '', msg = {}) {
|
||||||
// Setup new message's visibility
|
// Setup new message's visibility
|
||||||
let rollMode = game.settings.get("core", "rollMode");
|
let rollMode = game.settings.get("core", "rollMode");
|
||||||
if (["gmroll", "blindroll"].includes(rollMode)) msg["whisper"] = ChatMessage.getWhisperRecipients("GM");
|
if (["gmroll", "blindroll"].includes(rollMode)) {
|
||||||
if (rollMode === "blindroll") msg["blind"] = true;
|
msg["whisper"] = ChatMessage.getWhisperRecipients("GM");
|
||||||
|
}
|
||||||
|
if (rollMode === "blindroll"){
|
||||||
|
msg["blind"] = true;
|
||||||
|
}
|
||||||
msg["type"] = 0;
|
msg["type"] = 0;
|
||||||
|
|
||||||
|
if (!this.commandsTable) {
|
||||||
|
this._registerCommands();
|
||||||
|
}
|
||||||
|
|
||||||
let command = commandLine[0].toLowerCase();
|
let command = commandLine[0].toLowerCase();
|
||||||
let params = commandLine.slice(1);
|
if (this._isCommandHandled(command)) {
|
||||||
|
let params = commandLine.slice(1);
|
||||||
return this.process(command, params, content, msg);
|
this._processCommand(this.commandsTable, command, params, content, msg);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
process(command, params, content, msg) {
|
_isCommandHandled(command){
|
||||||
return this._processCommand(this.getCommands(), command, params, content, msg);
|
return this.commandsTable[command] != undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async _processCommand(commandsTable, name, params, content = '', msg = {}, path = "") {
|
async _processCommand(commandsTable, name, params, content = '', msg = {}, path = "") {
|
||||||
@ -217,18 +234,20 @@ export class RdDCommands {
|
|||||||
path = path + name + " ";
|
path = path + name + " ";
|
||||||
if (command && command.subTable) {
|
if (command && command.subTable) {
|
||||||
if (params[0]) {
|
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 {
|
else {
|
||||||
this.help(msg, command.subTable);
|
this.help(msg, command.subTable);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (command && command.func) {
|
if (command && command.func) {
|
||||||
const result = await command.func(content, msg, params);
|
new Promise(async () => {
|
||||||
if (result == false) {
|
const result = await command.func(content, msg, params);
|
||||||
RdDCommands._chatAnswer(msg, command.descr);
|
if (result == false) {
|
||||||
}
|
RdDCommands._chatAnswer(msg, command.descr);
|
||||||
|
}
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -240,7 +259,7 @@ export class RdDCommands {
|
|||||||
}
|
}
|
||||||
async help(msg, table) {
|
async help(msg, table) {
|
||||||
let commands = []
|
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 html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/settings/dialog-aide-commands.html", { commands: commands });
|
||||||
let d = new Dialog(
|
let d = new Dialog(
|
||||||
@ -366,7 +385,7 @@ export class RdDCommands {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async tableRencontres(msg, params) {
|
async tableRencontres(msg, params) {
|
||||||
if (params && params.length > 0) {
|
if (params && params.length > 0) {
|
||||||
const search = Misc.join(params, ' ');
|
const search = Misc.join(params, ' ');
|
||||||
|
@ -345,17 +345,3 @@ async function migrationPngWebp_1_5_34() {
|
|||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
Hooks.once('diceSoNiceReady', (dice3d) => RdDDice.diceSoNiceReady(dice3d));
|
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