diff --git a/src/lib/SideBars/Scripts/TriggerList2.svelte b/src/lib/SideBars/Scripts/TriggerList2.svelte index be7f7e04..7ed5bc2c 100644 --- a/src/lib/SideBars/Scripts/TriggerList2.svelte +++ b/src/lib/SideBars/Scripts/TriggerList2.svelte @@ -150,9 +150,11 @@ $effect(() => { if(menuMode === 0){ addElse = false - setTimeout(() => { - menu0Container.scrollTop = menu0ScrollPosition - }, 0) + if(menu0Container) { + setTimeout(() => { + menu0Container.scrollTop = menu0ScrollPosition + }, 0) + } } else if(menuMode === 1 || menuMode === 2 || menuMode === 3) { if(menu0Container) { menu0ScrollPosition = menu0Container.scrollTop @@ -1013,6 +1015,12 @@ if(effect[p1 + 'Type'] === 'value'){ return `"${d}"` } + if(effect.type === 'v2If' && p1 === 'source'){ + return `${d || 'null'}` + } + if(effect.type === 'v2SetVar' && p1 === 'var'){ + return `${d || 'null'}` + } return `${d || 'null'}` }) diff --git a/src/lib/SideBars/Toggles.svelte b/src/lib/SideBars/Toggles.svelte index afefa2bd..41402bda 100644 --- a/src/lib/SideBars/Toggles.svelte +++ b/src/lib/SideBars/Toggles.svelte @@ -1,10 +1,11 @@ -{#snippet toggles(reverse: boolean = false)} - {#each parsedKv as toggle} - {#if toggle.type === 'select'} -
+{#snippet toggles(items: sidebarToggle[], reverse: boolean = false)} + {#each items as toggle, index} + {#if toggle.type === 'group' && toggle.children.length > 0} +
+ + {@render toggles((toggle as sidebarToggleGroup).children, reverse)} + +
+ {:else if toggle.type === 'select'} +
{toggle.value} - {#each toggle.options as option, i} {option} @@ -33,12 +56,23 @@
{:else if toggle.type === 'text'} -
+
{toggle.value}
+ {:else if toggle.type === 'divider'} + {@const prevToggle = groupedToggles[index - 1]} + + {#if index === 0 || prevToggle.type !== 'divider' || prevToggle.value !== toggle.value} +
+ {#if toggle.value} + {toggle.value} + {/if} +
+
+ {/if} {:else} -
+
{ DBState.db.globalChatVariables[`toggle_${toggle.key}`] = DBState.db.globalChatVariables[`toggle_${toggle.key}`] === '1' ? '0' : '1' }} /> @@ -47,12 +81,12 @@ {/each} {/snippet} -{#if !noContainer && parsedKv.length > 4} +{#if !noContainer && groupedToggles.length > 4}
- {@render toggles(true)} + {@render toggles(groupedToggles, true)} {#if DBState.db.supaModelType !== 'none' || DBState.db.hanuraiEnable || DBState.db.hypaV3}
@@ -63,7 +97,7 @@
- {@render toggles()} + {@render toggles(groupedToggles)} {#if DBState.db.supaModelType !== 'none' || DBState.db.hanuraiEnable || DBState.db.hypaV3}
diff --git a/src/ts/process/lua.ts b/src/ts/process/lua.ts index 049a7fa1..6f8d94fb 100644 --- a/src/ts/process/lua.ts +++ b/src/ts/process/lua.ts @@ -109,6 +109,20 @@ export async function runLua(code:string, arg:{ } return alertSelect(value) }) + + luaEngine.global.set('getChatMain', (id:string, index:number) => { + const chat = luaEngineState.chat.message.at(index) + if(!chat){ + return JSON.stringify(null) + } + const data = { + role: chat.role, + data: chat.data, + time: chat.time ?? 0 + } + return JSON.stringify(data) + }) + luaEngine.global.set('setChat', (id:string, index:number, value:string) => { if(!LuaSafeIds.has(id)){ return @@ -153,12 +167,14 @@ export async function runLua(code:string, arg:{ let roleData:'user'|'char' = role === 'user' ? 'user' : 'char' luaEngineState.chat.message.splice(index, 0, {role: roleData, data: value}) }) + luaEngine.global.set('getTokens', async (id:string, value:string) => { if(!LuaSafeIds.has(id)){ return } return await tokenize(value) }) + luaEngine.global.set('getChatLength', (id:string) => { return luaEngineState.chat.message.length }) @@ -173,7 +189,7 @@ export async function runLua(code:string, arg:{ })) return data }) - + luaEngine.global.set('setFullChatMain', (id:string, value:string) => { if(!LuaSafeIds.has(id)){ return @@ -771,6 +787,10 @@ function luaCodeWarper(code:string){ return ` json = require 'json' +function getChat(id, index) + return json.decode(getChatMain(id, index)) +end + function getFullChat(id) return json.decode(getFullChatMain(id)) end diff --git a/src/ts/util.ts b/src/ts/util.ts index c80360a2..1c20da11 100644 --- a/src/ts/util.ts +++ b/src/ts/util.ts @@ -1009,33 +1009,69 @@ export function parseKeyValue(template:string){ } } +export type sidebarToggleGroup = { + key?:string, + value?:string, + type:'group', + children:sidebarToggle[] +} + +export type sidebarToggleGroupEnd = { + key?:string, + value?:string, + type:'groupEnd', +} + +export type sidebarToggle = + | sidebarToggleGroup + | sidebarToggleGroupEnd + | { + key?:string, + value?:string, + type:'divider', + } + | { + key:string, + value:string, + type:'select', + options:string[] + } + | { + key:string, + value:string, + type:'text'|undefined, + options?:string[] + } + export function parseToggleSyntax(template:string){ try { - console.log(template) if(!template){ return [] } - const keyValue:{ - key:string, - value:string, - type?:string, - options?:string[] - }[] = [] + const keyValue:sidebarToggle[] = [] const splited = template.split('\n') for(const line of splited){ const [key, value, type, option] = line.split('=') - if(key && value){ + if(type === 'group' || type === 'groupEnd' || type === 'divider'){ keyValue.push({ - key, value, type, options: option ? option.split(',') : [] + key, + value, + type, + children: [] + }) + } else if((key && value)){ + keyValue.push({ + key, + value, + type: type === 'select' || type === 'text' ? type : undefined, + options: option?.split(',') ?? [] }) } } - console.log(keyValue) - return keyValue } catch (error) { console.error(error)