mirror of
https://github.com/thilo-behnke/wasm-pong.git
synced 2026-07-11 10:39:18 +00:00
correct value for 'you' in network session
This commit is contained in:
@@ -28,7 +28,6 @@
|
||||
{#if !session}
|
||||
<h3>no session</h3>
|
||||
{:else}
|
||||
{JSON.stringify(session)}
|
||||
{JSON.stringify($sessionEvents)}
|
||||
{#if session.state === SessionState.PENDING}
|
||||
<h3>waiting for other player...</h3>
|
||||
|
||||
@@ -84,12 +84,14 @@ const networkEvents = (session: NetworkSession) => readable([], function(set) {
|
||||
})
|
||||
|
||||
export const networkSessionStateEvents = (session: NetworkSession): Readable<unknown[]> => derived(networkEvents(session), $sessionEvents => {
|
||||
console.log("test")
|
||||
const sessionEvents = $sessionEvents.filter(({topic}) => topic === 'session').map(({event}) => event);
|
||||
if (!sessionEvents.length) {
|
||||
return [];
|
||||
}
|
||||
const latestSessionEvent = sessionEvents[sessionEvents.length-1];
|
||||
const session = {...latestSessionEvent.session, you: latestSessionEvent.actor, type: get(sessionStore).type}
|
||||
const currentSession = get(sessionStore) as NetworkSession;
|
||||
const session = {...latestSessionEvent.session, you: currentSession.you, type: currentSession.type}
|
||||
console.debug("updating current session: ", session)
|
||||
sessionStore.set(session);
|
||||
return sessionEvents;
|
||||
|
||||
Reference in New Issue
Block a user