Skip to content

Commit

Permalink
Queue display 'syncing' state
Browse files Browse the repository at this point in the history
  • Loading branch information
Maironire committed Oct 25, 2024
1 parent 7c28043 commit ba7b78b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
Binary file modified mini-game-assets/images/GameSigns.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 12 additions & 5 deletions src/queue/display/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { queue } from '../..'
export enum SCREENS {
addToQueue,
playNext,
queueList
queueList,
syncing
}

let frameEntity: Entity
Expand Down Expand Up @@ -222,10 +223,16 @@ function updateScreenSystem() {
delayedFunction(() => disable())
}
} else {
//player not in queue
disable()
enterScreenShown = false
setScreen(SCREENS.addToQueue)
if (queue.isAwaiting()) {
//player is awaiting to enter
enable()
setScreen(SCREENS.syncing)

Check failure on line 229 in src/queue/display/index.ts

View workflow job for this annotation

GitHub Actions / build

Delete `·`
} else {
//player not in queue
disable()
enterScreenShown = false
setScreen(SCREENS.addToQueue)
}
}
}

Expand Down
38 changes: 25 additions & 13 deletions src/queue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const listeners: { onActivePlayerChange: (player: PlayerType | null) => v
onActivePlayerChange: () => {}
}
let initializedQueue = false
let addPlayerRequested = false
/**
* We need the engine, syncEntity and playerApi as params to avoid references to different engines
* when working on development environments.
Expand All @@ -26,6 +27,7 @@ export function startPlayersQueue() {
initializedQueue = true
const { engine, players } = getSDK()
players.onLeaveScene((userId: string) => {
addPlayerRequested = false
removePlayer(userId)
})

Expand All @@ -36,22 +38,12 @@ export function startPlayersQueue() {
* Add current player to the queue
*/
export function addPlayer() {
const {
engine,
syncEntity,
components: { Player },
isStateSyncronized
} = getSDK()

const userId = getUserId()
if (!userId || isPlayerInQueue(userId) || !isStateSyncronized()) {
if (!userId || isPlayerInQueue(userId) || addPlayerRequested) {
return
}

const timestamp = Date.now()
const entity = engine.addEntity()
Player.create(entity, { address: userId, joinedAt: timestamp })
syncEntity(entity, [Player.componentId])
addPlayerRequested = true
}

/**
Expand All @@ -65,6 +57,10 @@ export function isActive(): boolean {
return false
}

export function isAwaiting( ) {

Check failure on line 60 in src/queue/index.ts

View workflow job for this annotation

GitHub Actions / build

Delete `·`
return addPlayerRequested
}

/**
* Get queue of players ordered
*/
Expand Down Expand Up @@ -145,6 +141,23 @@ function internalPlayerSystem() {
}
timer = 0

const {
engine,
config,
syncEntity,
components: { Player, RealmInfo },
isStateSyncronized
} = getSDK()

const realmInfo = RealmInfo.getOrNull(engine.RootEntity)
if (addPlayerRequested && realmInfo?.isConnectedSceneRoom && isStateSyncronized()) {
const timestamp = Date.now()
const entity = engine.addEntity()
Player.create(entity, { address: userId, joinedAt: timestamp })
syncEntity(entity, [Player.componentId])
addPlayerRequested = false
}

const [_, activePlayer] = getActivePlayer()

// Emit onActivePlayerChange if the last player has changed
Expand All @@ -157,7 +170,6 @@ function internalPlayerSystem() {
if (!activePlayer) {
setNextPlayer()
}
const { config } = getSDK()

// TIMER for active player and inactivity detection
if (
Expand Down

0 comments on commit ba7b78b

Please sign in to comment.