1- package controller
1+ package config
22
33import (
44 "github.com/pkg/errors"
@@ -7,16 +7,17 @@ import (
77 "time"
88)
99
10- // ConfigSpecial holds configs that are different between normal and overtime halves
11- type ConfigSpecial struct {
10+ // Special holds configs that are different between normal and overtime halves
11+ type Special struct {
1212 HalfDuration time.Duration `yaml:"half-duration"`
1313 HalfTimeDuration time.Duration `yaml:"half-time-duration"`
1414 TimeoutDuration time.Duration `yaml:"timeout-duration"`
1515 Timeouts int `yaml:"timeouts"`
1616 BreakAfter time.Duration `yaml:"break-after"`
1717}
1818
19- type ConfigGeometry struct {
19+ // Geometry holds sizes of the field and distance for certain rules
20+ type Geometry struct {
2021 FieldLength float64 `yaml:"field-length"`
2122 FieldWidth float64 `yaml:"field-width"`
2223 DefenseAreaDepth float64 `yaml:"defense-area-depth"`
@@ -27,56 +28,56 @@ type ConfigGeometry struct {
2728 PlacementOffsetDefenseArea float64 `yaml:"placement-offset-defense-area"`
2829}
2930
30- // ConfigGame holds configs that are valid for the whole game
31- type ConfigGame struct {
32- YellowCardDuration time.Duration `yaml:"yellow-card-duration"`
33- DefaultDivision Division `yaml:"default-division"`
34- Normal ConfigSpecial `yaml:"normal"`
35- Overtime ConfigSpecial `yaml:"overtime"`
36- TeamChoiceTimeout time.Duration `yaml:"team-choice-timeout"`
37- DefaultGeometry map [Division ]* ConfigGeometry `yaml:"default-geometry"`
38- MultipleCardStep int `yaml:"multiple-card-step"`
39- MultipleFoulStep int `yaml:"multiple-foul-step"`
40- MultiplePlacementFailures int `yaml:"multiple-placement-failures"`
41- MaxBots map [Division ]int `yaml:"max-bots"`
42- AutoRefProposalTimeout time.Duration `yaml:"auto-ref-proposal-timeout"`
31+ // Game holds configs that are valid for the whole game
32+ type Game struct {
33+ YellowCardDuration time.Duration `yaml:"yellow-card-duration"`
34+ DefaultDivision Division `yaml:"default-division"`
35+ Normal Special `yaml:"normal"`
36+ Overtime Special `yaml:"overtime"`
37+ TeamChoiceTimeout time.Duration `yaml:"team-choice-timeout"`
38+ DefaultGeometry map [Division ]* Geometry `yaml:"default-geometry"`
39+ MultipleCardStep int `yaml:"multiple-card-step"`
40+ MultipleFoulStep int `yaml:"multiple-foul-step"`
41+ MultiplePlacementFailures int `yaml:"multiple-placement-failures"`
42+ MaxBots map [Division ]int `yaml:"max-bots"`
43+ AutoRefProposalTimeout time.Duration `yaml:"auto-ref-proposal-timeout"`
4344}
4445
45- // ConfigNetwork holds configs for network communication
46- type ConfigNetwork struct {
46+ // Network holds configs for network communication
47+ type Network struct {
4748 PublishAddress string `yaml:"publish-address"`
4849 VisionAddress string `yaml:"vision-address"`
4950}
5051
51- // ConfigServer holds configs for the available server services
52- type ConfigServer struct {
53- AutoRef ConfigServerAutoRef `yaml:"auto-ref"`
54- Team ConfigServerTeam `yaml:"team"`
52+ // Server holds configs for the available server services
53+ type Server struct {
54+ AutoRef ServerAutoRef `yaml:"auto-ref"`
55+ Team ServerTeam `yaml:"team"`
5556}
5657
57- // ConfigServerAutoRef holds configs for the autoRef server
58- type ConfigServerAutoRef struct {
58+ // ServerAutoRef holds configs for the autoRef server
59+ type ServerAutoRef struct {
5960 Address string `yaml:"address"`
6061 TrustedKeysDir string `yaml:"trusted-keys-dir"`
6162}
6263
63- // ConfigServerTeam holds configs for the team server
64- type ConfigServerTeam struct {
64+ // ServerTeam holds configs for the team server
65+ type ServerTeam struct {
6566 Address string `yaml:"address"`
6667 TrustedKeysDir string `yaml:"trusted-keys-dir"`
6768}
6869
69- // Config structure for the game controller
70- type Config struct {
71- Network ConfigNetwork `yaml:"network"`
72- Game ConfigGame `yaml:"game"`
73- Server ConfigServer `yaml:"server"`
70+ // Controller structure for the game controller
71+ type Controller struct {
72+ Network Network `yaml:"network"`
73+ Game Game `yaml:"game"`
74+ Server Server `yaml:"server"`
7475}
7576
76- // LoadConfig loads a config from given file
77- func LoadConfig (fileName string ) (config Config , err error ) {
77+ // LoadControllerConfig loads a config from given file
78+ func LoadControllerConfig (fileName string ) (config Controller , err error ) {
7879
79- config = DefaultConfig ()
80+ config = DefaultControllerConfig ()
8081
8182 f , err := os .OpenFile (fileName , os .O_RDONLY , 0600 )
8283 if err != nil {
@@ -96,8 +97,8 @@ func LoadConfig(fileName string) (config Config, err error) {
9697 return
9798}
9899
99- // DefaultConfig creates a config with default values
100- func DefaultConfig () (c Config ) {
100+ // DefaultControllerConfig creates a config with default values
101+ func DefaultControllerConfig () (c Controller ) {
101102 c .Network .PublishAddress = "224.5.23.1:10003"
102103 c .Network .VisionAddress = "224.5.23.2:10006"
103104 c .Game .YellowCardDuration = 2 * time .Minute
@@ -126,8 +127,8 @@ func DefaultConfig() (c Config) {
126127 c .Server .Team .Address = ":10008"
127128 c .Server .Team .TrustedKeysDir = "config/trusted_keys/team"
128129
129- c .Game .DefaultGeometry = map [Division ]* ConfigGeometry {}
130- c .Game .DefaultGeometry [DivA ] = new (ConfigGeometry )
130+ c .Game .DefaultGeometry = map [Division ]* Geometry {}
131+ c .Game .DefaultGeometry [DivA ] = new (Geometry )
131132 c .Game .DefaultGeometry [DivA ].FieldLength = 12
132133 c .Game .DefaultGeometry [DivA ].FieldWidth = 9
133134 c .Game .DefaultGeometry [DivA ].DefenseAreaDepth = 1.2
@@ -137,7 +138,7 @@ func DefaultConfig() (c Config) {
137138 c .Game .DefaultGeometry [DivA ].PlacementOffsetTouchLine = 0.2
138139 c .Game .DefaultGeometry [DivA ].PlacementOffsetDefenseArea = 1.0
139140
140- c .Game .DefaultGeometry [DivB ] = new (ConfigGeometry )
141+ c .Game .DefaultGeometry [DivB ] = new (Geometry )
141142 c .Game .DefaultGeometry [DivB ].FieldLength = 9
142143 c .Game .DefaultGeometry [DivB ].FieldWidth = 6
143144 c .Game .DefaultGeometry [DivB ].DefenseAreaDepth = 1
0 commit comments