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:
kingbri
2023-06-27 21:01:12 -04:00
parent 9949d5695c
commit 2f2f88dedd
2 changed files with 17 additions and 16 deletions

View File

@ -250,16 +250,18 @@ function displayWorldEntries(name, data) {
return;
}
const existingCharLores = world_info.charLore?.filter((e) => e.extraBooks.includes(name));
if (existingCharLores && existingCharLores.length > 0) {
existingCharLores.forEach((charLore) => {
const tempCharLore = charLore.extraBooks.filter((e) => e !== name);
if (tempCharLore.length === 0) {
world_info.charLore.splice(charLore, 1);
} else {
charLore.extraBooks = tempCharLore;
if (world_info.charLore) {
world_info.charLore.forEach((charLore, index) => {
if (charLore.extraBooks?.includes(name)) {
const tempCharLore = charLore.extraBooks.filter((e) => e !== name);
if (tempCharLore.length === 0) {
world_info.charLore.splice(index, 1);
} else {
charLore.extraBooks = tempCharLore;
}
}
});
saveSettingsDebounced();
}