mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	add scoped vars and fix hiding (scope->local->global)
This commit is contained in:
		| @@ -6,6 +6,7 @@ import { searchCharByName, getTagsList, tags } from "../tags.js"; | |||||||
| import { SlashCommandClosure } from "./SlashCommandClosure.js"; | import { SlashCommandClosure } from "./SlashCommandClosure.js"; | ||||||
| import { SlashCommandEnumValue, enumTypes } from "./SlashCommandEnumValue.js"; | import { SlashCommandEnumValue, enumTypes } from "./SlashCommandEnumValue.js"; | ||||||
| import { SlashCommandExecutor } from "./SlashCommandExecutor.js"; | import { SlashCommandExecutor } from "./SlashCommandExecutor.js"; | ||||||
|  | import { SlashCommandScope } from "./SlashCommandScope.js"; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * A collection of regularly used enum icons |  * A collection of regularly used enum icons | ||||||
| @@ -134,16 +135,16 @@ export const commonEnumProviders = { | |||||||
|      * Can be filtered by `type` to only show global or local variables |      * Can be filtered by `type` to only show global or local variables | ||||||
|      * |      * | ||||||
|      * @param {...('global'|'local'|'scope'|'all')} type - The type of variables to include in the array. Can be 'all', 'global', or 'local'. |      * @param {...('global'|'local'|'scope'|'all')} type - The type of variables to include in the array. Can be 'all', 'global', or 'local'. | ||||||
|      * @returns {() => SlashCommandEnumValue[]} |      * @returns {(executor:SlashCommandExecutor, scope:SlashCommandScope) => SlashCommandEnumValue[]} | ||||||
|      */ |      */ | ||||||
|     variables: (...type) => () => { |     variables: (...type) => (executor, scope) => { | ||||||
|         const types = type.flat(); |         const types = type.flat(); | ||||||
|         const isAll = types.includes('all'); |         const isAll = types.includes('all'); | ||||||
|         return [ |         return [ | ||||||
|             ...isAll || types.includes('global') ? Object.keys(extension_settings.variables.global ?? []).map(name => new SlashCommandEnumValue(name, null, enumTypes.macro, enumIcons.globalVariable)) : [], |             ...isAll || types.includes('scope') ? scope.allVariableNames.map(name => new SlashCommandEnumValue(name, null, enumTypes.variable, enumIcons.scopeVariable)) : [], | ||||||
|             ...isAll || types.includes('local') ? Object.keys(chat_metadata.variables ?? []).map(name => new SlashCommandEnumValue(name, null, enumTypes.name, enumIcons.localVariable)) : [], |             ...isAll || types.includes('local') ? Object.keys(chat_metadata.variables ?? []).map(name => new SlashCommandEnumValue(name, null, enumTypes.name, enumIcons.localVariable)) : [], | ||||||
|             ...isAll || types.includes('scope') ? [].map(name => new SlashCommandEnumValue(name, null, enumTypes.variable, enumIcons.scopeVariable)) : [], // TODO: Add scoped variables here, Lenny |             ...isAll || types.includes('global') ? Object.keys(extension_settings.variables.global ?? []).map(name => new SlashCommandEnumValue(name, null, enumTypes.macro, enumIcons.globalVariable)) : [], | ||||||
|         ]; |         ].filter((item, idx, list)=>idx == list.findIndex(it=>it.value == item.value)); | ||||||
|     }, |     }, | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user