Fix creation of characters with additional WI files assigned

257883a5f929ca45f9eac96fc0c869c9c936102b

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +17 -1Showing whitespace changes
public/script.js+17 -1
@@ -882,6 +882,7 @@ export let create_save = {
882882 depth_prompt_depth: depth_prompt_depth_default,
883883 depth_prompt_role: depth_prompt_role_default,
884884 extensions: {},
885+ extra_books: [],
885886};
886887
887888//animation right menu
@@ -8986,6 +8987,11 @@ async function openCharacterWorldPopup() {
89868987 const tempExtraBooks = selectedWorlds.map((index) => world_names[index]).filter(Boolean);
89878988 const existingCharIndex = charLore.findIndex((e) => e.name === fileName);
89888989
8990+ if (menu_type == 'create') {
8991+ create_save.extra_books = tempExtraBooks;
8992+ return;
8993+ }
8994+
89898995 if (existingCharIndex === -1) {
89908996 // Add record only if at least 1 lorebook is selected.
89918997 if (tempExtraBooks.length > 0) {
@@ -9012,7 +9018,8 @@ async function openCharacterWorldPopup() {
90129018 const extrasSelect = template.find('.character_extra_world_info_selector');
90139019 const existingCharLore = world_info.charLore?.find((e) => e.name === fileName);
90149020 world_names.forEach((item, i) => {
9015- const isSelected = !!existingCharLore?.extraBooks.includes(item);
9021+ const array = (menu_type == 'create' ? create_save.extra_books : existingCharLore?.extraBooks);
9022+ const isSelected = !!array?.includes(item);
90169023 extrasSelect.append(new Option(item, String(i), isSelected, isSelected));
90179024 });
90189025
@@ -9199,6 +9206,15 @@ async function createOrEditCharacter(e) {
91999206 field.callback && field.callback(fieldValue);
92009207 });
92019208
9209+ if (Array.isArray(create_save.extra_books) && create_save.extra_books.length > 0) {
9210+ const fileName = getCharaFilename(null, { manualAvatarKey: avatarId });
9211+ const charLore = world_info.charLore ?? [];
9212+ charLore.push({ name: fileName, extraBooks: create_save.extra_books });
9213+ Object.assign(world_info, { charLore: charLore });
9214+ saveSettingsDebounced();
9215+ }
9216+ create_save.extra_books = [];
9217+
92029218 $('#character_popup-button-h3').text('Create character');
92039219
92049220 create_save.avatar = null;