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
+21
View File
@@ -714,6 +714,27 @@
border-color: #667eea; border-color: #667eea;
} }
.save-global-toggle {
display: flex;
align-items: center;
gap: 0.5rem;
margin-top: 0.5rem;
font-size: 0.85rem;
color: #888;
cursor: pointer;
}
.save-global-toggle input[type="checkbox"] {
width: 16px;
height: 16px;
accent-color: #667eea;
cursor: pointer;
}
.save-global-toggle:hover {
color: #aaa;
}
/* Подсказки */ /* Подсказки */
.hint { .hint {
display: block; display: block;
+19 -2
View File
@@ -274,7 +274,7 @@ export default function CreateStoryPage() {
const handleCharacterChange = ( const handleCharacterChange = (
index: number, index: number,
field: keyof Character, field: keyof Character,
value: string, value: string | boolean,
) => { ) => {
const newCharacters = [...form.characters]; const newCharacters = [...form.characters];
newCharacters[index] = { ...newCharacters[index], [field]: value }; newCharacters[index] = { ...newCharacters[index], [field]: value };
@@ -454,7 +454,10 @@ export default function CreateStoryPage() {
const saveCharactersAsGlobalNPCs = async () => { const saveCharactersAsGlobalNPCs = async () => {
const existingNames = savedNPCs.map((npc) => npc.name.toLowerCase()); 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 // Skip if NPC with this name already exists
if (existingNames.includes(char.name.toLowerCase())) { if (existingNames.includes(char.name.toLowerCase())) {
continue; continue;
@@ -1046,6 +1049,20 @@ export default function CreateStoryPage() {
placeholder="Описание персонажа..." placeholder="Описание персонажа..."
rows={2} 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> </div>
</div> </div>
+1
View File
@@ -10,6 +10,7 @@ export interface Character {
age?: CharacterAge; // возраст персонажа age?: CharacterAge; // возраст персонажа
gender?: CharacterGender; // пол персонажа gender?: CharacterGender; // пол персонажа
avatarUrl?: string; // URL аватара персонажа avatarUrl?: string; // URL аватара персонажа
saveAsGlobal?: boolean; // сохранить как глобального NPC
} }
// NPC персонаж (сохранённый в БД) // NPC персонаж (сохранённый в БД)