doodle/pkg/balance/debug.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

116 lines
3.0 KiB
Go

package balance
import (
"os"
"strconv"
"strings"
"git.kirsle.net/apps/doodle/lib/render"
)
// Debug related variables that can toggle on or off certain features and
// overlays within the game.
var (
/***************
* Visualizers *
***************/
// Debug overlay (FPS etc.) settings.
DebugFontFilename = "DejaVuSans-Bold.ttf"
DebugFontSize = 16
DebugLabelColor = render.MustHexColor("#FF9900")
DebugValueColor = render.MustHexColor("#00CCFF")
DebugStrokeDarken = 80
// Background color to use when exporting a drawing Chunk as a bitmap image
// on disk. Default is white. Setting this to translucent yellow is a great
// way to visualize the chunks loaded from cache on your screen.
DebugChunkBitmapBackground = render.White // XXX: export $DEBUG_CHUNK_COLOR
// Put a border around all Canvas widgets.
DebugCanvasBorder = render.Invisible
DebugCanvasLabel = false // Tag the canvas with a label.
// Set to a color other than Invisible to force the uix.Canvas to color ALL
// Stroke pixels in this color.
DebugCanvasStrokeColor = render.Invisible
)
func init() {
// Load values from environment variables.
var config = map[string]interface{}{
// Window size.
"DOODLE_W": &Width,
"DOODLE_H": &Height,
// Tune some parameters. XXX: maybe dangerous at some point.
"D_SCROLL_SPEED": &CanvasScrollSpeed,
"D_DOODAD_SIZE": &DoodadSize,
// Shell settings.
"D_SHELL_BG": &ShellBackgroundColor,
"D_SHELL_FG": &ShellForegroundColor,
"D_SHELL_PC": &ShellPromptColor,
"D_SHELL_LN": &ShellHistoryLineCount,
"D_SHELL_FS": &ShellFontSize,
// Visualizers
"DEBUG_CHUNK_COLOR": &DebugChunkBitmapBackground,
"DEBUG_CANVAS_BORDER": &DebugCanvasBorder,
"DEBUG_CANVAS_LABEL": &DebugCanvasLabel,
}
for name, value := range config {
switch v := value.(type) {
case *int:
*v = IntEnv(name, *(v))
case *bool:
*v = BoolEnv(name, *(v))
case *int32:
*v = int32(IntEnv(name, int(*(v))))
case *render.Color:
*v = ColorEnv(name, *(v))
}
}
// Debug all?
if BoolEnv("DOODLE_DEBUG_ALL", false) {
DebugChunkBitmapBackground = render.RGBA(255, 255, 0, 128)
DebugCanvasBorder = render.Red
DebugCanvasLabel = true
}
}
// ColorEnv gets a color value from environment variable or returns a default.
// This will panic if the color is not valid, so only do this on startup time.
func ColorEnv(name string, v render.Color) render.Color {
if color := os.Getenv(name); color != "" {
return render.MustHexColor(color)
}
return v
}
// IntEnv gets an int value from environment variable or returns a default.
func IntEnv(name string, v int) int {
if env := os.Getenv(name); env != "" {
a, err := strconv.Atoi(env)
if err != nil {
panic(err)
}
return a
}
return v
}
// BoolEnv gets a bool from the environment with a default.
func BoolEnv(name string, v bool) bool {
if env := os.Getenv(name); env != "" {
switch strings.ToLower(env) {
case "true", "t", "1", "on", "yes", "y":
return true
case "false", "f", "0", "off", "no", "n":
return false
}
}
return v
}