import { Player } from '@runox-game/game-engine/lib/models/player.model' ; import type { IPlayer } from '@runox-game/game-engine/lib/models/player.model' ; import { getContext } from 'svelte' ; import { store } from '../store' ; import { AppStatus } from "../store/types" ; import { docStore } from "sveltefire" ; import { goto as _goto } from "@sveltech/routify" ; import { get } from "svelte/store" ; export const login = async ( ) => { const app = getContext ( 'firebase' ) . getFirebase ( ) ; const provider = new app . auth . GoogleAuthProvider ( ) ; try { const result = await app . auth ( ) . signInWithPopup ( provider ) ; const _user = new Player ( result . user . email , result . user . displayName , result . user . photoURL ) ; store . setUser ( _user ) ; store . setStatus ( AppStatus . AUTHENTICATED ) ; } catch ( err ) { console . log ( err ) ; } } ; export const handleRoomName = ( roomName ) => { store . setRoomName ( roomName ) ; } ; export const handleFixRoom = ( key , roomName ) => { if ( key === 'Enter' || key === 'Escape' ) { createRoom ( roomName ) ; } } ; export const logout = ( ) => { store . reset ( ) ; } ; export const createRoom = ( roomName ) => { const doc = docStore ( `rooms-svelte/${ roomName }` , { } ) ; store . setHasRoomNameFixed ( true ) ; doc . subscribe ( ( _doc ) => { if ( _doc === null ) { doc . ref . set ( { foo : "bar" } ) ; } } ) ; } ; export const startGame = ( ) => { const goto = get ( _goto ) ; goto ( "/game" ) ; console . log ( 'startGame edit me!' ) ; } ;