@@ -13,7 +13,7 @@ import (
1313 "os"
1414 "strings"
1515
16- "github.com/code-game-project/go-client/cg "
16+ "{{.LibraryURL}} "
1717 "github.com/spf13/pflag"
1818)
1919
@@ -28,6 +28,7 @@ func init() {
2828
2929type Game struct {
3030 Id string
31+ Config GameConfig
3132 socket *cg.Socket
3233 spectating bool
3334}
@@ -147,6 +148,7 @@ func CreateAndJoinGame(public, protected bool, username string, config GameConfi
147148
148149 return &Game{
149150 Id: gameId,
151+ Config: config,
150152 socket: socket,
151153 }, joinSecret, nil
152154}
@@ -170,6 +172,7 @@ func CreateAndSpectateGame(public, protected bool, config GameConfig) (*Game, st
170172
171173 return &Game{
172174 Id: gameId,
175+ Config: config,
173176 socket: socket,
174177 }, joinSecret, nil
175178}
@@ -187,8 +190,14 @@ func JoinGame(gameId, username, joinSecret string) (*Game, error) {
187190 return nil, fmt.Errorf("failed to join game: %s", err)
188191 }
189192
193+ config, err := cg.FetchGameConfig[GameConfig](socket, gameId)
194+ if err != nil {
195+ return nil, err
196+ }
197+
190198 return &Game{
191199 Id: gameId,
200+ Config: config,
192201 socket: socket,
193202 }, nil
194203}
@@ -205,8 +214,14 @@ func ReconnectGame(username string) (*Game, error) {
205214 return nil, fmt.Errorf("failed to reconnect: %s", err)
206215 }
207216
217+ config, err := cg.FetchGameConfig[GameConfig](socket, socket.Session().GameId)
218+ if err != nil {
219+ return nil, err
220+ }
221+
208222 return &Game{
209223 Id: socket.Session().GameId,
224+ Config: config,
210225 socket: socket,
211226 }, nil
212227}
@@ -222,9 +237,15 @@ func SpectateGame(gameId string) (*Game, error) {
222237 if err != nil {
223238 return nil, fmt.Errorf("failed to spectate game: %s", err)
224239 }
240+
241+ config, err := cg.FetchGameConfig[GameConfig](socket, gameId)
242+ if err != nil {
243+ return nil, err
244+ }
225245
226246 return &Game{
227247 Id: socket.Session().GameId,
248+ Config: config,
228249 socket: socket,
229250 }, nil
230251}
0 commit comments