From 5f3719351258cd34b9fa8a8c093fb17c214b8730 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sat, 6 Jul 2019 23:28:11 -0700 Subject: [PATCH] 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 ` returns the current value. * `boolProp ` 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. --- functions.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/functions.go b/functions.go index b78a254..d049f5d 100644 --- a/functions.go +++ b/functions.go @@ -1,5 +1,36 @@ package render +import ( + "fmt" + "regexp" + "strconv" +) + +var regexpResolution = regexp.MustCompile(`^(\d+)x(\d+)$`) + +// ParseResolution turns a resolution string like "1024x768" and returns the +// width and height values. +func ParseResolution(resi string) (int, int, error) { + m := regexpResolution.FindStringSubmatch(resi) + if m == nil { + return 0, 0, fmt.Errorf("invalid resolution format, should be %s", + regexpResolution.String(), + ) + } + + width, err := strconv.Atoi(m[1]) + if err != nil { + return 0, 0, err + } + + height, err := strconv.Atoi(m[2]) + if err != nil { + return 0, 0, err + } + + return width, height, nil +} + // TrimBox helps with Engine.Copy() to trim a destination box so that it // won't overflow with the parent container. func TrimBox(src, dst *Rect, p Point, S Rect, thickness int32) {