Add CurrentCharacter import
This commit is contained in:
@@ -5,7 +5,7 @@ import { getFileSrc } from './storage/globalApi';
|
|||||||
import { processScriptFull } from './process/scripts';
|
import { processScriptFull } from './process/scripts';
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
import css from '@adobe/css-tools'
|
import css from '@adobe/css-tools'
|
||||||
import { CurrentChat, SizeStore, selectedCharID } from './stores';
|
import { CurrentCharacter, CurrentChat, SizeStore, selectedCharID } from './stores';
|
||||||
import { calcString } from './process/infunctions';
|
import { calcString } from './process/infunctions';
|
||||||
import { findCharacterbyId, parseKeyValue, sfc32, sleep, uuidtoNumber } from './util';
|
import { findCharacterbyId, parseKeyValue, sfc32, sleep, uuidtoNumber } from './util';
|
||||||
import { getInlayImage, writeInlayImage } from './process/files/image';
|
import { getInlayImage, writeInlayImage } from './process/files/image';
|
||||||
@@ -242,14 +242,12 @@ async function renderHighlightableMarkdown(data:string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const assetRegex = /{{(raw|img|video|audio|bg|emotion|asset|video-img)::(.+?)}}/g
|
export const assetRegex = /{{(raw|img|video|audio|bg|emotion|asset|video-img|source)::(.+?)}}/g
|
||||||
|
|
||||||
async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|character, mode:'normal'|'back', mode2:'unset'|'pre'|'post' = 'unset'){
|
async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|character, mode:'normal'|'back', mode2:'unset'|'pre'|'post' = 'unset'){
|
||||||
const db = get(DataBase)
|
const db = get(DataBase)
|
||||||
const assetWidthString = (db.assetWidth && db.assetWidth !== -1 || db.assetWidth === 0) ? `max-width:${db.assetWidth}rem;` : ''
|
const assetWidthString = (db.assetWidth && db.assetWidth !== -1 || db.assetWidth === 0) ? `max-width:${db.assetWidth}rem;` : ''
|
||||||
|
|
||||||
if(char.additionalAssets || char.emotionImages){
|
|
||||||
|
|
||||||
let assetPaths:{[key:string]:{
|
let assetPaths:{[key:string]:{
|
||||||
path:string
|
path:string
|
||||||
ext?:string
|
ext?:string
|
||||||
@@ -276,6 +274,7 @@ async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const videoExtention = ['mp4', 'webm', 'avi', 'm4p', 'm4v']
|
const videoExtention = ['mp4', 'webm', 'avi', 'm4p', 'm4v']
|
||||||
|
let needsSourceAccess = false
|
||||||
data = data.replaceAll(assetRegex, (full:string, type:string, name:string) => {
|
data = data.replaceAll(assetRegex, (full:string, type:string, name:string) => {
|
||||||
name = name.toLocaleLowerCase()
|
name = name.toLocaleLowerCase()
|
||||||
if(type === 'emotion'){
|
if(type === 'emotion'){
|
||||||
@@ -285,6 +284,17 @@ async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|c
|
|||||||
}
|
}
|
||||||
return `<img src="${path}" alt="${path}" style="${assetWidthString} "/>`
|
return `<img src="${path}" alt="${path}" style="${assetWidthString} "/>`
|
||||||
}
|
}
|
||||||
|
if(type === 'source'){
|
||||||
|
needsSourceAccess = true
|
||||||
|
switch(name){
|
||||||
|
case 'char':{
|
||||||
|
return '\uE9b4CHAR\uE9b4'
|
||||||
|
}
|
||||||
|
case 'user': {
|
||||||
|
return '\uE9b4USER\uE9b4'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
const path = assetPaths[name]
|
const path = assetPaths[name]
|
||||||
if(!path){
|
if(!path){
|
||||||
return ''
|
return ''
|
||||||
@@ -314,7 +324,19 @@ async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|c
|
|||||||
}
|
}
|
||||||
return ''
|
return ''
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if(needsSourceAccess){
|
||||||
|
const chara = get(CurrentCharacter)
|
||||||
|
if(chara.image){}
|
||||||
|
data = data.replace(/\uE9b4CHAR\uE9b4/g,
|
||||||
|
chara.image ? (await getFileSrc(chara.image)) : ''
|
||||||
|
)
|
||||||
|
|
||||||
|
data = data.replace(/\uE9b4USER\uE9b4/g,
|
||||||
|
db.userIcon ? (await getFileSrc(db.userIcon)) : ''
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user