feat: auto-save story characters as global NPCs on save
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
getStory,
|
getStory,
|
||||||
updateStory,
|
updateStory,
|
||||||
getNPCCharacters,
|
getNPCCharacters,
|
||||||
|
createNPCCharacter,
|
||||||
} from "../services/api";
|
} from "../services/api";
|
||||||
import { generateAvatarUrl } from "../services/imageGen";
|
import { generateAvatarUrl } from "../services/imageGen";
|
||||||
import { useStoryGeneration } from "../hooks/useStoryGeneration";
|
import { useStoryGeneration } from "../hooks/useStoryGeneration";
|
||||||
@@ -424,6 +425,8 @@ export default function CreateStoryPage() {
|
|||||||
allSettings.push(form.customSetting.trim());
|
allSettings.push(form.customSetting.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const storyCharacters = form.characters.filter((c) => c.name.trim());
|
||||||
|
|
||||||
const storyData = {
|
const storyData = {
|
||||||
title: form.title,
|
title: form.title,
|
||||||
description: form.description || `Исекай история: ${form.title}`,
|
description: form.description || `Исекай история: ${form.title}`,
|
||||||
@@ -436,7 +439,7 @@ export default function CreateStoryPage() {
|
|||||||
summary: form.summary,
|
summary: form.summary,
|
||||||
plot: form.plot,
|
plot: form.plot,
|
||||||
firstMessage: form.firstMessage,
|
firstMessage: form.firstMessage,
|
||||||
characters: form.characters.filter((c) => c.name.trim()),
|
characters: storyCharacters,
|
||||||
isNsfw: form.isNsfw,
|
isNsfw: form.isNsfw,
|
||||||
temperature: form.temperature,
|
temperature: form.temperature,
|
||||||
narrativeRules: form.narrativeRules.trim() || undefined,
|
narrativeRules: form.narrativeRules.trim() || undefined,
|
||||||
@@ -447,14 +450,39 @@ export default function CreateStoryPage() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Helper function to save characters as global NPCs
|
||||||
|
const saveCharactersAsGlobalNPCs = async () => {
|
||||||
|
const existingNames = savedNPCs.map((npc) => npc.name.toLowerCase());
|
||||||
|
|
||||||
|
for (const char of storyCharacters) {
|
||||||
|
// Skip if NPC with this name already exists
|
||||||
|
if (existingNames.includes(char.name.toLowerCase())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create global NPC from story character
|
||||||
|
await createNPCCharacter({
|
||||||
|
name: char.name,
|
||||||
|
description: char.description,
|
||||||
|
role: char.role,
|
||||||
|
age: char.age || "adult",
|
||||||
|
gender: char.gender || "female",
|
||||||
|
isNsfw: form.isNsfw,
|
||||||
|
avatarUrl: char.avatarUrl,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (isEditMode && id) {
|
if (isEditMode && id) {
|
||||||
const success = await updateStory(id, storyData);
|
const success = await updateStory(id, storyData);
|
||||||
if (success) {
|
if (success) {
|
||||||
|
await saveCharactersAsGlobalNPCs();
|
||||||
navigate(`/story/${id}`);
|
navigate(`/story/${id}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const story = await createStory(storyData);
|
const story = await createStory(storyData);
|
||||||
if (story) {
|
if (story) {
|
||||||
|
await saveCharactersAsGlobalNPCs();
|
||||||
navigate(`/story/${story.id}`);
|
navigate(`/story/${story.id}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user