Skip to content

Commit 0a53e87

Browse files
committed
Add missing wrapper functions
1 parent 15c3d55 commit 0a53e87

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

new/client/templates/wrappers/game.go.tmpl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ func ReconnectGame(username string) (*Game, error) {
7575
}, nil
7676
}
7777

78+
// Spectate joins a game as a spectator.
79+
func Spectate(gameId string) (*Game, error) {
80+
socket, err := cg.NewSocket("{{.URL}}")
81+
if err != nil {
82+
return nil, fmt.Errorf("failed to connect to server: %s", err)
83+
}
84+
85+
err = socket.Spectate(gameId)
86+
if err != nil {
87+
return nil, fmt.Errorf("failed to spectate game: %s", err)
88+
}
89+
90+
return &Game{
91+
Id: socket.Session().GameId,
92+
socket: socket,
93+
}, nil
94+
}
95+
7896
// Run starts the event loop (blocking).
7997
func (g *Game) Run() error {
8098
return g.socket.RunEventLoop()
@@ -89,6 +107,16 @@ func (g *Game) Update() error {
89107
return err
90108
}
91109

110+
// ResolveUsername returns the username associated with playerId.
111+
func (g *Game) ResolveUsername(playerId string) string {
112+
return g.socket.ResolveUsername(playerId)
113+
}
114+
115+
// Session returns details of the current session.
116+
func (g *Game) Session() cg.Session {
117+
return g.socket.Session()
118+
}
119+
92120
// Disconnect closes the underlying socket connection.
93121
func (g *Game) Disconnect() error {
94122
return g.socket.Close()

versions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"server": {
3-
"0.7": "0.1"
3+
"0.7": "0.2"
44
},
55
"client": {
6-
"0.8": "0.1"
6+
"0.8": "0.2"
77
}
88
}

0 commit comments

Comments
 (0)