Tune Some Constants via Environment Variables
Some of the constants in the `balance` package can be set at startup time via environment variables. With this, you can customize the color and style of the developer shell, turn on debugging visuals to outline Canvas widgets, and more. The parser is at `balance/debug.go` and human readable descriptions are in the `balance/README.md`
This commit is contained in:
parent
97394f6cdb
commit
1c5a0842e4
33
balance/README.md
Normal file
33
balance/README.md
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# balance
|
||||||
|
|
||||||
|
Constants and settings for the Doodle app.
|
||||||
|
|
||||||
|
## Environment Variables
|
||||||
|
|
||||||
|
Some runtime settings can be configured in the environment. Here they are
|
||||||
|
with their default values.
|
||||||
|
|
||||||
|
Most colors work with alpha channels; just provide an 8 hex character code,
|
||||||
|
like `#FF00FF99` for 153 ($99) on the alpha channel.
|
||||||
|
|
||||||
|
* Application Windw Size (ints):
|
||||||
|
* `DOODLE_W=1024`
|
||||||
|
* `DOODLE_H=768`
|
||||||
|
* Shell settings:
|
||||||
|
* `D_SHELL_BG=#001428C8`: shell background color.
|
||||||
|
* `D_SHELL_FG=#0099FF`: shell text color.
|
||||||
|
* `D_SHELL_PC=#FFFFFF`: shell prompt color.
|
||||||
|
* `D_SHELL_LN=8`: shell history line count (how tall the shell is in lines)
|
||||||
|
* `D_SHELL_FS=16`: font size for both the shell and on-screen flashed
|
||||||
|
messages.
|
||||||
|
* Debug Colors and Hitboxes (default invisible=off):
|
||||||
|
* `DEBUG_CHUNK_COLOR=#FFFFFF`: background color when caching a
|
||||||
|
chunk to bitmap. Helps visualize where the chunks and caching
|
||||||
|
are happening.
|
||||||
|
* `DEBUG_CANVAS_BORDER`: draw a border color around every uix.Canvas
|
||||||
|
widget. This effectively draws the bounds of every Doodad drawn on top
|
||||||
|
of a level or inside a button and the bounds of the level space itself.
|
||||||
|
* Tuning constants (may not be available in production builds):
|
||||||
|
* `D_SCROLL_SPEED=8`: Canvas scroll speed when using the keyboard arrows
|
||||||
|
in the Editor Mode, in pixels per tick.
|
||||||
|
* `D_DOODAD_SIZE=100`: Default size when creating a new Doodad.
|
|
@ -1,7 +1,9 @@
|
||||||
package balance
|
package balance
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"git.kirsle.net/apps/doodle/render"
|
"git.kirsle.net/apps/doodle/render"
|
||||||
)
|
)
|
||||||
|
@ -17,10 +19,63 @@ var (
|
||||||
// on disk. Default is white. Setting this to translucent yellow is a great
|
// on disk. Default is white. Setting this to translucent yellow is a great
|
||||||
// way to visualize the chunks loaded from cache on your screen.
|
// way to visualize the chunks loaded from cache on your screen.
|
||||||
DebugChunkBitmapBackground = render.White // XXX: export $DEBUG_CHUNK_COLOR
|
DebugChunkBitmapBackground = render.White // XXX: export $DEBUG_CHUNK_COLOR
|
||||||
|
|
||||||
|
// Put a border around all Canvas widgets.
|
||||||
|
DebugCanvasBorder = render.Red
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if color := os.Getenv("DEBUG_CHUNK_COLOR"); color != "" {
|
// Load values from environment variables.
|
||||||
DebugChunkBitmapBackground = render.MustHexColor(color)
|
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,
|
||||||
|
}
|
||||||
|
for name, value := range config {
|
||||||
|
switch v := value.(type) {
|
||||||
|
case *int:
|
||||||
|
*v = IntEnv(name, *(v))
|
||||||
|
case *int32:
|
||||||
|
*v = int32(IntEnv(name, int(*(v))))
|
||||||
|
case *render.Color:
|
||||||
|
*v = ColorEnv(name, *(v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 != "" {
|
||||||
|
fmt.Printf("set %s to %s\n", 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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user