Add enable/disable management for book tools (characters, worlds, and locations)

- Introduced toggling functionality for managing `characters`, `worlds`, and `locations` tool availability per book.
- Updated `CharacterComponent`, `WorldSetting`, and `LocationComponent` with toggle switches for tool enablement.
- Added `book_tools` database table and related schema migration for storing tool settings.
- Extended API calls, models, and IPC handlers to support tool enablement states.
- Localized new strings for English with supporting descriptions and messages.
- Adjusted conditional rendering logic across components to respect tool enablement.
This commit is contained in:
natreex
2026-01-14 17:42:59 -05:00
parent 7215ac5c4f
commit e45a15225b
19 changed files with 782 additions and 341 deletions

View File

@@ -1,6 +1,7 @@
import { getUserEncryptionKey } from "../keyManager.js";
import System from "../System.js";
import WorldRepository, { WorldElementValue, WorldQuery } from "../repositories/world.repository.js";
import BookRepo, {BookToolsTable} from "../repositories/book.repository.js";
export interface SyncedWorld {
id: string;
@@ -44,6 +45,11 @@ export interface WorldProps {
importantCharacters: WorldElement[];
}
export interface WorldListResponse {
worlds: WorldProps[];
enabled: boolean;
}
/**
* Mapping of element type keys to their corresponding numeric type identifiers.
*/
@@ -107,9 +113,12 @@ export default class World {
* @param userId - The unique identifier of the user
* @param bookId - The unique identifier of the book
* @param lang - The language for error messages ('fr' or 'en'), defaults to 'fr'
* @returns An array of WorldProps objects containing all world data and their elements
* @returns WorldListResponse containing an array of WorldProps and enabled flag
*/
public static getWorlds(userId: string, bookId: string, lang: 'fr' | 'en' = 'fr'): WorldProps[] {
public static getWorlds(userId: string, bookId: string, lang: 'fr' | 'en' = 'fr'): WorldListResponse {
const bookTools: BookToolsTable | null = BookRepo.fetchBookTools(userId, bookId, lang);
const enabled: boolean = bookTools ? bookTools.worlds_enabled === 1 : false;
const worldQueryResults: WorldQuery[] = WorldRepository.fetchWorlds(userId, bookId, lang);
const userEncryptionKey: string = getUserEncryptionKey(userId);
const worlds: WorldProps[] = [];
@@ -167,7 +176,7 @@ export default class World {
}
}
}
return worlds;
return { worlds, enabled };
}
/**
@@ -265,4 +274,5 @@ export default class World {
public static removeElementFromWorld(userId: string, elementId: string, lang: 'fr' | 'en' = 'fr'): boolean {
return WorldRepository.deleteElement(userId, elementId, lang);
}
}