Merge pull request 'color is optional' (#3) from mertoalex/ballsoffline:main into main
Reviewed-on: #3
This commit is contained in:
commit
b04461b49d
|
@ -8,7 +8,9 @@ To play first create an accounts.json, you can look example file [account.def.js
|
|||
|
||||
If you're on linux, you can do:
|
||||
```bash
|
||||
echo '{"username":"'$USER'","color":"000000"}' > account.json
|
||||
echo '{"username":"'$USER'"}' > account.json
|
||||
# or
|
||||
echo '{"username":"'$USER'","color":"DEAD00"}' > account.json
|
||||
```
|
||||
|
||||
## Credits
|
||||
|
|
2
bf.go
2
bf.go
|
@ -11,7 +11,7 @@ const (
|
|||
screenWidth = 1280
|
||||
screenHeight = 720
|
||||
ballRadius = 12
|
||||
debug = false
|
||||
debug = false
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -15,10 +15,26 @@ func checkValid(something any) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func makeDefault(variable *map[string]interface{}, Type string) {
|
||||
switch Type {
|
||||
case "color": (*variable)[Type] = "000000"
|
||||
default: panic(fmt.Sprint("\"", Type, "\" isn't a type!"))
|
||||
}
|
||||
}
|
||||
|
||||
func checkUserDataValid(userdata map[string]interface{}) {
|
||||
for _, data := range []string{"username", "color"} {
|
||||
//required
|
||||
for _, data := range []string{"username"} {
|
||||
if !checkValid(userdata[data]) {
|
||||
panic(fmt.Sprint("\"", data, "\" isn't defined in userdata:\n", userdata))
|
||||
panic(fmt.Sprint("\"", data, "\" isn't defined in userdata:\n\t", userdata))
|
||||
}
|
||||
}
|
||||
|
||||
//optional
|
||||
for _, data := range []string{"color"} {
|
||||
if !checkValid(userdata[data]) {
|
||||
fmt.Printf("WARNING: \"%s\" isn't defined in userdata:\n\t%s\n\tgonna use default variable for that\n", data, userdata)
|
||||
makeDefault(&userdata, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue