doodle/pkg/balance/boolprops.go
Noah Petherbridge fd649b7ab1 Doodad CLI Tool Features; Write Lock and Hidden
* The `doodad` CLI tool got a lot of new commands:
  * `doodad show` to verbosely print details about Levels and Doodads.
  * `edit-level` and `edit-doodad` to update details about Levels and
    Doodads, such as their Title, Author, page type and size, etc.
* Doodads gain a `Hidden bool` that hides them from the palette in
  Editor Mode. The player character (Blue Azulian) is Hidden.
* Add some boolProps to the balance/ package and made a dynamic system
  to easily configure these with the in-game dev console.
  * Command: `boolProp list` returns available balance.boolProps
  * `boolProp <name>` returns the current value.
  * `boolProp <name> <true or false>` sets the value.
* The new boolProps are:
  * showAllDoodads: enable Hidden doodads on the palette UI (NOTE:
    reload the editor to take effect)
  * writeLockOverride: edit files that are write locked anyway
  * prettyJSON: pretty-format the JSON files saved by the game.
2019-07-06 23:28:11 -07:00

61 lines
1.3 KiB
Go

package balance
import (
"errors"
"fmt"
"sort"
"strings"
)
// Fun bool props to wreak havoc in the game.
var (
// Force show hidden doodads in the palette in Editor Mode.
ShowHiddenDoodads bool
// Force ability to edit Locked levels and doodads.
WriteLockOverride bool
// Pretty-print JSON files when writing.
JSONIndent bool
)
// Human friendly names for the boolProps. Not necessarily the long descriptive
// variable names above.
var props = map[string]*bool{
"showAllDoodads": &ShowHiddenDoodads,
"writeLockOverride": &WriteLockOverride,
"prettyJSON": &JSONIndent,
// WARNING: SLOW!
"disableChunkTextureCache": &DisableChunkTextureCache,
}
// GetBoolProp reads the current value of a boolProp.
// Special value "list" will error out with a list of available props.
func GetBoolProp(name string) (bool, error) {
if name == "list" {
var keys []string
for k := range props {
keys = append(keys, k)
}
sort.Strings(keys)
return false, fmt.Errorf(
"Boolprops: %s",
strings.Join(keys, ", "),
)
}
if prop, ok := props[name]; ok {
return *prop, nil
}
return false, errors.New("no such boolProp")
}
// BoolProp allows easily setting a boolProp by name.
func BoolProp(name string, v bool) error {
if prop, ok := props[name]; ok {
*prop = v
return nil
}
return errors.New("no such boolProp")
}