Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multilingual, closing #168 #170

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/MatchMaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ module.exports = class MatchMaker {
* Create a new game hosted by the given player.
*/

createGame (player) {
const [origin, goal] = this.wikiPages.randomPair()
async createGame (player) {
const [origin, goal] = await this.wikiPages.randomPair()
const game = new WikiBattle(origin, goal)
game.connect(player)
return game
Expand All @@ -32,7 +32,7 @@ module.exports = class MatchMaker {
* either the previous, or the next player that is passed to this method.
*/

pair (player) {
async pair (player) {
if (this.waitingPair) {
debug('pairing with existing')
const game = this.waitingPair
Expand All @@ -49,7 +49,7 @@ module.exports = class MatchMaker {
}

debug('waiting for pairing')
const game = this.createGame(player)
const game = await this.createGame(player)
this.waitingPair = game

player.notifyJoinedGame(game)
Expand All @@ -63,10 +63,10 @@ module.exports = class MatchMaker {
* shareable URL.
*/

new (player) {
async new (player) {
debug('forcing new game')

const game = this.createGame(player)
const game = await this.createGame(player)
this.games[game.id] = game

player.notifyJoinedGame(game)
Expand Down
10 changes: 5 additions & 5 deletions src/SocketHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ module.exports = class SocketHandler {
const sock = new SocketEvents(raw)
const player = new Player(sock)

sock.on('gameType', (type, id) => {
sock.on('gameType', async (type, id) => {
switch (type) {
case 'pair':
game = this.matchMaker.pair(player)
game = await this.matchMaker.pair(player)
break
case 'new':
game = this.matchMaker.new(player)
game = await this.matchMaker.new(player)
break
case 'join':
try {
Expand All @@ -47,8 +47,8 @@ module.exports = class SocketHandler {
}
})

raw.on('close', () => {
if (game) {
raw.on('close', async () => {
if (await game) {
game.disconnect(player)

this.matchMaker.disconnected(game)
Expand Down
2 changes: 1 addition & 1 deletion src/WikiPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = class WikiPages extends EventEmitter {
* Get a pair of random article names, guaranteed to be two different pages.
*/

randomPair () {
async randomPair () {
const one = this.random()

let two = this.random()
Expand Down