-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
48 lines (45 loc) · 1.33 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* @Author: Wujiahuo
* @Date: 2023-03-10 14:12:17
* @LastEditors: OBKoro1
* @LastEditTime: 2023-03-16 14:19:59
* @FilePath: \alien\config.go
* @Description:
* Copyright (c) 2023 by Wujiahuo/bzlrobot, All Rights Reserved.
*/
package main
import (
"encoding/json"
"image/color"
"log"
"os"
)
type Config struct {
ScreenWidth int `json:"screenWidth"`
ScreenHeight int `json:"screenHeight"`
Title string `json:"title"`
BgColor color.RGBA `json:"bgColor"`
ShipSpeedFactor float64 `json:"shipSpeedFactor"`
BulletWidth int `json:"bulletWidth"`
BulletHeight int `json:"bulletHeight"`
BulletSpeedFactor float64 `json:"bulletSpeedFactor"`
BulletColor color.RGBA `json:"bulletColor"`
MaxBulletNum int `json:"maxBulletNum"`
BulletInterval int64 `json:"bulletInterval"`
AlienSpeedFactor float64 `json:"alienSpeedFactor"`
TitleFontSize float64 `json:"titleFontSize"`
FontSize float64 `json:"fontSize"`
SmallFontSize float64 `json:"smallFontSize"`
}
func loadConfig() *Config {
r, err := os.Open("./config.json")
if err != nil {
log.Fatalf("os.Open failed: %v\n", err)
}
var cfg Config
err = json.NewDecoder(r).Decode(&cfg)
if err != nil {
log.Fatalf("cannot NewDecoder %v", err)
}
return &cfg
}