Several million refactoring of existing slash commands with enums (really)

This commit is contained in:
Wolfsblvt
2024-06-17 07:04:10 +02:00
parent 6f7ef25369
commit 66d609c35f
15 changed files with 332 additions and 132 deletions

View File

@ -30,22 +30,27 @@ export const commonEnumProviders = {
},
/**
* All possible character and group names
* All possible char entities, like characters and groups. Can be filtered down to just one type.
*
* @returns {SlashCommandEnumValue[]}
* @param {('all' | 'character' | 'group')?} [mode='all'] - Which type to return
* @returns {() => SlashCommandEnumValue[]}
*/
charName: () => [
...characters.map(it => new SlashCommandEnumValue(it.name, null, 'qr', 'C')),
...groups.map(it => new SlashCommandEnumValue(it.name, null, 'variable', 'G')),
],
charName: (mode) => () => {
mode = mode ?? 'all';
return [
...['all', 'character'].includes(mode) ? characters.map(it => new SlashCommandEnumValue(it.name, null, 'qr', 'C')) : [],
...['all', 'group'].includes(mode) ? groups.map(it => new SlashCommandEnumValue(it.name, null, 'variable', 'G')) : [],
];
},
/**
* All possible tags for a given char/group entity
*
* @param {'all' | 'existing' | 'not-existing'} mode - Which types of tags to show
* @param {('all' | 'existing' | 'not-existing')?} [mode='all'] - Which types of tags to show
* @returns {() => SlashCommandEnumValue[]}
*/
tagsForChar: (mode) => (/** @type {SlashCommandExecutor} */ executor) => {
mode = mode ?? 'all';
// Try to see if we can find the char during execution to filter down the tags list some more. Otherwise take all tags.
const key = searchCharByName(substituteParams(/**@type {string?}*/(executor.namedArgumentList.find(it => it.name == 'name')?.value)), { suppressLogging: true });
const assigned = key ? getTagsList(key) : [];
@ -61,6 +66,14 @@ export const commonEnumProviders = {
worlds: () => $('#world_info').children().toArray().map(x => new SlashCommandEnumValue(x.textContent)),
};
/**
* Get the enum values for boolean type, with class and icon
*
* @return {Array<SlashCommandEnumValue>} An array of SlashCommandEnumValue objects representing the boolean values 'true' and 'false'.
*/
export function getEnumBooleanValues() {
return [new SlashCommandEnumValue('true', null, 'boolean', getEnumIconByValueType('boolean')), new SlashCommandEnumValue('false', null, 'boolean', getEnumIconByValueType('boolean'))];
}
/**
* Get the unicode icon for the given enum value type