Merge pull request #586 from bdashore3/dev

[IMPORTANT] Fix world info splice method
This commit is contained in:
RossAscends
2023-06-28 14:08:32 +09:00
committed by GitHub
2 changed files with 17 additions and 16 deletions

View File

@ -5544,21 +5544,20 @@ function openCharacterWorldPopup() {
const fileName = getCharaFilename(chid);
const tempExtraBooks = selectedWorlds.map((index) => world_names[index]).filter((e) => e !== undefined);
const existingCharLore = charLore.find((e) => e.name === fileName);
if (existingCharLore) {
if (tempExtraBooks.length === 0) {
charLore.splice(existingCharLore, 1);
} else {
existingCharLore.extraBooks = tempExtraBooks;
}
} else {
const existingCharIndex = charLore.findIndex((e) => e.name === fileName);
if (existingCharIndex === -1) {
const newCharLoreEntry = {
name: fileName,
extraBooks: tempExtraBooks
}
charLore.push(newCharLoreEntry);
} else if (tempExtraBooks.length === 0) {
charLore.splice(existingCharIndex, 1);
} else {
charLore[existingCharIndex].extraBooks = tempExtraBooks;
}
Object.assign(world_info, { charLore: charLore });
saveSettingsDebounced();
}

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();
}