mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add type conversion for /setvar commands with index
This commit is contained in:
@ -36,6 +36,8 @@ export const enumIcons = {
|
||||
|
||||
true: '✔️',
|
||||
false: '❌',
|
||||
null: '🚫',
|
||||
undefined: '❓',
|
||||
|
||||
// Value types
|
||||
boolean: '🔲',
|
||||
@ -230,4 +232,19 @@ export const commonEnumProviders = {
|
||||
enumTypes.enum, '💉');
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets somewhat recognizable STscript types.
|
||||
*
|
||||
* @returns {SlashCommandEnumValue[]}
|
||||
*/
|
||||
types: () => [
|
||||
new SlashCommandEnumValue('string', null, enumTypes.type, enumIcons.string),
|
||||
new SlashCommandEnumValue('number', null, enumTypes.type, enumIcons.number),
|
||||
new SlashCommandEnumValue('boolean', null, enumTypes.type, enumIcons.boolean),
|
||||
new SlashCommandEnumValue('array', null, enumTypes.type, enumIcons.array),
|
||||
new SlashCommandEnumValue('object', null, enumTypes.type, enumIcons.dictionary),
|
||||
new SlashCommandEnumValue('null', null, enumTypes.type, enumIcons.null),
|
||||
new SlashCommandEnumValue('undefined', null, enumTypes.type, enumIcons.undefined),
|
||||
],
|
||||
};
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { SlashCommandClosure } from './SlashCommandClosure.js';
|
||||
import { convertValueType } from '../utils.js';
|
||||
|
||||
export class SlashCommandScope {
|
||||
/**@type {string[]}*/ variableNames = [];
|
||||
@ -55,7 +56,8 @@ export class SlashCommandScope {
|
||||
if (this.existsVariableInScope(key)) throw new SlashCommandScopeVariableExistsError(`Variable named "${key}" already exists.`);
|
||||
this.variables[key] = value;
|
||||
}
|
||||
setVariable(key, value, index = null) {
|
||||
setVariable(key, value, index = null, type = null) {
|
||||
value = convertValueType(value, type);
|
||||
if (this.existsVariableInScope(key)) {
|
||||
if (index !== null && index !== undefined) {
|
||||
let v = this.variables[key];
|
||||
|
Reference in New Issue
Block a user