Migrate all DataBase to DBState
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { v4 } from 'uuid';
|
||||
import { alertError, alertInput, alertNormal, alertStore, alertWait } from '../alert';
|
||||
import { get, writable } from 'svelte/store';
|
||||
import { DataBase, setDatabase, type character, saveImage, type Chat, getCurrentChat, setCurrentChat } from '../storage/database.svelte';
|
||||
import { setDatabase, type character, saveImage, type Chat, getCurrentChat, setCurrentChat, getDatabase } from '../storage/database.svelte';
|
||||
import { selectedCharID } from '../stores';
|
||||
import { findCharacterIndexbyId, sleep } from '../util';
|
||||
import type { DataConnection, Peer } from 'peerjs';
|
||||
@@ -79,7 +79,9 @@ export async function createMultiuserRoom(){
|
||||
console.log("new connection", conn)
|
||||
|
||||
async function requestChar(excludeAssets:string[]|null = null){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase({
|
||||
snapshot: true
|
||||
})
|
||||
const selectedCharId = get(selectedCharID)
|
||||
const char = structuredClone(db.characters[selectedCharId])
|
||||
if(char.type === 'group'){
|
||||
@@ -127,7 +129,9 @@ export async function createMultiuserRoom(){
|
||||
requestChar()
|
||||
}
|
||||
if(data.type === 'receive-char'){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase({
|
||||
snapshot: true
|
||||
})
|
||||
const selectedCharId = get(selectedCharID)
|
||||
const char = structuredClone(db.characters[selectedCharId])
|
||||
const recivedChar = data.data
|
||||
@@ -137,7 +141,7 @@ export async function createMultiuserRoom(){
|
||||
char.chats[char.chatPage] = recivedChar.chats[0]
|
||||
}
|
||||
if(data.type === 'request-chat-sync'){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedCharId = get(selectedCharID)
|
||||
const char = db.characters[selectedCharId]
|
||||
char.chats[char.chatPage] = data.data
|
||||
@@ -157,7 +161,7 @@ export async function createMultiuserRoom(){
|
||||
}
|
||||
}
|
||||
if(data.type === 'request-chat'){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedCharId = get(selectedCharID)
|
||||
const char = db.characters[selectedCharId]
|
||||
const chat = char.chats[char.chatPage]
|
||||
@@ -285,7 +289,7 @@ export async function joinMultiuserRoom(){
|
||||
switch(data.type){
|
||||
case 'receive-char':{
|
||||
//create temp character
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const cha = data.data
|
||||
cha.chaId = '§temp'
|
||||
cha.chatPage = 0
|
||||
@@ -309,7 +313,9 @@ export async function joinMultiuserRoom(){
|
||||
break
|
||||
}
|
||||
case 'receive-chat':{
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase({
|
||||
snapshot: true
|
||||
})
|
||||
const selectedCharId = get(selectedCharID)
|
||||
const char = structuredClone(db.characters[selectedCharId])
|
||||
char.chats[char.chatPage] = data.data
|
||||
|
||||
Reference in New Issue
Block a user