Noah Petherbridge
fd649b7ab1
* 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.
84 lines
1.8 KiB
Go
84 lines
1.8 KiB
Go
package level
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.kirsle.net/apps/doodle/lib/render"
|
|
)
|
|
|
|
// Swatch holds details about a single value in the palette.
|
|
type Swatch struct {
|
|
Name string `json:"name"`
|
|
Color render.Color `json:"color"`
|
|
|
|
// Optional attributes.
|
|
Solid bool `json:"solid,omitempty"`
|
|
Fire bool `json:"fire,omitempty"`
|
|
Water bool `json:"water,omitempty"`
|
|
|
|
// Private runtime attributes.
|
|
index int // position in the Palette, for reverse of `Palette.byName`
|
|
|
|
// When the swatch is loaded from JSON we only get the index number, and
|
|
// need to expand out the swatch later when the palette is loaded.
|
|
paletteIndex int
|
|
isSparse bool
|
|
}
|
|
|
|
// NewSparseSwatch creates a sparse Swatch from a palette index that will need
|
|
// later expansion, when loading drawings from disk.
|
|
func NewSparseSwatch(paletteIndex int) *Swatch {
|
|
return &Swatch{
|
|
isSparse: true,
|
|
paletteIndex: paletteIndex,
|
|
}
|
|
}
|
|
|
|
func (s Swatch) String() string {
|
|
if s.isSparse {
|
|
return fmt.Sprintf("Swatch<sparse:%d>", s.paletteIndex)
|
|
}
|
|
if s.Name == "" {
|
|
return s.Color.String()
|
|
}
|
|
return s.Name
|
|
}
|
|
|
|
// Attributes returns a comma-separated list of attributes as a string on
|
|
// this swatch. This is for debugging and the `doodad show` CLI command to
|
|
// summarize the swatch and shouldn't be used for game logic.
|
|
func (s *Swatch) Attributes() string {
|
|
var result string
|
|
|
|
if s.Solid {
|
|
result += "solid,"
|
|
}
|
|
if s.Fire {
|
|
result += "fire,"
|
|
}
|
|
if s.Water {
|
|
result += "water,"
|
|
}
|
|
if s.isSparse {
|
|
result += "sparse,"
|
|
}
|
|
|
|
if result == "" {
|
|
result = "none,"
|
|
}
|
|
|
|
return strings.TrimSuffix(result, ",")
|
|
}
|
|
|
|
// IsSparse returns whether this Swatch is sparse (has only a palette index) and
|
|
// requires inflation.
|
|
func (s *Swatch) IsSparse() bool {
|
|
return s.isSparse
|
|
}
|
|
|
|
// Index returns the Swatch's position in the palette.
|
|
func (s *Swatch) Index() int {
|
|
return s.index
|
|
}
|