-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): integrating the sdk with the new api def
- Loading branch information
Showing
16 changed files
with
114 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { HasteGame } from '../game/hasteGame'; | ||
import { GameSceneData } from '../models/gameState'; | ||
import { Button } from '../game-objects/button'; | ||
import { Auth0Client } from '@auth0/auth0-spa-js'; | ||
import { Leaderboard } from '../game-objects/leaderboard'; | ||
import { Leader } from '@haste-sdk/domain'; | ||
|
||
// The ResultsScene loads the leaderboard with the | ||
// top results | ||
export class ResultsScene extends Phaser.Scene { | ||
private auth0: Auth0Client; | ||
logoutButton: Button; | ||
leaderboard: Leaderboard; | ||
|
||
constructor() { | ||
super({ | ||
key: 'ResultsScene', | ||
}); | ||
} | ||
|
||
init(data: GameSceneData) { | ||
const hasteGame = this.game as HasteGame; | ||
this.auth0 = data.auth; | ||
this.addLogoutButton(); | ||
|
||
hasteGame.socketManager.gameGetLeadersCompletedEvent.on((data: Leader[]) => { | ||
this.leaderboard = new Leaderboard(this, 300, 100, data); | ||
this.add.existing(this.leaderboard); | ||
}); | ||
|
||
hasteGame.socketManager.gameGetLeadersEvent.emit(hasteGame.selectedLeaderboardId); | ||
} | ||
|
||
private addLogoutButton() { | ||
this.logoutButton = new Button(this, 700, 20, 'Logout', { fill: '#f00' }, async () => { | ||
return await this.logout(); | ||
}); | ||
this.add.existing(this.logoutButton); | ||
} | ||
|
||
preload() { | ||
this.cameras.main.setBackgroundColor(0x98d687); | ||
} | ||
|
||
async logout() { | ||
await new Promise((resolve) => { | ||
const hasteGame = this.game as HasteGame; | ||
hasteGame.socketManager.logoutEvent.emit(); | ||
this.auth0.logout({ | ||
returnTo: window.location.origin, | ||
}); | ||
resolve(undefined); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/haste-game-server/src/server/listeners/gameGetLeadersListener.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { JwtPayload } from 'jsonwebtoken'; | ||
import { GameEngine } from '../../game/gameEngine'; | ||
import { Haste } from '@haste-sdk/sdk'; | ||
import { Socket } from 'socket.io'; | ||
import { Leaderboard } from '@haste-sdk/domain'; | ||
|
||
// This is called when the user logs in | ||
// the haste client game. The gameGetLevels event is emitted | ||
// from the client and received by the server. The server is listening | ||
// and then leverages the Haste SDK to retrieve all the levels for | ||
// the current game. | ||
export async function gameGetLeadersListener( | ||
jwt: JwtPayload, | ||
haste: Haste, | ||
engine: GameEngine, | ||
socket: Socket, | ||
leaderboardId: string, | ||
) { | ||
const leaders = await haste.game.leaders(new Leaderboard(leaderboardId)); | ||
socket.emit('gameGetLeadersCompleted', leaders); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters