added config file support
This commit is contained in:
+11
-8
@@ -20,7 +20,8 @@ func startGame(w http.ResponseWriter, req *http.Request) {
|
||||
log.Println("asked to create a game")
|
||||
|
||||
requested_game_name := idg.Hash()
|
||||
width, height := float32(*width), float32(*height)
|
||||
width, height := float32(conf.Width), float32(conf.Height)
|
||||
tick := conf.Tick
|
||||
|
||||
// here we determine if we are going to run with defaults or pick them off
|
||||
// a posted json blob
|
||||
@@ -30,12 +31,13 @@ func startGame(w http.ResponseWriter, req *http.Request) {
|
||||
log.Printf("unable to read request body:", err)
|
||||
}
|
||||
req.Body.Close()
|
||||
conf := struct {
|
||||
With float32 `json:"width"`
|
||||
cfg := struct {
|
||||
Width float32 `json:"width"`
|
||||
Height float32 `json:"height"`
|
||||
Name string `json:"name"`
|
||||
Tick int `json:"tick"`
|
||||
}{}
|
||||
err = json.Unmarshal(body, &conf)
|
||||
err = json.Unmarshal(body, &cfg)
|
||||
if err != nil {
|
||||
NewFailure(err.Error())
|
||||
if err := json.NewEncoder(w).Encode(NewFailure(err.Error())); err != nil {
|
||||
@@ -43,15 +45,16 @@ func startGame(w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
return
|
||||
}
|
||||
requested_game_name = conf.Name
|
||||
width = conf.With
|
||||
height = conf.Height
|
||||
requested_game_name = cfg.Name
|
||||
width = cfg.Width
|
||||
height = cfg.Height
|
||||
tick = cfg.Tick
|
||||
}
|
||||
|
||||
g := games.get(requested_game_name)
|
||||
if g == nil {
|
||||
log.Printf("Game '%s' non-existant; making it now", requested_game_name)
|
||||
g = NewGame(requested_game_name, width, height)
|
||||
g = NewGame(requested_game_name, width, height, tick)
|
||||
go g.run()
|
||||
games.add(g)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user