feat: add global toggle buttons for lorebook always-active state (#754)
# PR Checklist - [x] Have you checked if it works normally in all models? *Ignore this if it doesn't use models.* - [x] Have you checked if it works normally in all web, local, and node hosted versions? If it doesn't, have you blocked it in those versions? - [ ] Have you added type definitions? # Preview   # Description This PR introduces following: - Add buttons to toggle all character/chat lorebooks' always-active state at once - Show SunIcon when all lorebooks are active, LinkIcon otherwise
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { DBState } from 'src/ts/stores.svelte';
|
import { DBState } from 'src/ts/stores.svelte';
|
||||||
import { language } from "../../../lang";
|
import { language } from "../../../lang";
|
||||||
import { DownloadIcon, FolderUpIcon, ImportIcon, PlusIcon } from "lucide-svelte";
|
import { DownloadIcon, FolderUpIcon, ImportIcon, PlusIcon, SunIcon, LinkIcon } from "lucide-svelte";
|
||||||
import { addLorebook, exportLoreBook, importLoreBook } from "../../../ts/process/lorebook.svelte";
|
import { addLorebook, exportLoreBook, importLoreBook } from "../../../ts/process/lorebook.svelte";
|
||||||
import Check from "../../UI/GUI/CheckInput.svelte";
|
import Check from "../../UI/GUI/CheckInput.svelte";
|
||||||
import NumberInput from "../../UI/GUI/NumberInput.svelte";
|
import NumberInput from "../../UI/GUI/NumberInput.svelte";
|
||||||
@@ -16,6 +16,40 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let { globalMode = $bindable(false) }: Props = $props();
|
let { globalMode = $bindable(false) }: Props = $props();
|
||||||
|
|
||||||
|
function isAllCharacterLoreAlwaysActive() {
|
||||||
|
const globalLore = DBState.db.characters[$selectedCharID].globalLore;
|
||||||
|
return globalLore && globalLore.every((book) => book.alwaysActive);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAllChatLoreAlwaysActive() {
|
||||||
|
const localLore = DBState.db.characters[$selectedCharID].chats[DBState.db.characters[$selectedCharID].chatPage].localLore;
|
||||||
|
return localLore && localLore.every((book) => book.alwaysActive);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleCharacterLoreAlwaysActive() {
|
||||||
|
const globalLore = DBState.db.characters[$selectedCharID].globalLore;
|
||||||
|
|
||||||
|
if (!globalLore) return;
|
||||||
|
|
||||||
|
const allActive = globalLore.every((book) => book.alwaysActive);
|
||||||
|
|
||||||
|
globalLore.forEach((book) => {
|
||||||
|
book.alwaysActive = !allActive;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleChatLoreAlwaysActive() {
|
||||||
|
const localLore = DBState.db.characters[$selectedCharID].chats[DBState.db.characters[$selectedCharID].chatPage].localLore;
|
||||||
|
|
||||||
|
if (!localLore) return;
|
||||||
|
|
||||||
|
const allActive = localLore.every((book) => book.alwaysActive);
|
||||||
|
|
||||||
|
localLore.forEach((book) => {
|
||||||
|
book.alwaysActive = !allActive;
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if !globalMode}
|
{#if !globalMode}
|
||||||
@@ -99,5 +133,25 @@
|
|||||||
}} class="hover:text-textcolor ml-2 cursor-pointer">
|
}} class="hover:text-textcolor ml-2 cursor-pointer">
|
||||||
<FolderUpIcon />
|
<FolderUpIcon />
|
||||||
</button>
|
</button>
|
||||||
|
<button onclick={() => {
|
||||||
|
toggleCharacterLoreAlwaysActive()
|
||||||
|
}} class="hover:text-textcolor ml-2 cursor-pointer flex items-center gap-1">
|
||||||
|
{#if isAllCharacterLoreAlwaysActive()}
|
||||||
|
<SunIcon />
|
||||||
|
{:else}
|
||||||
|
<LinkIcon />
|
||||||
|
{/if}
|
||||||
|
<span class="text-xs">CHAR</span>
|
||||||
|
</button>
|
||||||
|
<button onclick={() => {
|
||||||
|
toggleChatLoreAlwaysActive()
|
||||||
|
}} class="hover:text-textcolor ml-2 cursor-pointer flex items-center gap-1">
|
||||||
|
{#if isAllChatLoreAlwaysActive()}
|
||||||
|
<SunIcon />
|
||||||
|
{:else}
|
||||||
|
<LinkIcon />
|
||||||
|
{/if}
|
||||||
|
<span class="text-xs">CHAT</span>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
Reference in New Issue
Block a user