refactor: rename game package to connect4, drop Game prefix from types
Rename game/ -> connect4/ to avoid c4/game stutter. Drop redundant
Game prefix from exported types (GameStore -> Store, GameInstance ->
Instance, GameStatus -> Status). Rename NATS subjects from game.{id}
to connect4.{id}. URL routes unchanged.
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/ryanhamamura/c4/game"
|
||||
"github.com/ryanhamamura/c4/connect4"
|
||||
"github.com/starfederation/datastar-go/datastar"
|
||||
)
|
||||
|
||||
@@ -46,10 +46,10 @@ templ gameListEntry(g GameListItem) {
|
||||
}
|
||||
|
||||
func statusText(g GameListItem) string {
|
||||
switch game.GameStatus(g.Status) {
|
||||
case game.StatusWaitingForPlayer:
|
||||
switch connect4.Status(g.Status) {
|
||||
case connect4.StatusWaitingForPlayer:
|
||||
return "Waiting for opponent"
|
||||
case game.StatusInProgress:
|
||||
case connect4.StatusInProgress:
|
||||
if g.IsMyTurn {
|
||||
return "Your turn!"
|
||||
}
|
||||
@@ -59,10 +59,10 @@ func statusText(g GameListItem) string {
|
||||
}
|
||||
|
||||
func statusClass(g GameListItem) string {
|
||||
switch game.GameStatus(g.Status) {
|
||||
case game.StatusWaitingForPlayer:
|
||||
switch connect4.Status(g.Status) {
|
||||
case connect4.StatusWaitingForPlayer:
|
||||
return "text-sm opacity-60"
|
||||
case game.StatusInProgress:
|
||||
case connect4.StatusInProgress:
|
||||
if g.IsMyTurn {
|
||||
return "text-sm text-success font-bold"
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/ryanhamamura/c4/connect4"
|
||||
"github.com/ryanhamamura/c4/db/repository"
|
||||
lobbycomponents "github.com/ryanhamamura/c4/features/lobby/components"
|
||||
"github.com/ryanhamamura/c4/features/lobby/pages"
|
||||
"github.com/ryanhamamura/c4/game"
|
||||
"github.com/ryanhamamura/c4/snake"
|
||||
|
||||
"github.com/alexedwards/scs/v2"
|
||||
@@ -80,7 +80,7 @@ func HandleLobbyPage(queries *repository.Queries, sessions *scs.SessionManager,
|
||||
}
|
||||
|
||||
// HandleCreateGame reads the nickname signal, creates a connect4 game, and redirects via SSE.
|
||||
func HandleCreateGame(store *game.GameStore, sessions *scs.SessionManager) http.HandlerFunc {
|
||||
func HandleCreateGame(store *connect4.Store, sessions *scs.SessionManager) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
type Signals struct {
|
||||
Nickname string `json:"nickname"`
|
||||
@@ -104,7 +104,7 @@ func HandleCreateGame(store *game.GameStore, sessions *scs.SessionManager) http.
|
||||
}
|
||||
|
||||
// HandleDeleteGame deletes a connect4 game and redirects to the lobby.
|
||||
func HandleDeleteGame(store *game.GameStore, sessions *scs.SessionManager) http.HandlerFunc {
|
||||
func HandleDeleteGame(store *connect4.Store, sessions *scs.SessionManager) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
gameID := chi.URLParam(r, "id")
|
||||
if gameID == "" {
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
package lobby
|
||||
|
||||
import (
|
||||
"github.com/ryanhamamura/c4/connect4"
|
||||
"github.com/ryanhamamura/c4/db/repository"
|
||||
"github.com/ryanhamamura/c4/game"
|
||||
"github.com/ryanhamamura/c4/snake"
|
||||
|
||||
"github.com/alexedwards/scs/v2"
|
||||
@@ -14,7 +14,7 @@ func SetupRoutes(
|
||||
router chi.Router,
|
||||
queries *repository.Queries,
|
||||
sessions *scs.SessionManager,
|
||||
store *game.GameStore,
|
||||
store *connect4.Store,
|
||||
snakeStore *snake.SnakeStore,
|
||||
) {
|
||||
router.Get("/", HandleLobbyPage(queries, sessions, snakeStore))
|
||||
|
||||
Reference in New Issue
Block a user