From 9d5af396820e85e3b5f5661ece3594c9ed1d895c Mon Sep 17 00:00:00 2001 From: kingbri Date: Sun, 25 Jun 2023 23:51:32 -0400 Subject: [PATCH] World Info: Add rename and delete hooks to char layers If a world info is renamed or deleted, update that in the character lore section of settings as well. Signed-off-by: kingbri --- public/scripts/world-info.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 5428e851f..f244f26d8 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -250,6 +250,19 @@ 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; + } + }); + saveSettingsDebounced(); + } + // Selected world_info automatically refreshes await deleteWorldInfo(name); }); @@ -614,6 +627,16 @@ async function renameWorldInfo(name, data) { await saveWorldInfo(newName, data, true); await deleteWorldInfo(oldName); + const existingCharLores = world_info.charLore.filter((e) => e.extraBooks.includes(oldName)); + if (existingCharLores && existingCharLores.length > 0) { + existingCharLores.forEach((charLore) => { + const tempCharLore = charLore.extraBooks.filter((e) => e !== oldName); + tempCharLore.push(newName); + charLore.extraBooks = tempCharLore; + }); + saveSettingsDebounced(); + } + if (entryPreviouslySelected !== -1) { const wiElement = getWIElement(newName); wiElement.prop("selected", true);