mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Prompt when tags are being imported
This commit is contained in:
@ -6319,7 +6319,7 @@ function importCharacter(file) {
|
|||||||
let currentContext = getContext();
|
let currentContext = getContext();
|
||||||
let avatarFileName = `${data.file_name}.png`;
|
let avatarFileName = `${data.file_name}.png`;
|
||||||
let importedCharacter = currentContext.characters.find(character => character.avatar === avatarFileName);
|
let importedCharacter = currentContext.characters.find(character => character.avatar === avatarFileName);
|
||||||
importTags(importedCharacter);
|
await importTags(importedCharacter);
|
||||||
}
|
}
|
||||||
$("#rm_info_block").transition({ opacity: 1, duration: 1000 });
|
$("#rm_info_block").transition({ opacity: 1, duration: 1000 });
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
callPopup,
|
callPopup,
|
||||||
menu_type,
|
menu_type,
|
||||||
updateVisibleDivs,
|
updateVisibleDivs,
|
||||||
|
getCharacters,
|
||||||
} from "../script.js";
|
} from "../script.js";
|
||||||
|
|
||||||
import { selected_group } from "./group-chats.js";
|
import { selected_group } from "./group-chats.js";
|
||||||
@ -202,24 +203,42 @@ function selectTag(event, ui, listSelector) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function importTags(imported_char) {
|
function getExistingTags(new_tags) {
|
||||||
//Ignore the tags ROOT and TAVERN
|
let existing_tags = [];
|
||||||
|
for (let tag of new_tags) {
|
||||||
|
if (tags.find(t => t.name === tag)) {
|
||||||
|
existing_tags.push(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return existing_tags
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function importTags(imported_char) {
|
||||||
let imported_tags = imported_char.tags.filter(t => t !== "ROOT" && t !== "TAVERN");
|
let imported_tags = imported_char.tags.filter(t => t !== "ROOT" && t !== "TAVERN");
|
||||||
for (let tagName of imported_tags) {
|
let existingTags = await getExistingTags(imported_tags);
|
||||||
|
let newTags = imported_tags.filter(t => !existingTags.includes(t));
|
||||||
|
let selected_tags = "";
|
||||||
|
if(newTags.length === 0) {
|
||||||
|
await callPopup(`<h3>Importing Tags</h3><p>${existingTags.length} exisiting tags have been found.</p>`, 'text');
|
||||||
|
} else {
|
||||||
|
selected_tags = await callPopup(`<h3>Importing Tags</h3><p>${existingTags.length} exisiting tags have been found.</p><p>The following ${newTags.length} new tags will be imported.</p>`, 'input', newTags.join(', '));
|
||||||
|
}
|
||||||
|
selected_tags = existingTags.concat(selected_tags.split(', '));
|
||||||
|
selected_tags = selected_tags.filter(t => t !== "");
|
||||||
|
for (let tagName of selected_tags) {
|
||||||
let tag = tags.find(t => t.name === tagName);
|
let tag = tags.find(t => t.name === tagName);
|
||||||
|
|
||||||
// create new tag if it doesn't exist
|
|
||||||
if (!tag) {
|
if (!tag) {
|
||||||
tag = createNewTag(tagName);
|
tag = createNewTag(tagName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add tag to the UI and internal map
|
|
||||||
//appendTagToList(listSelector, tag, { removable: true });
|
|
||||||
addTagToMap(tag.id);
|
addTagToMap(tag.id);
|
||||||
tag_map[imported_char.avatar].push(tag.id);
|
tag_map[imported_char.avatar].push(tag.id);
|
||||||
};
|
};
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
printTags();
|
printTags();
|
||||||
|
getCharacters();
|
||||||
|
|
||||||
// need to return false to keep the input clear
|
// need to return false to keep the input clear
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user