feat: Add default variables to character settings

This commit is contained in:
kwaroran
2024-05-27 12:09:04 +09:00
parent 608dad465b
commit 6d5be694d0
6 changed files with 43 additions and 4 deletions

View File

@@ -9,7 +9,7 @@ import { get } from 'svelte/store';
import css from '@adobe/css-tools'
import { selectedCharID } from './stores';
import { calcString } from './process/infunctions';
import { findCharacterbyId, sfc32, uuidtoNumber } from './util';
import { findCharacterbyId, parseKeyValue, sfc32, uuidtoNumber } from './util';
import { getInlayImage } from './process/files/image';
import { autoMarkNew } from './plugins/automark';
import { getModuleLorebooks } from './process/modules';
@@ -1461,7 +1461,18 @@ export function getChatVar(key:string){
}
const chat = char.chats[char.chatPage]
chat.scriptstate = chat.scriptstate ?? {}
return (chat.scriptstate['$' + key])?.toString() ?? 'null'
const state = (chat.scriptstate['$' + key])
if(state === undefined || state === null){
const defaultVariables = parseKeyValue(char.defaultVariables).concat(parseKeyValue(db.templateDefaultVariables))
const findResult = defaultVariables.find((f) => {
return f[0] === key
})
if(findResult){
return findResult[1]
}
return 'null'
}
return state.toString()
}
export function getGlobalChatVar(key:string){