mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
World Info: Fix array splice method
Character lore layers used array.splice() in the wrong way. Somehow this passed my testing through sheer luck. Rewrite for using indicies to splice and for more efficiency with iteration. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
@ -5543,21 +5543,20 @@ function openCharacterWorldPopup() {
|
|||||||
const fileName = getCharaFilename(chid);
|
const fileName = getCharaFilename(chid);
|
||||||
const tempExtraBooks = selectedWorlds.map((index) => world_names[index]).filter((e) => e !== undefined);
|
const tempExtraBooks = selectedWorlds.map((index) => world_names[index]).filter((e) => e !== undefined);
|
||||||
|
|
||||||
const existingCharLore = charLore.find((e) => e.name === fileName);
|
const existingCharIndex = charLore.findIndex((e) => e.name === fileName);
|
||||||
if (existingCharLore) {
|
if (existingCharIndex === -1) {
|
||||||
if (tempExtraBooks.length === 0) {
|
|
||||||
charLore.splice(existingCharLore, 1);
|
|
||||||
} else {
|
|
||||||
existingCharLore.extraBooks = tempExtraBooks;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const newCharLoreEntry = {
|
const newCharLoreEntry = {
|
||||||
name: fileName,
|
name: fileName,
|
||||||
extraBooks: tempExtraBooks
|
extraBooks: tempExtraBooks
|
||||||
}
|
}
|
||||||
|
|
||||||
charLore.push(newCharLoreEntry);
|
charLore.push(newCharLoreEntry);
|
||||||
|
} else if (tempExtraBooks.length === 0) {
|
||||||
|
charLore.splice(existingCharIndex, 1);
|
||||||
|
} else {
|
||||||
|
charLore[existingCharIndex].extraBooks = tempExtraBooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(world_info, { charLore: charLore });
|
Object.assign(world_info, { charLore: charLore });
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
}
|
}
|
||||||
|
@ -250,16 +250,18 @@ function displayWorldEntries(name, data) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const existingCharLores = world_info.charLore?.filter((e) => e.extraBooks.includes(name));
|
if (world_info.charLore) {
|
||||||
if (existingCharLores && existingCharLores.length > 0) {
|
world_info.charLore.forEach((charLore, index) => {
|
||||||
existingCharLores.forEach((charLore) => {
|
if (charLore.extraBooks?.includes(name)) {
|
||||||
const tempCharLore = charLore.extraBooks.filter((e) => e !== name);
|
const tempCharLore = charLore.extraBooks.filter((e) => e !== name);
|
||||||
if (tempCharLore.length === 0) {
|
if (tempCharLore.length === 0) {
|
||||||
world_info.charLore.splice(charLore, 1);
|
world_info.charLore.splice(index, 1);
|
||||||
} else {
|
} else {
|
||||||
charLore.extraBooks = tempCharLore;
|
charLore.extraBooks = tempCharLore;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user