Fix creation of characters with additional WI files assigned
| @@ -882,6 +882,7 @@ export let create_save = { | |||
| 882 | depth_prompt_depth: depth_prompt_depth_default, | 882 | depth_prompt_depth: depth_prompt_depth_default, |
| 883 | depth_prompt_role: depth_prompt_role_default, | 883 | depth_prompt_role: depth_prompt_role_default, |
| 884 | extensions: {}, | 884 | extensions: {}, |
| 885 | extra_books: [], | ||
| 885 | }; | 886 | }; |
| 886 | 887 | ||
| 887 | //animation right menu | 888 | //animation right menu |
| @@ -8986,6 +8987,11 @@ async function openCharacterWorldPopup() { | |||
| 8986 | const tempExtraBooks = selectedWorlds.map((index) => world_names[index]).filter(Boolean); | 8987 | const tempExtraBooks = selectedWorlds.map((index) => world_names[index]).filter(Boolean); |
| 8987 | const existingCharIndex = charLore.findIndex((e) => e.name === fileName); | 8988 | const existingCharIndex = charLore.findIndex((e) => e.name === fileName); |
| 8988 | 8989 | ||
| 8990 | if (menu_type == 'create') { | ||
| 8991 | create_save.extra_books = tempExtraBooks; | ||
| 8992 | return; | ||
| 8993 | } | ||
| 8994 | |||
| 8989 | if (existingCharIndex === -1) { | 8995 | if (existingCharIndex === -1) { |
| 8990 | // Add record only if at least 1 lorebook is selected. | 8996 | // Add record only if at least 1 lorebook is selected. |
| 8991 | if (tempExtraBooks.length > 0) { | 8997 | if (tempExtraBooks.length > 0) { |
| @@ -9012,7 +9018,8 @@ async function openCharacterWorldPopup() { | |||
| 9012 | const extrasSelect = template.find('.character_extra_world_info_selector'); | 9018 | const extrasSelect = template.find('.character_extra_world_info_selector'); |
| 9013 | const existingCharLore = world_info.charLore?.find((e) => e.name === fileName); | 9019 | const existingCharLore = world_info.charLore?.find((e) => e.name === fileName); |
| 9014 | world_names.forEach((item, i) => { | 9020 | 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); | ||
| 9016 | extrasSelect.append(new Option(item, String(i), isSelected, isSelected)); | 9023 | extrasSelect.append(new Option(item, String(i), isSelected, isSelected)); |
| 9017 | }); | 9024 | }); |
| 9018 | 9025 | ||
| @@ -9199,6 +9206,15 @@ async function createOrEditCharacter(e) { | |||
| 9199 | field.callback && field.callback(fieldValue); | 9206 | field.callback && field.callback(fieldValue); |
| 9200 | }); | 9207 | }); |
| 9201 | 9208 | ||
| 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 | |||
| 9202 | $('#character_popup-button-h3').text('Create character'); | 9218 | $('#character_popup-button-h3').text('Create character'); |
| 9203 | 9219 | ||
| 9204 | create_save.avatar = null; | 9220 | create_save.avatar = null; |