Fixes mineurs #583
@ -58,7 +58,7 @@ export class Environnement {
|
|||||||
const milieux = new Set(this.getMilieuxSettings());
|
const milieux = new Set(this.getMilieuxSettings());
|
||||||
const elements = await this.getElements(it => 1, it => ITEM_ENVIRONNEMENT_TYPES.includes(it.type));
|
const elements = await this.getElements(it => 1, it => ITEM_ENVIRONNEMENT_TYPES.includes(it.type));
|
||||||
elements.forEach(it => it.system.environnement.forEach(env => milieux.add(env.milieu)))
|
elements.forEach(it => it.system.environnement.forEach(env => milieux.add(env.milieu)))
|
||||||
return [...milieux];
|
return [...milieux].filter(env => env);
|
||||||
}
|
}
|
||||||
|
|
||||||
getMilieuxSettings() {
|
getMilieuxSettings() {
|
||||||
@ -66,22 +66,34 @@ export class Environnement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findEnvironnementsLike(search) {
|
async findEnvironnementsLike(search) {
|
||||||
return (await this.milieux()).filter(it => Grammar.includesLowerCaseNoAccent(it, search));
|
const milieux = (await this.milieux()).filter(it => Grammar.includesLowerCaseNoAccent(it, search));
|
||||||
|
if (milieux.length > 1){
|
||||||
|
const milieuExact = milieux.find(it => Grammar.equalsInsensitive(it, search));
|
||||||
|
if (milieuExact) {
|
||||||
|
return [milieuExact];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return milieux;
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchToChatMessage(search) {
|
async searchToChatMessage(milieux, typeName) {
|
||||||
const table = await this.buildEnvironnementTable(search);
|
const table = await this.buildEnvironnementTable(milieux);
|
||||||
await CompendiumTableHelpers.tableToChatMessage(table, 'Item', ITEM_ENVIRONNEMENT_TYPES, `ressources en "${search}"`);
|
await CompendiumTableHelpers.tableToChatMessage(table, 'Item', ITEM_ENVIRONNEMENT_TYPES, typeName);
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRandom(search) {
|
async getRandom(milieux, typeName) {
|
||||||
const table = await this.buildEnvironnementTable(search);
|
const table = await this.buildEnvironnementTable(milieux);
|
||||||
return await CompendiumTableHelpers.getRandom(table, 'Item', ITEM_ENVIRONNEMENT_TYPES, undefined, `ressources en "${search}"`);
|
return await CompendiumTableHelpers.getRandom(table, 'Item', ITEM_ENVIRONNEMENT_TYPES, undefined, typeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
async buildEnvironnementTable(search) {
|
async buildEnvironnementTable(milieux) {
|
||||||
const itemRareteEnMilieu = item => item.system?.environnement.find(env => Grammar.includesLowerCaseNoAccent(env.milieu, search));
|
const filterMilieux = item => item.system?.environnement.filter(env => milieux.includes(env.milieu));
|
||||||
|
const itemRareteEnMilieu = item => {
|
||||||
|
const raretes = filterMilieux(item);
|
||||||
|
const frequenceMax = Math.max(raretes.map(env => env.frequence));
|
||||||
|
return raretes.find(env => env.frequence == frequenceMax);
|
||||||
|
}
|
||||||
const itemFrequenceEnMilieu = item => itemRareteEnMilieu(item)?.frequence ?? 0;
|
const itemFrequenceEnMilieu = item => itemRareteEnMilieu(item)?.frequence ?? 0;
|
||||||
const isPresentEnMilieu = item => itemFrequenceEnMilieu(item) > 0;
|
const isPresentEnMilieu = item => itemFrequenceEnMilieu(item) > 0;
|
||||||
return await this.table.buildTable(itemFrequenceEnMilieu, isPresentEnMilieu);
|
return await this.table.buildTable(itemFrequenceEnMilieu, isPresentEnMilieu);
|
||||||
@ -139,7 +151,7 @@ export class EnvironmentSheetHelper {
|
|||||||
|
|
||||||
static activateListeners(sheet, html) {
|
static activateListeners(sheet, html) {
|
||||||
if (!sheet.options.editable) return;
|
if (!sheet.options.editable) return;
|
||||||
html.find("a.milieu-add").click(event => EnvironmentSheetHelper.onAddMilieu(sheet, event));
|
html.find("a.milieu-add").click(event => EnvironmentSheetHelper.onAddMilieu(html, sheet, event));
|
||||||
html.find("div.environnement-milieu a.milieu-delete").click(event => EnvironmentSheetHelper.onDeleteMilieu(sheet, event));
|
html.find("div.environnement-milieu a.milieu-delete").click(event => EnvironmentSheetHelper.onDeleteMilieu(sheet, event));
|
||||||
html.find("div.environnement-milieu select.environnement-rarete").change(event => EnvironmentSheetHelper.onChange(sheet, event,
|
html.find("div.environnement-milieu select.environnement-rarete").change(event => EnvironmentSheetHelper.onChange(sheet, event,
|
||||||
(updated) => {
|
(updated) => {
|
||||||
@ -156,8 +168,8 @@ export class EnvironmentSheetHelper {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
static async onAddMilieu(sheet, event) {
|
static async onAddMilieu(html, sheet, event) {
|
||||||
const milieu = $("input.input-selection-milieu").val();
|
const milieu = html.find('input.input-selection-milieu').val();
|
||||||
if (!milieu) {
|
if (!milieu) {
|
||||||
ui.notifications.warn(`Choisissez le milieu dans lequel se trouve le/la ${sheet.item.name}`);
|
ui.notifications.warn(`Choisissez le milieu dans lequel se trouve le/la ${sheet.item.name}`);
|
||||||
return
|
return
|
||||||
|
@ -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,7 +63,7 @@ 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" });
|
||||||
@ -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;
|
||||||
|
|
||||||
let command = commandLine[0].toLowerCase();
|
if (!this.commandsTable) {
|
||||||
let params = commandLine.slice(1);
|
this._registerCommands();
|
||||||
|
}
|
||||||
|
|
||||||
return this.process(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
||||||
@ -382,15 +401,20 @@ export class RdDCommands {
|
|||||||
async tableMilieu(msg, params, toChat) {
|
async tableMilieu(msg, params, toChat) {
|
||||||
if (params && params.length > 0) {
|
if (params && params.length > 0) {
|
||||||
const search = Misc.join(params, ' ');
|
const search = Misc.join(params, ' ');
|
||||||
const searches = game.system.rdd.environnement.findEnvironnementsLike(search);
|
const milieux = await game.system.rdd.environnement.findEnvironnementsLike(search);
|
||||||
if (searches.length == 0) {
|
if (milieux.length == 0) {
|
||||||
return RdDCommands._chatAnswer(msg, 'Aucun milieu correspondant à ' + search);
|
return RdDCommands._chatAnswer(msg, 'Aucun milieu correspondant à ' + search);
|
||||||
}
|
}
|
||||||
|
if (milieux.length > 1) {
|
||||||
|
ui.notifications.warn(`<strong>Plusieurs milieux correspondent à '${search}'</strong>:
|
||||||
|
<br><ul><li>${milieux.reduce(Misc.joining('</li><li>'))}</li></ul>`);
|
||||||
|
}
|
||||||
|
const tableName = `ressources en ${milieux.reduce(Misc.joining(', '))}`;
|
||||||
if (toChat == 'liste') {
|
if (toChat == 'liste') {
|
||||||
return await game.system.rdd.environnement.searchToChatMessage(search);
|
return await game.system.rdd.environnement.searchToChatMessage(milieux, tableName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const row = await game.system.rdd.environnement.getRandom(search);
|
const row = await game.system.rdd.environnement.getRandom(milieux, tableName);
|
||||||
await CompendiumTableHelpers.tableRowToChatMessage(row, 'Item');
|
await CompendiumTableHelpers.tableRowToChatMessage(row, 'Item');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
@ -947,23 +947,23 @@ ul, li {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
ul.list-item-margin1 {
|
ul.list-item-margin1 li {
|
||||||
margin-left: 0.5rem;
|
margin-left: 0.8rem;
|
||||||
}
|
}
|
||||||
ul.list-item-margin2 {
|
ul.list-item-margin2 li {
|
||||||
margin-left: 1rem;
|
margin-left: 1.6rem;
|
||||||
}
|
}
|
||||||
ul.list-item-margin3 {
|
ul.list-item-margin3 li {
|
||||||
margin-left: 1.5rem;
|
margin-left: 2.4rem;
|
||||||
}
|
}
|
||||||
ul.list-item-margin4 {
|
ul.list-item-margin4 li {
|
||||||
margin-left: 2rem;
|
margin-left: 3.2rem;
|
||||||
}
|
}
|
||||||
ul.list-item-margin5 {
|
ul.list-item-margin5 li {
|
||||||
margin-left: 2.5rem;
|
margin-left: 4rem;
|
||||||
}
|
}
|
||||||
ul.list-item-margin6 {
|
ul.list-item-margin6 li {
|
||||||
margin-left: 3rem;
|
margin-left: 4.8rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.grid-select-type-tmr {
|
.grid-select-type-tmr {
|
||||||
|
Loading…
Reference in New Issue
Block a user