diff --git a/client/svelte-client/src/App.svelte b/client/svelte-client/src/App.svelte index a1e93c3..1884ada 100644 --- a/client/svelte-client/src/App.svelte +++ b/client/svelte-client/src/App.svelte @@ -28,19 +28,19 @@ } function createSession() { $network.loading = true; - sessionStore.createSession().then(() => { + sessionStore.createNetworkSession().then(() => { $network.loading = false; }) } function joinSession(sessionId) { $network.loading = true; - sessionStore.joinSession(sessionId).then(() => { + sessionStore.joinNetworkSession(sessionId).then(() => { $network.loading = false; }) } function watchSession(sessionId) { $network.loading = true; - sessionStore.watchSession(sessionId).then(() => { + sessionStore.watchNetworkSession(sessionId).then(() => { $network.loading = false; }) } diff --git a/client/svelte-client/src/game/session.ts b/client/svelte-client/src/game/session.ts index d93aad0..8fb8cac 100644 --- a/client/svelte-client/src/game/session.ts +++ b/client/svelte-client/src/game/session.ts @@ -5,7 +5,7 @@ export enum SessionState { } export enum SessionType { - HOST = 'HOST', PEER = 'PEER', OBSERVER = 'OBSERVER' + LOCAL = 'LOCAL', HOST = 'HOST', PEER = 'PEER', OBSERVER = 'OBSERVER' } export type Player = { @@ -16,13 +16,19 @@ export type Observer = { id: string } -export type Session = { +export type LocalSession = { + state: SessionState +} + +export type NetworkSession = { session_id: string, state: SessionState, players: Player[], observers: Observer[] } +export type Session = LocalSession | NetworkSession; + export type SessionStore = { session?: Session, sessionType?: SessionType @@ -42,9 +48,10 @@ function makeSessionStore() { return { subscribe, - createSession: () => createSession().then(session => update(() => ({session, sessionType: SessionType.HOST}))), - joinSession: (sessionId) => joinSession(sessionId).then(session => update(() => ({session, sessionType: SessionType.PEER}))), - watchSession: (sessionId) => watchSession(sessionId).then(session => update(() => ({session, sessionType: SessionType.OBSERVER}))), + createLocalSession: () => update(() => ({session: {state: SessionState.RUNNING}})), + createNetworkSession: () => createSession().then(session => update(() => ({session, sessionType: SessionType.HOST}))), + joinNetworkSession: (sessionId) => joinSession(sessionId).then(session => update(() => ({session, sessionType: SessionType.PEER}))), + watchNetworkSession: (sessionId) => watchSession(sessionId).then(session => update(() => ({session, sessionType: SessionType.OBSERVER}))), reset: () => set(initialValue()) } }