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 <bdashore3@proton.me>
This commit is contained in:
kingbri
2023-06-25 23:51:32 -04:00
parent b6fbe41f93
commit 9d5af39682

View File

@ -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);