Refactor script caching functions to include mode parameter and improve background HTML parsing
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
{#if selIdState.selId > -1}
|
{#if selIdState.selId > -1}
|
||||||
{#key $ReloadGUIPointer}
|
{#key $ReloadGUIPointer}
|
||||||
<div class="absolute top-0 left-0 w-full h-full">
|
<div class="absolute top-0 left-0 w-full h-full">
|
||||||
{#await ParseMarkdown(risuChatParser((backgroundHTML || '') + ($moduleBackgroundEmbedding || ''), {chara:currentChar}), currentChar, 'back') then md}
|
{#await ParseMarkdown(risuChatParser((backgroundHTML || '') + '\n' + ($moduleBackgroundEmbedding || ''), {chara:currentChar}), currentChar, 'back') then md}
|
||||||
{@html md}
|
{@html md}
|
||||||
{/await}
|
{/await}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -67,8 +67,8 @@ export async function importRegex(o?:customscript[]):Promise<customscript[]>{
|
|||||||
let bestMatchCache = new Map<string, string>()
|
let bestMatchCache = new Map<string, string>()
|
||||||
let processScriptCache = new Map<string, string>()
|
let processScriptCache = new Map<string, string>()
|
||||||
|
|
||||||
function cacheScript(scripts:customscript[], data:string, result:string){
|
function cacheScript(scripts:customscript[], data:string, result:string, mode:ScriptMode){
|
||||||
let hash = data + '|||'
|
let hash = data + '|||' + mode + '|||'
|
||||||
for(const script of scripts){
|
for(const script of scripts){
|
||||||
hash += `${script.in}|||${script.out}|||${script.flag}|||${script.ableFlag}|||${script.type}`
|
hash += `${script.in}|||${script.out}|||${script.flag}|||${script.ableFlag}|||${script.type}`
|
||||||
}
|
}
|
||||||
@@ -81,8 +81,8 @@ function cacheScript(scripts:customscript[], data:string, result:string){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getScriptCache(scripts:customscript[], data:string){
|
function getScriptCache(scripts:customscript[], data:string, mode:ScriptMode){
|
||||||
let hash = data + '|||'
|
let hash = data + '|||' + mode + '|||'
|
||||||
for(const script of scripts){
|
for(const script of scripts){
|
||||||
hash += `${script.in}|||${script.out}|||${script.flag}|||${script.ableFlag}|||${script.type}`
|
hash += `${script.in}|||${script.out}|||${script.flag}|||${script.ableFlag}|||${script.type}`
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ export function resetScriptCache(){
|
|||||||
export async function processScriptFull(char:character|groupChat|simpleCharacterArgument, data:string, mode:ScriptMode, chatID = -1, cbsConditions:CbsConditions = {}){
|
export async function processScriptFull(char:character|groupChat|simpleCharacterArgument, data:string, mode:ScriptMode, chatID = -1, cbsConditions:CbsConditions = {}){
|
||||||
let db = getDatabase()
|
let db = getDatabase()
|
||||||
const originalData = data
|
const originalData = data
|
||||||
const cached = getScriptCache((db.globalscript ?? []).concat(char.customscript), originalData)
|
const cached = getScriptCache((db.globalscript ?? []).concat(char.customscript), originalData, mode)
|
||||||
if(cached){
|
if(cached){
|
||||||
return {data: cached, emoChanged: false}
|
return {data: cached, emoChanged: false}
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,7 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
|
|||||||
})
|
})
|
||||||
data = await runLuaEditTrigger(char, mode, data)
|
data = await runLuaEditTrigger(char, mode, data)
|
||||||
if(scripts.length === 0){
|
if(scripts.length === 0){
|
||||||
cacheScript(scripts, originalData, data)
|
cacheScript(scripts, originalData, data, mode)
|
||||||
return {data, emoChanged}
|
return {data, emoChanged}
|
||||||
}
|
}
|
||||||
function executeScript(pscript:pScript){
|
function executeScript(pscript:pScript){
|
||||||
@@ -345,7 +345,7 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cacheScript(scripts, originalData, data)
|
cacheScript(scripts, originalData, data, mode)
|
||||||
|
|
||||||
return {data, emoChanged}
|
return {data, emoChanged}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user