doodle/balance/debug.go
Noah Petherbridge 20771fbe13 Draw Actors Embedded in Levels in Edit Mode
Add the JSON format for embedding Actors (Doodad instances) inside of a
Level. I made a test map that manually inserted a couple of actors.

Actors are given to the Canvas responsible for the Level via the
function `InstallActors()`. So it means you'll call LoadLevel and then
InstallActors to hook everything up.

The Canvas creates sub-Canvas widgets from each Actor.

After drawing the main level geometry from the Canvas.Chunker, it calls
the drawActors() function which does the same but for Actors.

Levels keep a global map of all Actors that exist. For any Actors that
are visible within the Viewport, their sub-Canvas widgets are presented
appropriately on top of the parent Canvas. In case their sub-Canvas
overlaps the parent's boundaries, their sub-Canvas is resized and moved
appropriately.

- Allow the MainWindow to be resized at run time, and the UI
  recalculates its sizing and position.
- Made the in-game Shell properties editable via environment variables.
  The kirsle.env file sets a blue and pink color scheme.
- Begin the ground work for Levels and Doodads to embed files inside
  their data via the level.FileSystem type.
- UI: Labels can now contain line break characters. It will
  appropriately render multiple lines of render.Text and take into
  account the proper BoxSize to contain them all.
- Add environment variable DOODLE_DEBUG_ALL=true that will turn on ALL
  debug overlay and visualization options.
- Add debug overlay to "tag" each Canvas widget with some of its
  details, like its Name and World Position. Can be enabled with the
  environment variable DEBUG_CANVAS_LABEL=true
- Improved the FPS debug overlay to show in labeled columns and multiple
  colors, with easy ability to add new data points to it.
2018-10-19 13:32:25 -07:00

112 lines
2.9 KiB
Go

package balance
import (
"os"
"strconv"
"strings"
"git.kirsle.net/apps/doodle/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 = "./fonts/DejaVuSans-Bold.ttf"
DebugFontSize = 15
DebugLabelColor = render.MustHexColor("#FF9900")
DebugValueColor = render.MustHexColor("#00CCFF")
DebugStrokeDarken int32 = 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.
)
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
}