refactor(parser): cleanup & add getEmoSrc()
This commit is contained in:
committed by
ThePotioner(Dong Hyun Kim)
parent
b3587fc950
commit
997b4f70ce
@@ -293,7 +293,6 @@ async function renderHighlightableMarkdown(data:string) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const assetRegex = /{{(raw|path|img|image|video|audio|bg|emotion|asset|video-img|source)::(.+?)}}/gms
|
export const assetRegex = /{{(raw|path|img|image|video|audio|bg|emotion|asset|video-img|source)::(.+?)}}/gms
|
||||||
|
|
||||||
async function replaceAsync(string, regexp, replacerFunction) {
|
async function replaceAsync(string, regexp, replacerFunction) {
|
||||||
@@ -304,32 +303,27 @@ async function replaceAsync(string, regexp, replacerFunction) {
|
|||||||
return string.replace(regexp, () => replacements[i++]);
|
return string.replace(regexp, () => replacements[i++]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAssetSrc(assetArr: string[][], name: string, assetPaths?: {[key: string]:{path: string, ext?: string}}, emoPaths?: {[key: string]:{path: string, ext?: string}}) {
|
async function getAssetSrc(assetArr: string[][], name: string, assetPaths: {[key: string]:{path: string, ext?: string}}) {
|
||||||
name = name.toLocaleLowerCase()
|
name = name.toLocaleLowerCase()
|
||||||
if (assetPaths) {
|
|
||||||
for (const asset of assetArr) {
|
for (const asset of assetArr) {
|
||||||
if (trimmer(asset[0].toLocaleLowerCase()) !== trimmer(name)) continue;
|
if (trimmer(asset[0].toLocaleLowerCase()) !== trimmer(name)) continue;
|
||||||
console.log("In getAssets() > Catch Asset : " + asset[0])
|
|
||||||
console.log("In getAssets() > Asset Path : " + asset[1])
|
|
||||||
const assetPath = await getFileSrc(asset[1])
|
const assetPath = await getFileSrc(asset[1])
|
||||||
assetPaths[name] = {
|
assetPaths[asset[0].toLocaleLowerCase()] = {
|
||||||
path: assetPath,
|
path: assetPath,
|
||||||
ext: asset[2]
|
ext: asset[2]
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (emoPaths) {
|
|
||||||
for(const emo of assetArr){
|
async function getEmoSrc(emoArr: string[][], emoPaths: {[key: string]:{path: string}}) {
|
||||||
if (trimmer(emo[0].toLocaleLowerCase()) !== trimmer(name)) continue;
|
for (const emo of emoArr) {
|
||||||
console.log("In getAssets() > Catch Asset(emo) : " + emo[0])
|
|
||||||
console.log("In getAssets() > Asset Path(emo) : " + emo[1])
|
|
||||||
const emoPath = await getFileSrc(emo[1])
|
const emoPath = await getFileSrc(emo[1])
|
||||||
emoPaths[name] = {
|
emoPaths[emo[0].toLocaleLowerCase()] = {
|
||||||
path: emoPath,
|
path: emoPath,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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 assetWidthString = (DBState.db.assetWidth && DBState.db.assetWidth !== -1 || DBState.db.assetWidth === 0) ? `max-width:${DBState.db.assetWidth}rem;` : ''
|
const assetWidthString = (DBState.db.assetWidth && DBState.db.assetWidth !== -1 || DBState.db.assetWidth === 0) ? `max-width:${DBState.db.assetWidth}rem;` : ''
|
||||||
@@ -342,6 +336,8 @@ async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|c
|
|||||||
path:string
|
path:string
|
||||||
}} = {}
|
}} = {}
|
||||||
|
|
||||||
|
if (char.emotionImages) getEmoSrc(char.emotionImages, emoPaths)
|
||||||
|
|
||||||
const videoExtention = ['mp4', 'webm', 'avi', 'm4p', 'm4v']
|
const videoExtention = ['mp4', 'webm', 'avi', 'm4p', 'm4v']
|
||||||
let needsSourceAccess = false
|
let needsSourceAccess = false
|
||||||
|
|
||||||
@@ -350,15 +346,10 @@ async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|c
|
|||||||
if (char.additionalAssets) {
|
if (char.additionalAssets) {
|
||||||
await getAssetSrc(char.additionalAssets, name, assetPaths);
|
await getAssetSrc(char.additionalAssets, name, assetPaths);
|
||||||
}
|
}
|
||||||
if (char.emotionImages) {
|
|
||||||
await getAssetSrc(char.emotionImages, name, assetPaths, emoPaths);
|
|
||||||
}
|
|
||||||
if (moduleAssets.length > 0) {
|
if (moduleAssets.length > 0) {
|
||||||
await getAssetSrc(moduleAssets, name, assetPaths);
|
await getAssetSrc(moduleAssets, name, assetPaths);
|
||||||
}
|
}
|
||||||
console.log("In parseAdditionalAssets() > Name: " + name)
|
|
||||||
console.log("In parseAdditionalAssets() > Char Obj: ", char)
|
|
||||||
console.log("In parseAdditionalAssets() > Char Type: " + char.type)
|
|
||||||
if(type === 'emotion'){
|
if(type === 'emotion'){
|
||||||
const path = emoPaths[name]?.path
|
const path = emoPaths[name]?.path
|
||||||
if(!path){
|
if(!path){
|
||||||
@@ -366,6 +357,7 @@ 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'){
|
if(type === 'source'){
|
||||||
needsSourceAccess = true
|
needsSourceAccess = true
|
||||||
switch(name){
|
switch(name){
|
||||||
@@ -377,7 +369,9 @@ async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = assetPaths[name]
|
let path = assetPaths[name]
|
||||||
|
|
||||||
if(!path){
|
if(!path){
|
||||||
if(DBState.db.legacyMediaFindings){
|
if(DBState.db.legacyMediaFindings){
|
||||||
return ''
|
return ''
|
||||||
@@ -463,9 +457,6 @@ async function getClosestMatch(char: simpleCharacterArgument|character, name:str
|
|||||||
ext: targetExt
|
ext: targetExt
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("In getClosestMatch() > assetPaths[closest]: ", assetPaths[closest])
|
|
||||||
console.log("In getClosestMatch() > closet, closetDist: " + closest, closestDist)
|
|
||||||
|
|
||||||
return assetPaths[closest]
|
return assetPaths[closest]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user