Change first message to chat dependent

This commit is contained in:
kwaroran
2024-09-18 23:25:02 +09:00
parent 6ad841e931
commit 85609e890e
15 changed files with 50 additions and 61 deletions

View File

@@ -1,7 +1,7 @@
<script lang="ts">
import { ParseMarkdown, risuChatParser } from "src/ts/parser";
import { DataBase, type Database, type character, type groupChat } from "src/ts/storage/database";
import { CurrentVariablePointer, moduleBackgroundEmbedding, ReloadGUIPointer, selectedCharID } from "src/ts/stores";
import { moduleBackgroundEmbedding, ReloadGUIPointer, selectedCharID } from "src/ts/stores";
import { onDestroy } from "svelte";
let backgroundHTML = ''
@@ -43,14 +43,12 @@
{#if backgroundHTML || $moduleBackgroundEmbedding}
{#if $selectedCharID > -1}
{#key $CurrentVariablePointer}
{#key $ReloadGUIPointer}
<div class="absolute top-0 left-0 w-full h-full">
{#await ParseMarkdown(risuChatParser((backgroundHTML || '') + ($moduleBackgroundEmbedding || ''), {chara:currentChar}), currentChar, 'back') then md}
{@html md}
{/await}
</div>
{/key}
{#key $ReloadGUIPointer}
<div class="absolute top-0 left-0 w-full h-full">
{#await ParseMarkdown(risuChatParser((backgroundHTML || '') + ($moduleBackgroundEmbedding || ''), {chara:currentChar}), currentChar, 'back') then md}
{@html md}
{/await}
</div>
{/key}
{/if}
{/if}

View File

@@ -5,7 +5,7 @@
import { alertConfirm, alertError, alertRequestData } from "../../ts/alert";
import { language } from "../../lang";
import { DataBase, type MessageGenerationInfo } from "../../ts/storage/database";
import { CurrentCharacter, CurrentChat, CurrentVariablePointer, HideIconStore, ReloadGUIPointer } from "../../ts/stores";
import { CurrentCharacter, CurrentChat, HideIconStore, ReloadGUIPointer } from "../../ts/stores";
import { translateHTML } from "../../ts/translator/translator";
import { risuChatParser } from "src/ts/process/scripts";
import { get, type Unsubscriber } from "svelte/store";
@@ -146,9 +146,6 @@
const unsubscribers:Unsubscriber[] = []
onMount(()=>{
unsubscribers.push(CurrentVariablePointer.subscribe((v) => {
displaya(message)
}))
unsubscribers.push(ReloadGUIPointer.subscribe((v) => {
displaya(message)
}))
@@ -295,13 +292,11 @@
style:line-height="{($DataBase.lineHeight ?? 1.25) * ($DataBase.zoomsize / 100)}rem"
>
{#key $ReloadGUIPointer}
{#key $CurrentVariablePointer}
{#await markParsing(msgDisplay, character, 'normal', idx, translated)}
{@html lastParsed}
{:then md}
{@html md}
{/await}
{/key}
{#await markParsing(msgDisplay, character, 'normal', idx, translated)}
{@html lastParsed}
{:then md}
{@html md}
{/await}
{/key}
</span>
{/if}

View File

@@ -601,32 +601,34 @@
<Chat
character={$CurrentSimpleCharacter}
name={$CurrentCharacter.name}
message={$CurrentCharacter.firstMsgIndex === -1 ? $CurrentCharacter.firstMessage :
$CurrentCharacter.alternateGreetings[$CurrentCharacter.firstMsgIndex]}
message={$CurrentChat.fmIndex === -1 ? $CurrentCharacter.firstMessage :
$CurrentCharacter.alternateGreetings[$CurrentChat.fmIndex]}
img={getCharImage($CurrentCharacter.image, 'css')}
idx={-1}
altGreeting={$CurrentCharacter.alternateGreetings.length > 0}
largePortrait={$CurrentCharacter.largePortrait}
onReroll={() => {
const cha = $CurrentCharacter
const chat = $CurrentChat
if(cha.type !== 'group'){
if (cha.firstMsgIndex >= (cha.alternateGreetings.length - 1)){
cha.firstMsgIndex = -1
if (chat.fmIndex >= (cha.alternateGreetings.length - 1)){
chat.fmIndex = -1
}
else{
cha.firstMsgIndex += 1
chat.fmIndex += 1
}
}
$CurrentCharacter = cha
$CurrentChat = chat
}}
unReroll={() => {
const cha = $CurrentCharacter
const chat = $CurrentChat
if(cha.type !== 'group'){
if (cha.firstMsgIndex === -1){
cha.firstMsgIndex = (cha.alternateGreetings.length - 1)
if (chat.fmIndex === -1){
chat.fmIndex = (cha.alternateGreetings.length - 1)
}
else{
cha.firstMsgIndex -= 1
chat.fmIndex -= 1
}
}
$CurrentCharacter = cha

View File

@@ -51,15 +51,6 @@
let currentChar:character|groupChat = $CurrentCharacter;
let messages:Message[] = []
if(currentChar.type !== 'group'){
const firstMsg:string = currentChar.firstMsgIndex === -1 ? currentChar.firstMessage : currentChar.alternateGreetings[currentChar.firstMsgIndex]
messages.push({
role: 'char',
data: await processScript(currentChar,
replacePlaceholders(firstMsg, currentChar.name),
'editprocess')
})
}
messages = [...messages, ...currentChar.chats[currentChar.chatPage].message];
let lastMessages:Message[] = messages.slice(Math.max(messages.length - 10, 0));
if(lastMessages.length === 0)

View File

@@ -2,7 +2,7 @@
import { alertConfirm, alertError } from "../../ts/alert";
import { language } from "../../lang";
import { DataBase } from "../../ts/storage/database";
import { CurrentCharacter, selectedCharID } from "../../ts/stores";
import { CurrentCharacter, ReloadGUIPointer, selectedCharID } from "../../ts/stores";
import { DownloadIcon, EditIcon, FolderUpIcon, PlusIcon, TrashIcon, XIcon } from "lucide-svelte";
import { exportChat, importChat } from "../../ts/characters";
import { findCharacterbyId } from "../../ts/util";
@@ -66,7 +66,7 @@
const len = $CurrentCharacter.chats.length
let chats = $CurrentCharacter.chats
chats.unshift({
message:[], note:'', name:`New Chat ${len + 1}`, localLore:[]
message:[], note:'', name:`New Chat ${len + 1}`, localLore:[], fmIndex: -1
})
if(cha.type === 'group'){
cha.characters.map((c) => {
@@ -78,6 +78,7 @@
})
}
$CurrentCharacter.chats = chats
$ReloadGUIPointer += 1
$CurrentCharacter.chatPage = len
close()
}}>

View File

@@ -2,7 +2,7 @@
import { language } from "../../lang";
import { tokenizeAccurate } from "../../ts/tokenizer";
import { DataBase, saveImage as saveAsset, type Database, type character, type groupChat } from "../../ts/storage/database";
import { CharConfigSubMenu, MobileGUI, ShowRealmFrameStore, selectedCharID } from "../../ts/stores";
import { CharConfigSubMenu, CurrentChat, MobileGUI, ShowRealmFrameStore, selectedCharID } from "../../ts/stores";
import { PlusIcon, SmileIcon, TrashIcon, UserIcon, ActivityIcon, BookIcon, User, CurlyBraces, Volume2Icon, DownloadIcon, FolderUpIcon } from 'lucide-svelte'
import Check from "../UI/GUI/CheckInput.svelte";
import { addCharEmotion, addingEmotion, getCharImage, rmCharEmotion, selectCharImg, makeGroupImage, removeChar, changeCharImage } from "../../ts/characters";
@@ -966,7 +966,7 @@
<th class="font-medium cursor-pointer w-10">
<button class="hover:text-green-500" on:click={() => {
if(currentChar.type === 'character'){
currentChar.data.firstMsgIndex = -1
$CurrentChat.fmIndex = -1
let alternateGreetings = currentChar.data.alternateGreetings
alternateGreetings.splice(i, 1)
currentChar.data.alternateGreetings = alternateGreetings
@@ -1031,7 +1031,7 @@
<th class="font-medium cursor-pointer w-10">
<button class="hover:text-green-500" on:click={() => {
if(currentChar.type === 'character'){
currentChar.data.firstMsgIndex = -1
$CurrentChat.fmIndex = -1
let additionalAssets = currentChar.data.additionalAssets
additionalAssets.splice(i, 1)
currentChar.data.additionalAssets = additionalAssets

View File

@@ -10,7 +10,7 @@
import { findCharacterbyId, parseKeyValue, sleep, sortableOptions } from "src/ts/util";
import CheckInput from "../UI/GUI/CheckInput.svelte";
import { createMultiuserRoom } from "src/ts/sync/multiuser";
import { CurrentCharacter, MobileGUI } from "src/ts/stores";
import { CurrentCharacter, MobileGUI, ReloadGUIPointer } from "src/ts/stores";
import Sortable from 'sortablejs/modular/sortable.core.esm.js';
import { onDestroy, onMount } from "svelte";
import { v4 } from "uuid";
@@ -69,7 +69,7 @@
const len = chara.chats.length
let chats = chara.chats
chats.unshift({
message:[], note:'', name:`New Chat ${len + 1}`, localLore:[]
message:[], note:'', name:`New Chat ${len + 1}`, localLore:[], fmIndex: -1
})
if(cha.type === 'group'){
cha.characters.map((c) => {
@@ -82,6 +82,7 @@
}
chara.chats = chats
chara.chatPage = 0
$ReloadGUIPointer += 1
}}>New Chat</Button>
<div class="flex flex-col w-full mt-2 overflow-y-auto flex-grow" bind:this={ele}>
{#key sorted}
@@ -89,6 +90,8 @@
<button data-risu-idx={i} on:click={() => {
if(!editMode){
chara.chatPage = i
$ReloadGUIPointer += 1
}
}} class="flex items-center text-textcolor border-solid border-0 border-darkborderc p-2 cursor-pointer rounded-md"class:bg-selected={i === chara.chatPage}>
{#if editMode}
@@ -158,6 +161,7 @@
const d = await alertConfirm(`${language.removeConfirm}${chat.name}`)
if(d){
chara.chatPage = 0
$ReloadGUIPointer += 1
let chats = chara.chats
chats.splice(i, 1)
chara.chats = chats