Skip to content

Commit

Permalink
feat: add game type
Browse files Browse the repository at this point in the history
  • Loading branch information
SomethingSexy committed Oct 13, 2024
1 parent 02e003f commit 492384a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
4 changes: 2 additions & 2 deletions internal/chronicle/adapter/http/game/game_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewGameRequest(g domain.Game) GameRequest {
ID: g.GameId.String(),
GameId: g.GameId.String(),
Name: g.Name,
Type: g.Type,
Type: g.Type.String(),
Worlds: worlds,
}
}
Expand Down Expand Up @@ -52,6 +52,6 @@ func (a *GameRequest) ToDomain() domain.Game {
return domain.Game{
GameId: uuid.MustParse(a.GameId),
Name: a.Name,
Type: a.Type,
Type: domain.NewGameType(a.Type),
}
}
8 changes: 4 additions & 4 deletions internal/chronicle/adapter/persistence/postgres/query/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (g GameQuery) CreateGame(ctx context.Context, game domain.Game) (domain.Gam
args := repository.CreateGameParams{
GameID: game.GameId,
Name: game.Name,
Type: game.Type,
Type: game.Type.String(),
CreatedAt: ts,
UpdatedAt: ts,
}
Expand All @@ -42,7 +42,7 @@ func (g GameQuery) CreateGame(ctx context.Context, game domain.Game) (domain.Gam

return domain.Game{
Name: response.Name,
Type: response.Type,
Type: domain.NewGameType(response.Type),
}, nil
}

Expand All @@ -62,7 +62,7 @@ func (g GameQuery) ListGames(ctx context.Context) ([]domain.Game, error) {
for i, game := range response {
games[i] = domain.Game{
Name: game.Name,
Type: game.Type,
Type: domain.NewGameType(game.Type),
GameId: game.GameID,
}
}
Expand All @@ -78,7 +78,7 @@ func (g GameQuery) GetGame(ctx context.Context, id uuid.UUID) (domain.Game, erro

game := domain.Game{
Name: response.Name,
Type: response.Type,
Type: domain.NewGameType(response.Type),
GameId: response.GameID,
}

Expand Down
29 changes: 28 additions & 1 deletion internal/chronicle/core/domain/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,36 @@ package domain

import "github.com/google/uuid"

func NewGameType(t string) GameType {
switch t {
case "vtm":
return NPC
case "generic":
return PC
}

return NPC
}

// There will more than likely need to be a much more robust
// setup for different types of games, utilizing this for now.
//
// Game Type will be used to determine a lot of different things,
// including how characters are created
type GameType int

const (
Generic = iota
VTM
)

func (t GameType) String() string {
return [...]string{"generic", "vtm"}[t-1]
}

type Game struct {
GameId uuid.UUID
Name string
Type string
Type GameType
Worlds []World
}

0 comments on commit 492384a

Please sign in to comment.