-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from the-ai-team/feature/105-race-page-develo…
…pment [Related #105] Race page development
- Loading branch information
Showing
56 changed files
with
1,166 additions
and
316 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { REQUEST_WAITING_TIME } from '@razor/constants'; | ||
|
||
export const REQUEST_WAITING_TIME_FOR_CLIENT = | ||
import.meta.env.VITE_REQUEST_WAITING_TIME || REQUEST_WAITING_TIME; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * as Connection from './connection'; | ||
export * as Race from './race'; | ||
export * as TextStyles from './text-styles'; | ||
export * as Time from './time'; |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './create-tournament.controller'; | ||
export * from './join-tournament.controller'; | ||
export * from './player-join.controller'; | ||
export * from './start-race.controller'; | ||
export * from './update-type-logs.controller'; |
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 |
---|---|---|
@@ -1,31 +1,33 @@ | ||
import { playerStateToAppPlayerState, SocketProtocols } from '@razor/models'; | ||
import { AddPlayerPayload, store } from '@razor/store'; | ||
|
||
import { AllServerPubSubEventsToTypeMap } from '../models'; | ||
import { AllClientPubSubEventsToTypeMap } from '../models'; | ||
import { pubsub } from '../utils/pubsub'; | ||
|
||
pubsub.subscribe( | ||
SocketProtocols.PlayerJoin, | ||
({ | ||
data, | ||
tournamentId, | ||
}: AllServerPubSubEventsToTypeMap[SocketProtocols.PlayerJoin]) => { | ||
const { id: playerId, state, ...playerData } = data.player; | ||
type PlayerJoinControllerArgs = | ||
AllClientPubSubEventsToTypeMap[SocketProtocols.PlayerJoin]; | ||
|
||
// converted PlayerState to AppPlayerState, | ||
// because we're using two models for store and socket | ||
const appPlayerState = playerStateToAppPlayerState(state); | ||
function playerJoinController({ | ||
data, | ||
tournamentId, | ||
}: PlayerJoinControllerArgs): void { | ||
const { id: playerId, state, ...playerData } = data.player; | ||
|
||
const dataToDispatch: AddPlayerPayload = { | ||
playerId, | ||
player: { | ||
...playerData, | ||
state: appPlayerState, | ||
// This is equal because received player and joined player on same tournament | ||
tournamentId, | ||
}, | ||
}; | ||
// converted PlayerState to AppPlayerState, | ||
// because we're using two models for store and socket | ||
const appPlayerState = playerStateToAppPlayerState(state); | ||
|
||
store.dispatch.game.addPlayer({ ...dataToDispatch }); | ||
}, | ||
); | ||
const dataToDispatch: AddPlayerPayload = { | ||
playerId, | ||
player: { | ||
...playerData, | ||
state: appPlayerState, | ||
// This is equal because received player and joined player on same tournament | ||
tournamentId, | ||
}, | ||
}; | ||
|
||
store.dispatch.game.addPlayer({ ...dataToDispatch }); | ||
} | ||
|
||
pubsub.subscribe(SocketProtocols.PlayerJoin, playerJoinController); |
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,23 @@ | ||
import { SocketProtocols } from '@razor/models'; | ||
import { store } from '@razor/store'; | ||
|
||
import { AllClientPubSubEventsToTypeMap } from '../models'; | ||
import { pubsub } from '../utils/pubsub'; | ||
|
||
type StartRaceControllerArgs = | ||
AllClientPubSubEventsToTypeMap[SocketProtocols.StartRaceAccept]; | ||
|
||
function StartRaceController({ | ||
data, | ||
tournamentId, | ||
}: StartRaceControllerArgs): void { | ||
const { raceStartedBy, raceText, ..._ } = data; | ||
|
||
store.dispatch.game.startCountdown({ | ||
tournamentId, | ||
playerId: raceStartedBy, | ||
raceText, | ||
}); | ||
} | ||
|
||
pubsub.subscribe(SocketProtocols.StartRaceAccept, StartRaceController); |
32 changes: 32 additions & 0 deletions
32
apps/client/src/controllers/update-type-logs.controller.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,32 @@ | ||
import { PlayerId, SocketProtocols } from '@razor/models'; | ||
import { store } from '@razor/store'; | ||
|
||
import { AllClientPubSubEventsToTypeMap } from '../models'; | ||
import { pubsub } from '../utils/pubsub'; | ||
|
||
type UpdateTypeLogsControllerArgs = | ||
AllClientPubSubEventsToTypeMap[SocketProtocols.UpdateTypeLogs]; | ||
|
||
function updateTypeLogsController({ | ||
data, | ||
savedPlayerId, | ||
}: UpdateTypeLogsControllerArgs): void { | ||
const { raceId, playerLogs: playersLogs } = data; | ||
const race = store.getState().game.racesModel[raceId]; | ||
const racePlayerIds = Object.keys(race.players) as PlayerId[]; | ||
|
||
for (const playerId of racePlayerIds) { | ||
const logs = playersLogs[playerId]; | ||
if (!logs || playerId === savedPlayerId) { | ||
continue; | ||
} | ||
|
||
store.dispatch.game.sendTypeLog({ | ||
playerLog: logs, | ||
playerId, | ||
raceId, | ||
}); | ||
} | ||
} | ||
|
||
pubsub.subscribe(SocketProtocols.UpdateTypeLogs, updateTypeLogsController); |
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
{ | ||
"page": "Race" | ||
"page": "Race", | ||
"toasts": { | ||
"race_start": { | ||
"title": "Ready, set, go!", | ||
"message": "{{player_name}} started the race. Good luck!" | ||
} | ||
} | ||
} |
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
Oops, something went wrong.