Refactor character creation

This commit is contained in:
kwaroran
2024-09-11 09:50:54 +09:00
parent f66ae59d70
commit b37e70a6a5
6 changed files with 77 additions and 116 deletions

View File

@@ -30,7 +30,7 @@
</button> </button>
</div> </div>
{/if} {/if}
<div class="w-full flex-1 overflow-y-auto bg-bgcolor"> <div class="w-full flex-1 overflow-y-auto bg-bgcolor relative">
{#if $MobileSideBar > 0} {#if $MobileSideBar > 0}
<div class="w-full flex flex-col p-2 mt-2 h-full"> <div class="w-full flex flex-col p-2 mt-2 h-full">
{#if $MobileSideBar === 1} {#if $MobileSideBar === 1}

View File

@@ -1,20 +1,9 @@
<script lang="ts"> <script lang="ts">
import { type character, DataBase, type groupChat } from "src/ts/storage/database"; import { type character, DataBase, type groupChat } from "src/ts/storage/database";
import BarIcon from "../SideBars/BarIcon.svelte"; import BarIcon from "../SideBars/BarIcon.svelte";
import { characterFormatUpdate, getCharImage } from "src/ts/characters"; import { addCharacter, changeChar, getCharImage } from "src/ts/characters";
import { MobileSearch, selectedCharID } from "src/ts/stores"; import { MobileSearch } from "src/ts/stores";
import { doingChat } from "src/ts/process"; import { MessageSquareIcon, PlusIcon } from "lucide-svelte";
import { language } from "src/lang";
import { MessageSquareIcon } from "lucide-svelte";
function changeChar(index: number) {
if($doingChat){
return
}
characterFormatUpdate(index, {
updateInteraction: true,
});
selectedCharID.set(index);
}
const agoFormatter = new Intl.RelativeTimeFormat(navigator.languages, { style: 'short' }); const agoFormatter = new Intl.RelativeTimeFormat(navigator.languages, { style: 'short' });
@@ -65,7 +54,7 @@
}); });
} }
</script> </script>
<div class="flex flex-col items-center w-full"> <div class="flex flex-col items-center w-full overflow-y-auto h-full">
{#each sortChar($DataBase.characters) as char, i} {#each sortChar($DataBase.characters) as char, i}
{#if char.name.toLocaleLowerCase().includes($MobileSearch.toLocaleLowerCase())} {#if char.name.toLocaleLowerCase().includes($MobileSearch.toLocaleLowerCase())}
<button class="flex p-2 border-t-darkborderc gap-2 w-full" class:border-t={i !== 0} on:click={() => { <button class="flex p-2 border-t-darkborderc gap-2 w-full" class:border-t={i !== 0} on:click={() => {
@@ -85,3 +74,9 @@
{/if} {/if}
{/each} {/each}
</div> </div>
<button class="p-4 rounded-full absolute bottom-2 right-2 bg-borderc" on:click={() => {
addCharacter()
}}>
<PlusIcon size={24} />
</button>

View File

@@ -305,7 +305,7 @@
{:else if $alertStore.type === 'addchar'} {:else if $alertStore.type === 'addchar'}
<div class="w-2xl flex flex-col max-w-full"> <div class="w-2xl flex flex-col max-w-full">
<button class="border-darkborderc border py-12 px-8 flex rounded-md hover:ring-2 justify-center items-center" on:click={() => { <button class="border-darkborderc border py-12 px-8 flex rounded-md hover:ring-2 justify-center items-center" on:click|stopPropagation|preventDefault={(e) => {
alertStore.set({ alertStore.set({
type: 'none', type: 'none',
msg: 'importFromRealm' msg: 'importFromRealm'
@@ -319,7 +319,7 @@
<ChevronRightIcon /> <ChevronRightIcon />
</div> </div>
</button> </button>
<button class="border-darkborderc border py-2 px-8 flex rounded-md hover:ring-2 items-center mt-2" on:click={() => { <button class="border-darkborderc border py-2 px-8 flex rounded-md hover:ring-2 items-center mt-2" on:click|stopPropagation|preventDefault={() => {
alertStore.set({ alertStore.set({
type: 'none', type: 'none',
msg: 'importCharacter' msg: 'importCharacter'
@@ -332,7 +332,7 @@
<ChevronRightIcon /> <ChevronRightIcon />
</div> </div>
</button> </button>
<button class="border-darkborderc border py-2 px-8 flex rounded-md hover:ring-2 items-center mt-2" on:click={() => { <button class="border-darkborderc border py-2 px-8 flex rounded-md hover:ring-2 items-center mt-2" on:click|stopPropagation|preventDefault={() => {
alertStore.set({ alertStore.set({
type: 'none', type: 'none',
msg: 'createfromScratch' msg: 'createfromScratch'
@@ -345,7 +345,7 @@
<ChevronRightIcon /> <ChevronRightIcon />
</div> </div>
</button> </button>
<button class="border-darkborderc border py-2 px-8 flex rounded-md hover:ring-2 items-center mt-2" on:click={() => { <button class="border-darkborderc border py-2 px-8 flex rounded-md hover:ring-2 items-center mt-2" on:click|stopPropagation|preventDefault={() => {
alertStore.set({ alertStore.set({
type: 'none', type: 'none',
msg: 'createGroup' msg: 'createGroup'
@@ -358,7 +358,7 @@
<ChevronRightIcon /> <ChevronRightIcon />
</div> </div>
</button> </button>
<button class="border-darkborderc border py-2 px-8 flex rounded-md hover:ring-2 items-center mt-2" on:click={() => { <button class="border-darkborderc border py-2 px-8 flex rounded-md hover:ring-2 items-center mt-2" on:click|stopPropagation|preventDefault={() => {
alertStore.set({ alertStore.set({
type: 'none', type: 'none',
msg: 'cancel' msg: 'cancel'

View File

@@ -29,9 +29,8 @@
WrenchIcon, WrenchIcon,
} from "lucide-svelte"; } from "lucide-svelte";
import { import {
characterFormatUpdate, addCharacter,
createNewCharacter, changeChar,
createNewGroup,
getCharImage, getCharImage,
} from "../../ts/characters"; } from "../../ts/characters";
import { importCharacter } from "src/ts/characterCards"; import { importCharacter } from "src/ts/characterCards";
@@ -60,42 +59,6 @@
let devTool = false let devTool = false
export let openGrid = () => {}; export let openGrid = () => {};
function createScratch() {
reseter();
createNewCharacter();
let db = get(DataBase)
if(db.characters[db.characters.length-1]){
changeChar(db.characters.length-1)
}
}
function createGroup() {
reseter();
createNewGroup();
let db = get(DataBase)
if(db.characters[db.characters.length-1]){
changeChar(db.characters.length-1)
}
}
async function createImport() {
reseter();
await importCharacter();
let db = get(DataBase)
if(db.characters[db.characters.length-1]){
changeChar(db.characters.length-1)
}
}
function changeChar(index: number) {
if($doingChat){
return
}
reseter();
characterFormatUpdate(index, {
updateInteraction: true,
});
selectedCharID.set(index);
}
function reseter() { function reseter() {
menuMode = 0; menuMode = 0;
sideBarMode = 0; sideBarMode = 0;
@@ -426,13 +389,13 @@
<div <div
on:click={() => { on:click={() => {
if(char.type === "normal"){ if(char.type === "normal"){
changeChar(char.index); changeChar(char.index, {reseter});
} }
}} }}
on:keydown={(e) => { on:keydown={(e) => {
if (e.key === "Enter") { if (e.key === "Enter") {
if(char.type === "normal"){ if(char.type === "normal"){
changeChar(char.index); changeChar(char.index, {reseter});
} }
} }
}} }}
@@ -537,13 +500,13 @@
<div <div
on:click={() => { on:click={() => {
if(char2.type === "normal"){ if(char2.type === "normal"){
changeChar(char2.index); changeChar(char2.index, {reseter});
} }
}} }}
on:keydown={(e) => { on:keydown={(e) => {
if (e.key === "Enter") { if (e.key === "Enter") {
if(char2.type === "normal"){ if(char2.type === "normal"){
changeChar(char2.index); changeChar(char2.index, {reseter});
} }
} }
}} }}
@@ -587,22 +550,7 @@
<div class="flex flex-col items-center space-y-2 px-2"> <div class="flex flex-col items-center space-y-2 px-2">
<BaseRoundedButton <BaseRoundedButton
onClick={async () => { onClick={async () => {
const r = await alertAddCharacter() addCharacter({reseter})
switch(r){
case 'createfromScratch':
createScratch()
break
case 'importCharacter':
createImport()
break
case 'createGroup':
createGroup()
break
case 'importFromRealm':
selectedCharID.set(-1)
OpenRealmStore.set(true)
break
}
}} }}
><svg viewBox="0 0 24 24" width="1.2em" height="1.2em" ><svg viewBox="0 0 24 24" width="1.2em" height="1.2em"
><path ><path
@@ -703,38 +651,6 @@
<SideChatList bind:chara={ $CurrentCharacter} /> <SideChatList bind:chara={ $CurrentCharacter} />
{/if} {/if}
{/if} {/if}
{:else if sideBarMode === 1}
<Button
on:click={createScratch}
className="mt-2"
>
{language.createfromScratch}
</Button>
<Button
on:click={createImport}
className="mt-2"
>
{language.importCharacter}
</Button>
<Button
on:click={createGroup}
className="mt-2"
>
{language.createGroup}
</Button>
<Button
on:click={BotCreator.createBotFromWeb}
className="mt-2"
>
{language.createBotwithAI}
</Button>
{:else if sideBarMode === 2}
<Button
on:click={joinMultiuserRoom}
className="mt-2"
>
{language.joinMultiUserRoom}
</Button>
{/if} {/if}
</div> </div>

View File

@@ -1,17 +1,19 @@
import { get, writable } from "svelte/store"; import { get, writable } from "svelte/store";
import { DataBase, saveImage, setDatabase, type character, type Chat, defaultSdDataFunc, type loreBook } from "./storage/database"; import { DataBase, saveImage, setDatabase, type character, type Chat, defaultSdDataFunc, type loreBook } from "./storage/database";
import { alertConfirm, alertError, alertNormal, alertSelect, alertStore, alertWait } from "./alert"; import { alertAddCharacter, alertConfirm, alertError, alertNormal, alertSelect, alertStore, alertWait } from "./alert";
import { language } from "../lang"; import { language } from "../lang";
import { decode as decodeMsgpack } from "msgpackr"; import { decode as decodeMsgpack } from "msgpackr";
import { checkNullish, findCharacterbyId, getUserName, selectMultipleFile, selectSingleFile, sleep } from "./util"; import { checkNullish, findCharacterbyId, getUserName, selectMultipleFile, selectSingleFile, sleep } from "./util";
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { selectedCharID } from "./stores"; import { MobileGUIStack, OpenRealmStore, selectedCharID } from "./stores";
import { checkCharOrder, downloadFile, getFileSrc } from "./storage/globalApi"; import { checkCharOrder, downloadFile, getFileSrc } from "./storage/globalApi";
import { reencodeImage } from "./process/files/image"; import { reencodeImage } from "./process/files/image";
import { updateInlayScreen } from "./process/inlayScreen"; import { updateInlayScreen } from "./process/inlayScreen";
import { PngChunk } from "./pngChunk"; import { PngChunk } from "./pngChunk";
import { parseMarkdownSafe } from "./parser"; import { parseMarkdownSafe } from "./parser";
import { translateHTML } from "./translator/translator"; import { translateHTML } from "./translator/translator";
import { doingChat } from "./process";
import { importCharacter } from "./characterCards";
export function createNewCharacter() { export function createNewCharacter() {
let db = get(DataBase) let db = get(DataBase)
@@ -735,3 +737,51 @@ export async function removeChar(index:number,name:string, type:'normal'|'perman
setDatabase(db) setDatabase(db)
selectedCharID.set(-1) selectedCharID.set(-1)
} }
export async function addCharacter(arg:{
reseter?:()=>any,
} = {}){
MobileGUIStack.set(100)
const reseter = arg.reseter ?? (() => {})
const r = await alertAddCharacter()
if(r === 'importFromRealm'){
selectedCharID.set(-1)
OpenRealmStore.set(true)
MobileGUIStack.set(0)
return
}
reseter();
switch(r){
case 'createfromScratch':
createNewCharacter()
break
case 'createGroup':
createNewGroup()
break
case 'importCharacter':
await importCharacter()
break
default:
MobileGUIStack.set(1)
return
}
let db = get(DataBase)
if(db.characters[db.characters.length-1]){
changeChar(db.characters.length-1)
}
MobileGUIStack.set(1)
}
export function changeChar(index: number, arg:{
reseter?:()=>any,
} = {}) {
const reseter = arg.reseter ?? (() => {})
if(get(doingChat)){
return
}
reseter();
characterFormatUpdate(index, {
updateInteraction: true,
});
selectedCharID.set(index);
}

View File

@@ -543,7 +543,7 @@ export async function loadData() {
if(db.botSettingAtStart){ if(db.botSettingAtStart){
botMakerMode.set(true) botMakerMode.set(true)
} }
if((db.betaMobileGUI && window.innerWidth <= 800) || import.meta.env.VITE_RISU_LITE){ if((db.betaMobileGUI && window.innerWidth <= 800) || import.meta.env.VITE_RISU_LITE === 'TRUE'){
initMobileGesture() initMobileGesture()
MobileGUI.set(true) MobileGUI.set(true)
} }