From 693664db6cc0fde38e88888739c54a16f78b508d Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Fri, 19 Apr 2019 17:23:37 -0700 Subject: [PATCH] Shareware Build Flags * Build the app with -tags="shareware" to compile the free/shareware build of the game. * `make build-free` compiles both binaries to the bin/ folder in shareware mode. * The constant balance.FreeVersion is true in the shareware build and all functionality related to the Doodad Editor UI mode is disabled in this build mode. --- Makefile | 7 +++++++ cmd/doodad/main.go | 10 +++++++++- cmd/doodle/main.go | 9 ++++++++- docs/Release Modes.md | 29 +++++++++++++++++++++++++++++ pkg/balance/flag_free.go | 6 ++++++ pkg/balance/flag_paid.go | 6 ++++++ pkg/commands.go | 17 ++++++++++++++--- pkg/config.go | 4 +--- pkg/doodle.go | 8 ++++++++ pkg/editor_ui.go | 8 +++++++- 10 files changed, 95 insertions(+), 9 deletions(-) create mode 100644 docs/Release Modes.md create mode 100644 pkg/balance/flag_free.go create mode 100644 pkg/balance/flag_paid.go diff --git a/Makefile b/Makefile index e3069a7..ffaf01e 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,13 @@ build: go build $(LDFLAGS) -i -o bin/doodle cmd/doodle/main.go go build $(LDFLAGS) -i -o bin/doodad cmd/doodad/main.go +# `make build-free` to build the binary in free mode. +.PHONY: build-free +build-free: + gofmt -w . + go build $(LDFLAGS) -tags="shareware" -i -o bin/doodle cmd/doodle/main.go + go build $(LDFLAGS) -tags="shareware" -i -o bin/doodad cmd/doodad/main.go + # `make mingw` to cross-compile a Windows binary with mingw. .PHONY: mingw mingw: diff --git a/cmd/doodad/main.go b/cmd/doodad/main.go index 4c6ab2b..f05be02 100644 --- a/cmd/doodad/main.go +++ b/cmd/doodad/main.go @@ -10,6 +10,7 @@ import ( "git.kirsle.net/apps/doodle/cmd/doodad/commands" doodle "git.kirsle.net/apps/doodle/pkg" + "git.kirsle.net/apps/doodle/pkg/balance" "github.com/urfave/cli" ) @@ -29,9 +30,16 @@ func main() { app := cli.NewApp() app.Name = "doodad" app.Usage = "command line interface for Doodle" - app.Version = fmt.Sprintf("%s build %s. Built on %s", + + var freeLabel string + if balance.FreeVersion { + freeLabel = " (shareware)" + } + + app.Version = fmt.Sprintf("%s build %s%s. Built on %s", doodle.Version, Build, + freeLabel, BuildDate, ) diff --git a/cmd/doodle/main.go b/cmd/doodle/main.go index d9fe3e2..a074b92 100644 --- a/cmd/doodle/main.go +++ b/cmd/doodle/main.go @@ -34,9 +34,16 @@ func main() { app := cli.NewApp() app.Name = "doodle" app.Usage = "command line interface for Doodle" - app.Version = fmt.Sprintf("%s build %s. Built on %s", + + var freeLabel string + if balance.FreeVersion { + freeLabel = " (shareware)" + } + + app.Version = fmt.Sprintf("%s build %s%s. Built on %s", doodle.Version, Build, + freeLabel, BuildDate, ) diff --git a/docs/Release Modes.md b/docs/Release Modes.md new file mode 100644 index 0000000..ec91552 --- /dev/null +++ b/docs/Release Modes.md @@ -0,0 +1,29 @@ +# Release Modes + +Verifying your release mode: + +```bash +# Full release version +$ doodle -version +doodle version 0.0.7 build 52a2545. Built on 2019-04-19T17:16:19-07:00 + +# Shareware version includes the word "(shareware)" after the build number. +$ doodle -version +doodle version 0.0.7 build 52a2545 (shareware). Built on 2019-04-19T17:16:19-07:00 +``` + +## Shareware + +* `make build-free` to build the shareware binaries to the bin/ folder. + +The shareware (free) version of the game has the following restrictions: + +* No Doodad Editor Mode available. + * "New Doodad" button hidden from UI + * d.NewDoodad() function errors out + * The dev console `edit ` command won't edit a doodad. + +## Full Version + +The full release of the game has no restrictions and includes the Doodad Editor +Mode. diff --git a/pkg/balance/flag_free.go b/pkg/balance/flag_free.go new file mode 100644 index 0000000..af5c4f4 --- /dev/null +++ b/pkg/balance/flag_free.go @@ -0,0 +1,6 @@ +// +build shareware + +package balance + +// FreeVersion is true in the free version of the game. +const FreeVersion = true diff --git a/pkg/balance/flag_paid.go b/pkg/balance/flag_paid.go new file mode 100644 index 0000000..52a40aa --- /dev/null +++ b/pkg/balance/flag_paid.go @@ -0,0 +1,6 @@ +// +build !shareware + +package balance + +// FreeVersion is true in the free version of the game. +const FreeVersion = false diff --git a/pkg/commands.go b/pkg/commands.go index 11026bc..2e91f15 100644 --- a/pkg/commands.go +++ b/pkg/commands.go @@ -6,6 +6,7 @@ import ( "strconv" "git.kirsle.net/apps/doodle/pkg/enum" + "github.com/robertkrimen/otto" ) // Command is a parsed shell command. @@ -60,7 +61,7 @@ func (c Command) Run(d *Doodle) error { return nil case "eval": case "$": - out, err := d.shell.js.Run(c.ArgsLiteral) + out, err := c.RunScript(d, c.ArgsLiteral) d.Flash("%+v", out) return err case "repl": @@ -163,8 +164,7 @@ func (c Command) Edit(d *Doodle) error { filename := c.Args[0] d.shell.Write("Editing file: " + filename) - d.EditFile(filename) - return nil + return d.EditFile(filename) } // Play a map. @@ -220,6 +220,17 @@ func (c Command) BoolProp(d *Doodle) error { return nil } +// RunScript evaluates some JavaScript code safely. +func (c Command) RunScript(d *Doodle, code interface{}) (otto.Value, error) { + defer func() { + if err := recover(); err != nil { + d.Flash("Panic: %s", err) + } + }() + out, err := d.shell.js.Run(code) + return out, err +} + // Default command. func (c Command) Default() error { return fmt.Errorf("%s: command not found. Try `help` for help", diff --git a/pkg/config.go b/pkg/config.go index 8ddd8a8..83fd87c 100644 --- a/pkg/config.go +++ b/pkg/config.go @@ -48,7 +48,5 @@ func (d *Doodle) EditFile(filename string) error { } } - d.EditDrawing(absPath) - - return nil + return d.EditDrawing(absPath) } diff --git a/pkg/doodle.go b/pkg/doodle.go index 6f9bfc1..4cc24de 100644 --- a/pkg/doodle.go +++ b/pkg/doodle.go @@ -186,6 +186,11 @@ func (d *Doodle) NewMap() { // NewDoodad loads a new Doodad in Edit Mode. func (d *Doodle) NewDoodad(size int) { + if balance.FreeVersion { + d.Flash("Doodad editor is not available in your version of the game.") + return + } + log.Info("Starting a new doodad") scene := &EditorScene{ DrawingType: enum.DoodadDrawing, @@ -214,6 +219,9 @@ func (d *Doodle) EditDrawing(filename string) error { log.Info("is a Level type") scene.DrawingType = enum.LevelDrawing case "doodad": + if balance.FreeVersion { + return fmt.Errorf("Doodad editor not supported in your version of the game") + } scene.DrawingType = enum.DoodadDrawing default: return fmt.Errorf("file extension '%s' doesn't indicate its drawing type", ext) diff --git a/pkg/editor_ui.go b/pkg/editor_ui.go index 5cc0fc1..71e2d0d 100644 --- a/pkg/editor_ui.go +++ b/pkg/editor_ui.go @@ -399,7 +399,7 @@ func (u *EditorUI) SetupMenuBar(d *Doodle) *ui.Frame { d.Prompt("Open filename>", func(answer string) { if answer != "" { if err := d.EditFile(answer); err != nil { - d.Flash("File not found: %s", answer) + d.Flash(err.Error()) } } }) @@ -408,6 +408,12 @@ func (u *EditorUI) SetupMenuBar(d *Doodle) *ui.Frame { } for _, btn := range buttons { + if balance.FreeVersion { + if btn.Text == "New Doodad" { + continue + } + } + w := ui.NewButton(btn.Text, ui.NewLabel(ui.Label{ Text: btn.Text, Font: balance.MenuFont,