Skip to content

Commit 19a6f48

Browse files
author
prima
committed
feat: Addition of metadata display to character manager
1 parent d31216b commit 19a6f48

File tree

1 file changed

+75
-3
lines changed

1 file changed

+75
-3
lines changed

klite.embd

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37504,14 +37504,81 @@ flowchart TD\n${treeToViewOutput.outputText.trim()}`
3750437504
}
3750537505
else
3750637506
{
37507+
let createDetailsContent = (name) => {
37508+
let contents = document.createElement("div");
37509+
contents.style.color = "white";
37510+
contents.style.padding = "5px";
37511+
let titleElem = document.createElement("span");
37512+
titleElem.classList.add("popuptitletext");
37513+
titleElem.innerText = name;
37514+
titleElem.style.borderBottom = "solid";
37515+
contents.appendChild(titleElem);
37516+
return contents;
37517+
}
37518+
let createSection = (containerElem, section, text) => {
37519+
if (!!text && text.length > 0)
37520+
{
37521+
let sectionContainer = document.createElement("span");
37522+
sectionContainer.style = "width: 100%; display: flex; padding: 10px;";
37523+
let sectionTitle = document.createElement("span"), sectionElem;
37524+
sectionTitle.innerText = section;
37525+
sectionTitle.style = "padding-right: 5px; font-weight: bold;"
37526+
sectionContainer.appendChild(sectionTitle);
37527+
if (Array.isArray(text))
37528+
{
37529+
sectionElem = document.createElement("ul");
37530+
text.forEach(listContent => {
37531+
let listElem = document.createElement("li");
37532+
let summaryOfKey = listContent.length > 100 ? `${listContent.substr(0, 50).trim()}...${listContent.substr(-50).trim()}` : listContent.trim();
37533+
listElem.innerText = summaryOfKey
37534+
sectionElem.appendChild(listElem)
37535+
})
37536+
}
37537+
else
37538+
{
37539+
sectionElem = document.createElement("span");
37540+
sectionElem.innerText = text.trim();
37541+
}
37542+
sectionContainer.appendChild(sectionElem);
37543+
containerElem.appendChild(sectionContainer);
37544+
}
37545+
}
37546+
let lorebookEntryToString = (entry) => {
37547+
return `Primary: ${[...entry?.keys].join(", ")}\nSecondary: ${[...entry?.secondary_keys].join(",")}`;
37548+
}
37549+
let wiEntryToString = (entry) => {
37550+
return `Primary: ${entry?.key}\nSecondary: ${entry?.keysecondary}`;
37551+
}
3750737552
for (let i = 0; i < allCharacterNames.length; i++)
3750837553
{
3750937554
let {name, thumbnail} = allCharacterNames[i], type = getTypeFromAllCharacterData(allCharacterNames[i]);
3751037555
let charIcon = createIcon(name, !!thumbnail ? `url(${thumbnail})` : undefined)
37511-
charIcon.onclick = () => {
37556+
charIcon.onclick = async () => {
3751237557
if (type === "Character")
3751337558
{
37514-
popupUtils.reset().title("Character Options").button("Load character", async () => {
37559+
let data = await getCharacterData(name), {image} = data;
37560+
let {description, first_mes, alternate_greetings, character_book, tags, creator, creator_notes, personality } = (data)?.data;
37561+
let contents = createDetailsContent(name);
37562+
if (!!image)
37563+
{
37564+
let imageContainer = document.createElement("span"), imageElem = document.createElement("img");
37565+
imageElem.src = image;
37566+
imageElem.style = "height: 30%; width: 30%; border-radius: 10px;"
37567+
imageContainer.style = "width: 100%; display: flex; justify-content: space-around; padding: 10px;";
37568+
imageContainer.appendChild(imageElem);
37569+
contents.appendChild(imageContainer);
37570+
}
37571+
createSection(contents, "Creator", creator);
37572+
createSection(contents, "Tags", tags);
37573+
createSection(contents, "Creators notes", creator_notes);
37574+
createSection(contents, "Memory", description);
37575+
createSection(contents, "Alternative greetings", [first_mes, ...alternate_greetings]);
37576+
createSection(contents, "Personality", personality);
37577+
createSection(contents, "World info", character_book?.entries?.map(entry => {
37578+
return lorebookEntryToString(entry);
37579+
}));
37580+
37581+
popupUtils.reset().title("Character Options").content(contents).button("Load character", async () => {
3751537582
popupUtils.reset()
3751637583
let charData = await getCharacterData(name)
3751737584
load_tavern_obj(charData.data);
@@ -37529,7 +37596,12 @@ flowchart TD\n${treeToViewOutput.outputText.trim()}`
3752937596
}
3753037597
else if (type === "World Info")
3753137598
{
37532-
popupUtils.reset().title("World Info Options").button("Add to WI", async () => {
37599+
let data = await getCharacterData(name);
37600+
let contents = createDetailsContent(name);
37601+
createSection(contents, "World info", data?.data?.map(entry => {
37602+
return wiEntryToString(entry);
37603+
}));
37604+
popupUtils.reset().title("World Info Options").content(contents).button("Add to WI", async () => {
3753337605
popupUtils.reset()
3753437606
let charData = await getCharacterData(name)
3753537607
let wiToAdd = charData.data;

0 commit comments

Comments
 (0)