-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.go
More file actions
56 lines (47 loc) · 1.43 KB
/
routes.go
File metadata and controls
56 lines (47 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/core"
)
// registerRoutes registers all custom API routes
func registerRoutes(app *pocketbase.PocketBase) {
// Routes will be implemented using PocketBase hooks
// For now, we'll set up basic structure
app.OnRecordCreate("tables").BindFunc(func(e *core.RecordEvent) error {
// Auto-add owner to players list
record := e.Record
owner := record.GetString("owner")
players := record.GetStringSlice("players")
// Check if owner is already in players
found := false
for _, p := range players {
if p == owner {
found = true
break
}
}
if !found {
players = append(players, owner)
record.Set("players", players)
}
return e.Next()
})
app.OnRecordUpdate("tables").BindFunc(func(e *core.RecordEvent) error {
// TODO: Implement auto-start game logic when all players are ready
// This should:
// 1. Check if all players have player_states.ready = true
// 2. Verify minimum player count is met
// 3. Create initial game_state
// 4. Transition table status to "playing"
// 5. Broadcast game start event to all players
// Example implementation outline:
// record := e.Record
// if record.GetString("status") == "waiting" {
// playerStates := record.Get("player_states")
// if allPlayersReady(playerStates) {
// startGame(e.App, record)
// }
// }
return e.Next()
})
}