feat: add 'save as global NPC' toggle for story characters

This commit is contained in:
Alexej Wolff
2026-05-07 00:44:17 +02:00
parent ce55101bc5
commit 249d21364e
3 changed files with 41 additions and 2 deletions
+19 -2
View File
@@ -274,7 +274,7 @@ export default function CreateStoryPage() {
const handleCharacterChange = (
index: number,
field: keyof Character,
value: string,
value: string | boolean,
) => {
const newCharacters = [...form.characters];
newCharacters[index] = { ...newCharacters[index], [field]: value };
@@ -454,7 +454,10 @@ export default function CreateStoryPage() {
const saveCharactersAsGlobalNPCs = async () => {
const existingNames = savedNPCs.map((npc) => npc.name.toLowerCase());
for (const char of storyCharacters) {
// Only save characters that have saveAsGlobal flag enabled
const charsToSave = storyCharacters.filter((c) => c.saveAsGlobal);
for (const char of charsToSave) {
// Skip if NPC with this name already exists
if (existingNames.includes(char.name.toLowerCase())) {
continue;
@@ -1046,6 +1049,20 @@ export default function CreateStoryPage() {
placeholder="Описание персонажа..."
rows={2}
/>
<label className="save-global-toggle">
<input
type="checkbox"
checked={char.saveAsGlobal || false}
onChange={(e) =>
handleCharacterChange(
index,
"saveAsGlobal",
e.target.checked,
)
}
/>
<span>Сделать общим (добавить в библиотеку NPC)</span>
</label>
</div>
</div>
</div>