Add option for inline character card replacements

This commit is contained in:
Cohee 2024-03-03 21:04:27 +02:00
parent 7acd2916ec
commit 24b33a5f77
2 changed files with 25 additions and 0 deletions

View File

@ -4001,6 +4001,9 @@
<option id="character_source" data-i18n="Link to Source">
Link to Source
</option>
<option id="replace_update" data-i18n="Replace / Update">
Replace / Update
</option>
<!--<option id="dupe_button">
Duplicate
</option>
@ -4200,6 +4203,7 @@
<input multiple type="file" id="character_import_file" accept=".json, image/png, .yaml, .yml" name="avatar">
<input id="character_import_file_type" name="file_type" class="text_pole" maxlength="999" size="2" value="" autocomplete="off">
</form>
<input type="file" id="character_replace_file" accept="image/png" name="replace_avatar" hidden>
</div>
<div name="Character List Panel" id="rm_characters_block" class="right_menu">
<div id="charListFixedTop">

View File

@ -9837,7 +9837,28 @@ jQuery(async function () {
toastr.info('This character doesn\'t seem to have a source.');
}
} break;
case 'replace_update': {
const confirm = await callPopup('<p><b>Choose a new character card to replace this character with.</b></p><p>All chats, assets and group memberships will be preserved, but local changes to the character data will be lost.</p><p>Proceed?</p>', 'confirm', '');
if (confirm) {
async function uploadReplacementCard(e) {
const file = e.target.files[0];
if (!file) {
return;
}
try {
const cloneFile = new File([file], characters[this_chid].avatar, { type: file.type });
const chatFile = characters[this_chid]['chat'];
await processDroppedFiles([cloneFile], true);
await openCharacterChat(chatFile);
} catch {
toastr.error('Failed to replace the character card.', 'Something went wrong');
}
}
$('#character_replace_file').off('change').on('change', uploadReplacementCard).trigger('click');
}
} break;
/*case 'delete_button':
popup_type = "del_ch";
callPopup(`