added implementation in GO lang
This commit is contained in:
43
internal/app/config.go
Normal file
43
internal/app/config.go
Normal file
@ -0,0 +1,43 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
WindowWidth int
|
||||
WindowHeight int
|
||||
Fullscreen bool
|
||||
}
|
||||
|
||||
func ParseConfig() Config {
|
||||
cfg := Config{
|
||||
WindowWidth: 1280,
|
||||
WindowHeight: 720,
|
||||
Fullscreen: envBool("KIDSKEYBOARD_FULLSCREEN"),
|
||||
}
|
||||
|
||||
flag.IntVar(&cfg.WindowWidth, "width", cfg.WindowWidth, "window width")
|
||||
flag.IntVar(&cfg.WindowHeight, "height", cfg.WindowHeight, "window height")
|
||||
flag.BoolVar(&cfg.Fullscreen, "fullscreen", cfg.Fullscreen, "start in fullscreen mode")
|
||||
flag.Bool("windowed", false, "force windowed mode")
|
||||
flag.Parse()
|
||||
|
||||
if flag.Lookup("windowed") != nil {
|
||||
if v := flag.Lookup("windowed").Value.String(); v == "true" {
|
||||
cfg.Fullscreen = false
|
||||
}
|
||||
}
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
func envBool(name string) bool {
|
||||
switch os.Getenv(name) {
|
||||
case "1", "true", "TRUE", "yes", "YES", "on", "ON":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user