balance

package
v0.0.0-...-79996cc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

README

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):
    • DOODLE_DEBUG_ALL=false: turn on all debug colors and hitboxes to their default colors and settings.
    • 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.
    • DEBUG_CANVAS_LABEL=false: draw a label in the corner of every Canvas with details about the Canvas.
  • 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.

Development booleans for unit tests (set to any non-empty value):

  • T_WALLPAPER_PNG for pkg/wallpaper to output PNG images.

Documentation

Index

Constants

View Source
const (
	// Enable "v1.5" compression in the MapAccessor Chunker.
	//
	// The original MapAccessor encodes a chunk to json using syntax like
	// {"x,y": index} mapping coordinates to palette swatches.
	//
	// With compression on, it is encoded to a byte stream of x,y,index
	// triplets. The game can read both formats and will follow this flag
	// on all saves. NOTE: this applies to when we still use JSON format.
	// If BinaryChunkerEnabled, map accessors are always compressed as they
	// are written to .bin files instead of .json.
	CompressMapAccessor = true

	// Enable "v2" binary storage of Chunk data in Zipfiles.
	//
	// This is a separate toggle to the CompressMapAccessor. Some possible
	// variations of these flags includes:
	//
	// - CompressMapAccessor=true alone, will write the compressed bytes
	//   still wrapped in the JSON format as a Base64 encoded string.
	// - With BinaryChunkerEnabled=true: all chunks are encoded to
	//   binary and put in the zip as .bin instead of as .json files.
	//   MapAccessor is always compressed in binary mode.
	//
	// If you set both flags to false, level zipfiles will use the classic
	// json chunk format as before on save.
	BinaryChunkerEnabled = true
)

Hard-coded feature flags.

View Source
const (
	// Main UI fonts (sans-serif and monospace)
	SansSerifFont = "DejaVuSans.ttf"
	MonospaceFont = "DejaVuSansMono.ttf"
	SansBoldFont  = "DejaVuSans-Bold.ttf"
)

Font filenames used as part of game configuration.

View Source
const (
	Linux   platform = "linux"
	Windows platform = "windows"
	Darwin  platform = "darwin"
	Web     platform = "web"
)

Runtime.Platform constants.

View Source
const FreeVersion = false

FreeVersion is true in the free version of the game.

Variables

View Source
var (
	CheatUncapFPS         = "unleash the beast"
	CheatEditDuringPlay   = "don't edit and drive"
	CheatScrollDuringPlay = "scroll scroll scroll your boat"
	CheatAntigravity      = "import antigravity"
	CheatNoclip           = "ghost mode"
	CheatShowAllActors    = "show all actors"
	CheatGiveKeys         = "give all keys"
	CheatGiveGems         = "give all gems"
	CheatDropItems        = "drop all items"
	CheatPlayAsBird       = "fly like a bird"
	CheatGodMode          = "god mode"
	CheatDebugLoadScreen  = "test load screen"
	CheatDebugWaitScreen  = "test wait screen"
	CheatUnlockLevels     = "master key"
	CheatSkipLevel        = "warp whistle"
	CheatFreeEnergy       = "tesla"
)

The game's cheat codes

View Source
var (

	// Debug overlay (FPS etc.) settings.
	DebugFontFilename = SansBoldFont
	DebugFontSize     = 14
	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.Invisible // 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
)

Debug related variables that can toggle on or off certain features and overlays within the game.

View Source
var (
	// Window dimensions.
	Width  = 1024
	Height = 768

	// Title screen height needed for the main menu. Phones in landscape
	// mode will switch to the horizontal layout if less than this height.
	TitleScreenResponsiveHeight = 600

	// Speed to scroll a canvas with arrow keys in Edit Mode.
	CanvasScrollSpeed         = 8
	FollowActorMaxScrollSpeed = 64

	// Window scrolling behavior in Play Mode.
	ScrollboxOffset = render.Point{
		X: 60,
		Y: 60,
	}

	// Player speeds
	PlayerMaxVelocity    float64 = 7
	PlayerJumpVelocity   float64 = -23
	PlayerAcceleration   float64 = 0.04 // 0.12
	PlayerFriction       float64 = 0.1
	SlipperyAcceleration float64 = 0.02
	SlipperyFriction     float64 = 0.02
	Gravity              float64 = 7
	GravityAcceleration  float64 = 0.1
	SwimGravity          float64 = 3
	SwimJumpVelocity     float64 = -12
	SwimJumpCooldown     uint64  = 24 // number of frames of cooldown between swim-jumps
	SlopeMaxHeight               = 8  // max pixel height for player to walk up a slope

	// Number of game ticks to insist the canvas follows the player at the start
	// of a level - to overcome Anvils settling into their starting positions so
	// they don't steal the camera focus straight away.
	FollowPlayerFirstTicks uint64 = 20

	// Default chunk size for canvases.
	ChunkSize uint8 = 128

	// Default size for a new Doodad.
	DoodadSize = 100

	// Size of Undo/Redo history for map editor.
	UndoHistory = 20

	// Options for brush size.
	BrushSizeOptions = []int{
		0,
		1,
		2,
		4,
		8,
		16,
		24,
		32,
		48,
		64,
	}
	DefaultEraserBrushSize = 8
	MaxEraserBrushSize     = 32 // the bigger, the slower

	// Default font filename selected for Text Tool in the editor.
	// TODO: better centralize font filenames, here and in theme.go
	TextToolDefaultFont = SansSerifFont

	// Interval for auto-save in the editor
	AutoSaveInterval = 5 * time.Minute

	// Default player character doodad in Play Mode.
	PlayerCharacterDoodad = "boy.doodad"

	// Levelpack and level names for the title screen.
	DemoLevelPack = "assets/levelpacks/builtin-Tutorial.levelpack"
	DemoLevelName = []string{
		"Tutorial 1.level",
		"Tutorial 2.level",
		"Tutorial 3.level",
		"Tutorial 5.level",
	}

	// Level attachment filename for the custom wallpaper.
	// NOTE: due to hard-coded "assets/wallpapers/" prefix in uix/canvas.go#LoadLevel.
	CustomWallpaperFilename  = "custom.b64img"
	CustomWallpaperEmbedPath = "assets/wallpapers/custom.b64img"

	// Publishing: Doodads-embedded-within-levels.
	EmbeddedDoodadsBasePath   = "assets/doodads/"
	EmbeddedWallpaperBasePath = "assets/wallpapers/"

	// File formats: save new levels and doodads gzip compressed
	DrawingFormat = FormatZipfile

	// Zipfile drawings: max size of the LRU cache for loading chunks from
	// a zip file. Normally the chunker discards chunks not loaded in a
	// recent tick, but when iterating the full level this limits the max
	// size of loaded chunks before some will be freed to make room.
	// 0 = do not cap the cache.
	ChunkerLRUCacheMax = 0

	// Play Mode Touchscreen controls.
	PlayModeIdleTimeout = 2200 * time.Millisecond
	PlayModeAlphaStep   = 8 // 0-255 alpha, steps per tick for fade in
	PlayModeAlphaMax    = 220

	// Invulnerability time in seconds at respawn from checkpoint, in case
	// enemies are spawn camping.
	RespawnGodModeTimer = 3 * time.Second

	// GameController thresholds.
	GameControllerMouseMoveMax float64 = 20  // Max pixels per tick to simulate mouse movement.
	GameControllerScrollMin    float64 = 0.3 // Minimum threshold for a right-stick scroll event.

	// Limits on the Flood Fill tool so it doesn't run away on us.
	FloodToolVoidLimit = 600  // If clicking the void, +- 1000 px limit
	FloodToolLimit     = 1200 // If clicking a valid color on the level

	// Eager render level chunks to images during the load screen.
	// Originally chunks rendered to image and SDL texture on-demand, the loadscreen was
	// added to eager load (to image) the whole entire level at once (SDL textures were
	// still on demand, as they scroll into screen). Control this in-game with
	// `boolProp eager-render false` and the loadscreen will go quicker cuz it won't
	// load the whole entire level. Maybe useful to explore memory issues.
	EagerRenderLevelChunks = true

	// Number of chunks margin outside the Canvas Viewport for the LoadingViewport.
	LoadingViewportMarginChunks              = render.NewPoint(10, 8) // hoz, vert
	CanvasLoadUnloadModuloTicks       uint64 = 4
	CanvasChunkFreeChoppingBlockTicks uint64 = 128 // number of ticks old a chunk is to free it

	// For bounded levels, the game will try and keep actors inside the boundaries. But
	// in case e.g. the player is teleported far out of the boundaries (going thru a warp
	// door into an interior room "off the map"), allow them to be out of bounds. This
	// variable is the tolerance offset - if they are only this far out of bounds, put them
	// back in bounds but further out and they're OK.
	OutOfBoundsMargin = 40
)

Numbers.

View Source
var (
	// Number of Doodads per row in the palette.
	UIDoodadsPerRow = 2

	// Size of the DoodadButtons on actor canvas mouseover.
	UICanvasDoodadButtonSize = 16

	// Threshold for "very small doodad" where the buttons take up too big a proportion
	// and the doodad can't drag/drop easily.. tiny doodads will show the DoodadButtons
	// 50% off the top/right edge.
	UICanvasDoodadButtonSpaceNeeded = 20
)

Edit Mode Values

View Source
var (
	Runtime rtc

	GuidebookPath = "./guidebook/index.html"
)

Runtime environment settings.

View Source
var (
	ShellFontFilename            = MonospaceFont
	ShellBackgroundColor         = render.RGBA(0, 20, 40, 200)
	ShellForegroundColor         = render.RGBA(0, 153, 255, 255)
	ShellPromptColor             = render.White
	ShellPadding                 = 8
	ShellFontSize                = 16
	ShellFontSizeSmall           = 10
	ShellCursorBlinkRate  uint64 = 20
	ShellHistoryLineCount        = 8

	// Ticks that a flashed message persists for.
	FlashTTL uint64 = 400
)

Shell related variables.

View Source
var (
	// Sprite filenames.
	WindowIcon = "assets/icons/96.png"
	GoldCoin   = "assets/sprites/gold.png"
	SilverCoin = "assets/sprites/silver.png"
	LockIcon   = "assets/sprites/padlock.png"
	GearIcon   = "assets/sprites/gear.png"

	// Cursors
	CursorIcon  = "assets/sprites/pointer.png"
	PencilIcon  = "assets/sprites/pencil.png"
	FloodCursor = "assets/sprites/flood-cursor.png"

	// Pixel attributes
	AttrSolid     = "assets/sprites/attr-solid.png"
	AttrFire      = "assets/sprites/attr-fire.png"
	AttrWater     = "assets/sprites/attr-water.png"
	AttrSemiSolid = "assets/sprites/attr-semisolid.png"
	AttrSlippery  = "assets/sprites/attr-slippery.png"

	// Title Screen Font
	TitleScreenFont = render.Text{
		Size:   46,
		Color:  render.Pink,
		Stroke: render.SkyBlue,
		Shadow: render.Black,
	}
	TitleScreenSubtitleFont = render.Text{
		FontFilename: SansSerifFont,
		Size:         18,
		Color:        render.SkyBlue,
		Shadow:       render.SkyBlue.Darken(128),
	}
	TitleScreenVersionFont = render.Text{
		Size:   14,
		Color:  render.Grey,
		Shadow: render.Black,
	}

	// Loading Screen fonts.
	LoadScreenFont = render.Text{
		Size:   46,
		Color:  render.Pink,
		Stroke: render.SkyBlue,
		Shadow: render.Black,
	}
	LoadScreenSecondaryFont = render.Text{
		FontFilename: SansSerifFont,
		Size:         18,
		Color:        render.SkyBlue,
		Shadow:       render.SkyBlue.Darken(128),
	}

	// Play Mode Touch UI Hints Font
	TouchHintsFont = render.Text{
		FontFilename: SansSerifFont,
		Size:         14,
		Color:        render.SkyBlue,
		Shadow:       render.SkyBlue.Darken(128),
		Padding:      8,
		PadY:         12,
	}

	// Window and panel styles.
	TitleConfig = ui.Config{
		Background:   render.MustHexColor("#FF9900"),
		OutlineSize:  1,
		OutlineColor: render.Black,
	}
	TitleFont = render.Text{
		FontFilename: SansBoldFont,
		Size:         9,
		Padding:      4,
		Color:        render.White,
		Stroke:       render.Red,
	}
	WindowBackground = render.MustHexColor("#cdb689")
	WindowBorder     = render.Grey

	// Developer Shell and Flashed Messages styles.
	FlashStrokeDarken = 60
	FlashShadowDarken = 120
	FlashFont         = func(text string) render.Text {
		return render.Text{
			Text:   text,
			Size:   18,
			Color:  render.SkyBlue,
			Stroke: render.SkyBlue.Darken(FlashStrokeDarken),
			Shadow: render.SkyBlue.Darken(FlashShadowDarken),
		}
	}
	FlashErrorColor = render.MustHexColor("#FF9900")

	// Menu bar styles.
	MenuBackground = render.Black
	MenuFont       = render.Text{
		Size: 12,
		PadX: 4,
	}
	MenuFontBold = render.Text{
		FontFilename: SansBoldFont,
		Size:         12,
		PadX:         4,
	}

	// TabFrame styles.
	TabFont = render.Text{
		Size: 12,
		PadX: 8,
		PadY: 4,
	}

	// Modal backdrop color.
	ModalBackdrop = render.RGBA(1, 1, 1, 42)

	// StatusFont is the font for the status bar.
	StatusFont = render.Text{
		Size:    12,
		Padding: 4,
		Color:   render.Black,
	}

	// UIFont is the main font for UI labels.
	UIFont = render.Text{
		Size:    12,
		Padding: 4,
		Color:   render.Black,
	}

	// LabelFont is the font for strong labels in UI.
	LabelFont = render.Text{
		Size:         12,
		FontFilename: SansBoldFont,
		Padding:      4,
		Color:        render.Black,
	}

	// A New Record! Label (Gold/Perfect and Silver/Normal)
	NewRecordPerfectFont = LabelFont.Update(render.Text{
		Color:  render.Yellow,
		Stroke: render.Orange,
	})
	NewRecordFont = LabelFont.Update(render.Text{
		Color:  render.White,
		Stroke: render.Grey,
	})

	LargeLabelFont = render.Text{
		Size:         18,
		FontFilename: SansBoldFont,
		Padding:      4,
		Color:        render.Black,
	}

	// SmallMonoFont for cramped spaces like the +/- buttons on Toolbar.
	SmallMonoFont = render.Text{
		Size:         14,
		PadX:         3,
		FontFilename: MonospaceFont,
		Color:        render.Black,
	}

	// CodeLiteralFont for rendering <code>-like text.
	CodeLiteralFont = render.Text{
		Size:         11,
		PadX:         3,
		FontFilename: MonospaceFont,
		Color:        render.Magenta,
	}

	// ExceptionFont for showing JavaScript errors to the user.
	ExceptionFont = render.Text{
		Size:         12,
		PadX:         3,
		FontFilename: MonospaceFont,
		Color:        render.Black,
	}

	// Small font
	SmallFont = render.Text{
		Size:    10,
		Padding: 2,
		Color:   render.Black,
	}

	// Color for draggable doodad.
	DragColor = render.MustHexColor("#0099FF")

	// Link lines drawn between connected doodads.
	LinkLineColor        = render.Magenta
	LinkLighten          = 128
	LinkAnimSpeed uint64 = 30 // ticks

	PlayButtonFont = render.Text{
		FontFilename: SansBoldFont,
		Size:         16,
		Padding:      4,
		Color:        render.RGBA(255, 255, 0, 255),
		Stroke:       render.RGBA(100, 100, 0, 255),
	}

	// In-game level timer font.
	TimerFont = render.Text{
		FontFilename: MonospaceFont,
		Size:         16,
		Color:        render.Cyan,
		Stroke:       render.DarkCyan,
	}

	// Doodad Dropper Window settings.
	DoodadButtonBackground = render.RGBA(255, 255, 200, 255)
	DoodadButtonSize       = 64
	DoodadDropperCols      = 6 // rows/columns of buttons
	DoodadDropperRows      = 3

	// CheatsMenu window settings.
	CheatsMenuBackground = render.RGBA(0, 153, 153, 255)

	// Button styles, customized in init().
	ButtonPrimary  = style.DefaultButton
	ButtonDanger   = style.DefaultButton
	ButtonBabyBlue = style.DefaultButton
	ButtonPink     = style.DefaultButton
	ButtonLightRed = style.DefaultButton

	DefaultCrosshairColor = render.RGBA(0, 153, 255, 255)

	// Default built-in wallpapers.
	Wallpapers = []magicform.Option{
		{
			Label: "Notebook",
			Value: "notebook.png",
		},
		{
			Label: "Legal Pad",
			Value: "legal.png",
		},
		{
			Label: "Graph paper",
			Value: "graph.png",
		},
		{
			Label: "Dotted paper",
			Value: "dots.png",
		},
		{
			Label: "Dotted paper (dark)",
			Value: "dots-dark.png",
		},
		{
			Label: "Blueprint",
			Value: "blueprint.png",
		},
		{
			Label: "Red parchment",
			Value: "red-parchment.png",
		},
		{
			Label: "Green parchment",
			Value: "green-parchment.png",
		},
		{
			Label: "Blue parchment",
			Value: "blue-parchment.png",
		},
		{
			Label: "Yellow parchment",
			Value: "yellow-parchment.png",
		},
		{
			Label: "White parchment",
			Value: "white-parchment.png",
		},
		{
			Label: "Pure white",
			Value: "white.png",
		},
		{
			Label: "Atmosphere",
			Value: "atmosphere.png",
		},
		{
			Separator: true,
		},
		{
			Label: "Custom wallpaper...",
			Value: CustomWallpaperFilename,
		},
	}
)

Theme and appearance variables.

View Source
var Boolprops = map[string]Boolprop{
	"show-hidden-doodads": {
		Get: func() bool { return usercfg.Current.ShowHiddenDoodads },
		Set: func(v bool) { usercfg.Current.ShowHiddenDoodads = v },
	},
	"write-lock-override": {
		Get: func() bool { return usercfg.Current.WriteLockOverride },
		Set: func(v bool) { usercfg.Current.WriteLockOverride = v },
	},
	"pretty-json": {
		Get: func() bool { return usercfg.Current.JSONIndent },
		Set: func(v bool) { usercfg.Current.JSONIndent = v },
	},
	"horizontal-toolbars": {
		Get: func() bool { return usercfg.Current.HorizontalToolbars },
		Set: func(v bool) { usercfg.Current.HorizontalToolbars = v },
	},
	"eager-render": {
		Get: func() bool { return EagerRenderLevelChunks },
		Set: func(v bool) { EagerRenderLevelChunks = v },
	},
}

Boolprops are the map of available boolprops, shown in the dev console when you type: "boolProp list"

View Source
var CheatActors = map[string]string{
	"pinocchio":       PlayerCharacterDoodad,
	"the cell":        "azu-blu",
	"super azulian":   "azu-red",
	"hyper azulian":   "azu-white",
	"fly like a bird": "bird-red",
	"bluebird":        "bird-blue",
	"megaton weight":  "anvil",
	"play as thief":   "thief",
}

Actor replacement cheats

View Source
var (
	CheatEnabledUnlockLevels bool
)

Global cheat boolean states.

View Source
var CheatMenuActors = []magicform.Option{
	{
		Value: "",
		Label: "Play as . . .",
	},
	{
		Value: "boy.doodad",
		Label: "Boy",
	},
	{
		Value: "thief.doodad",
		Label: "Thief",
	},
	{
		Value: "azu-blu.doodad",
		Label: "Azulian",
	},
	{
		Value: "bird-red.doodad",
		Label: "Bird",
	},
	{
		Value: "crusher.doodad",
		Label: "Crusher",
	},
	{
		Value: "snake.doodad",
		Label: "Snake",
	},
	{
		Value: "anvil.doodad",
		Label: "Anvil",
	},
}

Options for the "Play as:" drop-down in the Cheat Menu window.

View Source
var (
	// Disable chunk texture caching (SLOW!)
	DisableChunkTextureCache = false
)
View Source
var Feature = feature{

	ViewportWindow: false,

	CustomWallpaper: true,

	EmbeddableDoodads: true,

	Zoom: true,

	ChangePalette: true,

	LoadUnloadChunk: true,
}

Feature Flags to turn on/off experimental content.

Functions

func BoolEnv

func BoolEnv(name string, v bool) bool

BoolEnv gets a bool from the environment with a default.

func BoolProp

func BoolProp(name string, v bool) error

BoolProp allows easily setting a boolProp by name.

func ColorEnv

func ColorEnv(name string, v render.Color) render.Color

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 FeaturesOn

func FeaturesOn()

FeaturesOn turns on all feature flags, from CLI --experimental option.

func GetBoolProp

func GetBoolProp(name string) (bool, error)

GetBoolProp reads the current value of a boolProp. Special value "list" will error out with a list of available props.

func IntEnv

func IntEnv(name string, v int) int

IntEnv gets an int value from environment variable or returns a default.

func IsPlayerCharacterDefault

func IsPlayerCharacterDefault() bool

IsPlayerCharacterDefault returns whether the balance.PlayerCharacterDoodad has been modified at runtime away from its built-in default. This is a cheat detection method: high scores could be tainted if you `fly like a bird` right to the exit in a couple of seconds.

Types

type Boolprop

type Boolprop struct {
	Name string
	Get  func() bool
	Set  func(bool)
}

Boolprop is a boolean setting that can be toggled in the game using the developer console. Many of these consist of usercfg settings that are not exposed to the Settings UI window, and secret testing functions. Where one points to usercfg, check usercfg.Settings for documentation about what that boolean does.

type Format

type Format int

Format for level and doodad files.

const (
	FormatJSON    Format = iota // v0: plain json files
	FormatGZip                  // v1: gzip compressed json files
	FormatZipfile               // v2: zip archive with external chunks
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL