Skip to content

Commit 0c14ad5

Browse files
committed
[refactoring] Move engine code to engine.go and remove global refBox var
1 parent 8bc3c8a commit 0c14ad5

File tree

5 files changed

+229
-209
lines changed

5 files changed

+229
-209
lines changed

cmd/ssl-game-controller/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77

88
func main() {
99

10-
controller.RefBox.Run()
10+
g := controller.NewGameController()
11+
g.Run()
1112

1213
// serve the static resource of UI (for production use only)
1314
http.Handle("/", http.FileServer(http.Dir(".")))
1415
// serve the bidirectional web socket
15-
http.HandleFunc("/ws", controller.RefBox.ApiServer.WsHandler)
16+
http.HandleFunc("/ws", g.ApiServer.WsHandler)
1617
http.ListenAndServe(":8081", nil)
1718
}

internal/app/controller/config.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ type ConfigSpecial struct {
1616
BreakAfter time.Duration `yaml:"break-after"`
1717
}
1818

19-
// ConfigGlobal holds configs that are valid for the whole game
20-
type ConfigGlobal struct {
19+
// ConfigGame holds configs that are valid for the whole game
20+
type ConfigGame struct {
2121
YellowCardDuration time.Duration `yaml:"yellow-card-duration"`
22+
Normal ConfigSpecial `yaml:"normal"`
23+
Overtime ConfigSpecial `yaml:"overtime"`
2224
}
2325

2426
// ConfigPublish holds configs for publishing the state and commands to the teams
@@ -28,10 +30,8 @@ type ConfigPublish struct {
2830

2931
// Config structure for the game controller
3032
type Config struct {
31-
Publish ConfigPublish `yaml:"publish"`
32-
Global ConfigGlobal `yaml:"global"`
33-
Normal ConfigSpecial `yaml:"normal"`
34-
Overtime ConfigSpecial `yaml:"overtime"`
33+
Publish ConfigPublish `yaml:"publish"`
34+
Game ConfigGame `yaml:"game"`
3535
}
3636

3737
// LoadConfig loads a config from given file
@@ -58,19 +58,19 @@ func LoadConfig(fileName string) (config Config, err error) {
5858
// DefaultConfig creates a config with default values
5959
func DefaultConfig() (c Config) {
6060
c.Publish.Address = "224.5.23.1:10003"
61-
c.Global.YellowCardDuration = 2 * time.Minute
62-
63-
c.Normal.HalfDuration = 5 * time.Minute
64-
c.Normal.HalfTimeDuration = 5 * time.Minute
65-
c.Normal.Timeouts = 4
66-
c.Normal.TimeoutDuration = 5 * time.Minute
67-
c.Normal.BreakAfter = 5 * time.Minute
68-
69-
c.Overtime.HalfDuration = 2*time.Minute + 30*time.Second
70-
c.Overtime.HalfTimeDuration = 2 * time.Minute
71-
c.Overtime.Timeouts = 2
72-
c.Overtime.TimeoutDuration = 5 * time.Minute
73-
c.Overtime.BreakAfter = 2 * time.Minute
61+
c.Game.YellowCardDuration = 2 * time.Minute
62+
63+
c.Game.Normal.HalfDuration = 5 * time.Minute
64+
c.Game.Normal.HalfTimeDuration = 5 * time.Minute
65+
c.Game.Normal.Timeouts = 4
66+
c.Game.Normal.TimeoutDuration = 5 * time.Minute
67+
c.Game.Normal.BreakAfter = 5 * time.Minute
68+
69+
c.Game.Overtime.HalfDuration = 2*time.Minute + 30*time.Second
70+
c.Game.Overtime.HalfTimeDuration = 2 * time.Minute
71+
c.Game.Overtime.Timeouts = 2
72+
c.Game.Overtime.TimeoutDuration = 5 * time.Minute
73+
c.Game.Overtime.BreakAfter = 2 * time.Minute
7474

7575
return
7676
}

0 commit comments

Comments
 (0)