Skip to content

Commit

Permalink
Use implicit cast of app/game structs
Browse files Browse the repository at this point in the history
That will make the code a bit tidier.
  • Loading branch information
sergystepanov committed Aug 1, 2023
1 parent 7fe3a89 commit 49cb752
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pkg/api/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ type (
PlayerIndex int `json:"player_index"`
}
GameInfo struct {
Name string `json:"name"`
Base string `json:"base"`
Name string `json:"name"`
Path string `json:"path"`
System string `json:"system"`
Type string `json:"type"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/coordinator/workerapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (w *Worker) StartGame(id com.Uid, app games.AppMeta, req api.GameStartUserR
return api.UnwrapChecked[api.StartGameResponse](
w.Send(api.StartGame, api.StartGameRequest[com.Uid]{
StatefulRoom: StateRoom(id, req.RoomId),
Game: api.GameInfo{Name: app.Name, Base: app.Base, Path: app.Path, System: app.System, Type: app.Type},
Game: api.GameInfo(app),
PlayerIndex: req.PlayerIndex,
Record: req.Record,
RecordUser: req.RecordUser,
Expand Down
4 changes: 2 additions & 2 deletions pkg/games/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ type Launcher interface {
}

type AppMeta struct {
Name string
Type string
Base string
Name string
Path string
System string
Type string
}

type GameLauncher struct {
Expand Down
11 changes: 4 additions & 7 deletions pkg/games/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,11 @@ type WithEmulatorInfo interface {
}

type GameMetadata struct {
// the display name of the game
Name string
// the game file extension (e.g. nes, n64)
Type string
Base string
// the game path relative to the library base path
Path string
Base string
Name string // the display name of the game
Path string // the game path relative to the library base path
System string
Type string // the game file extension (e.g. nes, n64)
}

func (g GameMetadata) FullPath(base string) string {
Expand Down
4 changes: 1 addition & 3 deletions pkg/worker/coordinatorhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ func (c *coordinator) HandleGameStart(rq api.StartGameRequest[com.Uid], w *Worke
if room == nil {
room = NewRoom(
rq.Room.Rid,
games.GameMetadata{
Name: rq.Game.Name, Base: rq.Game.Base, Type: rq.Game.Type, Path: rq.Game.Path, System: rq.Game.System,
},
games.GameMetadata(rq.Game),
func(room *Room) {
w.router.SetRoom(nil)
c.CloseRoom(room.id)
Expand Down

0 comments on commit 49cb752

Please sign in to comment.