From dce32ea14b6b5cb148a79ae92e00dc7114a697a3 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Wed, 16 Jun 2021 22:35:01 -0700 Subject: [PATCH] Diverge Free vs. Paid Features * Free (shareware) versions of the game will not be able to Publish Levels (attach custom doodads to the level file) and they will not be able to load a level which relies on embedded doodads. * The UI for the Publish Level window is still available, but clicking on the confirm button will just open the Register (License) window. * When loading a level containing embedded doodads: if some can't load because they're embedded and you're using the free version of the game, the error message is customized to reflect that. --- go.mod | 9 +++++++++ go.sum | 1 + pkg/branding/branding.go | 2 +- pkg/doodads/fmt_readwrite.go | 4 ++++ pkg/editor_scene.go | 9 ++++++++- pkg/editor_ui.go | 18 ------------------ pkg/editor_ui_popups.go | 35 +++++++++++++++++++++++++++++++++++ pkg/license/license.go | 5 +++++ pkg/uix/canvas_actors.go | 3 ++- pkg/windows/license_key.go | 9 +++++---- 10 files changed, 70 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index c0863c5..4374146 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( git.kirsle.net/go/log v0.0.0-20200902035305-70ac2848949b git.kirsle.net/go/render v0.0.0-20210104010442-b4a1979a8ba1 git.kirsle.net/go/ui v0.0.0-20200710023146-e2a561fbd04c + github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect github.com/fsnotify/fsnotify v1.4.9 github.com/gen2brain/dlgs v0.0.0-20210406143744-f512297a108e github.com/google/uuid v1.1.2 @@ -24,5 +25,13 @@ require ( ) // replace git.kirsle.net/go/render => /home/kirsle/SketchyMaze/deps/render + // replace git.kirsle.net/go/ui => /home/kirsle/SketchyMaze/deps/ui + // replace git.kirsle.net/go/audio => /home/kirsle/SketchyMaze/deps/audio + +// replace git.kirsle.net/go/render => /run/build/doodle/deps/render + +// replace git.kirsle.net/go/ui => /run/build/doodle/deps/ui + +// replace git.kirsle.net/go/audio => /run/build/doodle/deps/audio diff --git a/go.sum b/go.sum index 6b18b7e..f52d35d 100644 --- a/go.sum +++ b/go.sum @@ -37,6 +37,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= diff --git a/pkg/branding/branding.go b/pkg/branding/branding.go index fea84c6..09dce04 100644 --- a/pkg/branding/branding.go +++ b/pkg/branding/branding.go @@ -4,7 +4,7 @@ package branding const ( AppName = "Sketchy Maze" Summary = "A drawing-based maze game" - Version = "0.6.1" + Version = "0.7.0" Website = "https://www.sketchymaze.com" Copyright = "2021 Noah Petherbridge" diff --git a/pkg/doodads/fmt_readwrite.go b/pkg/doodads/fmt_readwrite.go index ded12ee..7582278 100644 --- a/pkg/doodads/fmt_readwrite.go +++ b/pkg/doodads/fmt_readwrite.go @@ -13,6 +13,7 @@ import ( "git.kirsle.net/apps/doodle/pkg/branding" "git.kirsle.net/apps/doodle/pkg/enum" "git.kirsle.net/apps/doodle/pkg/filesystem" + "git.kirsle.net/apps/doodle/pkg/license" "git.kirsle.net/apps/doodle/pkg/log" "git.kirsle.net/apps/doodle/pkg/userdir" "git.kirsle.net/apps/doodle/pkg/wasm" @@ -118,6 +119,9 @@ func ListBuiltin() ([]string, error) { func LoadFromEmbeddable(filename string, fs filesystem.Embeddable) (*Doodad, error) { if bin, err := fs.GetFile(balance.EmbeddedDoodadsBasePath + filename); err == nil { log.Debug("doodads.LoadFromEmbeddable: found %s", filename) + if !license.IsRegistered() { + return nil, license.ErrRegisteredFeature + } return Deserialize(filename, bin) } return LoadFile(filename) diff --git a/pkg/editor_scene.go b/pkg/editor_scene.go index 3780f31..de691ca 100644 --- a/pkg/editor_scene.go +++ b/pkg/editor_scene.go @@ -12,6 +12,7 @@ import ( "git.kirsle.net/apps/doodle/pkg/enum" "git.kirsle.net/apps/doodle/pkg/keybind" "git.kirsle.net/apps/doodle/pkg/level" + "git.kirsle.net/apps/doodle/pkg/license" "git.kirsle.net/apps/doodle/pkg/log" "git.kirsle.net/apps/doodle/pkg/modal" "git.kirsle.net/apps/doodle/pkg/userdir" @@ -279,7 +280,13 @@ func (s *EditorScene) LoadLevel(filename string) error { log.Info("Installing %d actors into the drawing", len(level.Actors)) if err := s.UI.Canvas.InstallActors(level.Actors); err != nil { - modal.Alert("This level references some doodads that were not found:\n\n%s", err).WithTitle("Level Errors") + summary := "This level references some doodads that were not found:" + if strings.Contains(err.Error(), license.ErrRegisteredFeature.Error()) { + summary = "This level contains embedded doodads, but this is not\n" + + "available in the free version of the game. The following\n" + + "doodads could not be loaded:" + } + modal.Alert("%s\n\n%s", summary, err).WithTitle("Level Errors") return fmt.Errorf("EditorScene.LoadLevel: InstallActors: %s", err) } diff --git a/pkg/editor_ui.go b/pkg/editor_ui.go index 8894947..cf028be 100644 --- a/pkg/editor_ui.go +++ b/pkg/editor_ui.go @@ -689,24 +689,6 @@ func (u *EditorUI) SetupMenuBar(d *Doodle) *ui.MenuBar { native.OpenLocalURL(balance.GuidebookPath) }) helpMenu.AddItem("Register", func() { - if u.licenseWindow == nil { - cfg := windows.License{ - Supervisor: u.Supervisor, - Engine: d.Engine, - OnCancel: func() { - u.licenseWindow.Hide() - }, - } - cfg.OnLicensed = func() { - // License status has changed, reload the window! - if u.licenseWindow != nil { - u.licenseWindow.Hide() - } - u.licenseWindow = windows.MakeLicenseWindow(d.width, d.height, cfg) - } - - cfg.OnLicensed() - } u.licenseWindow.Show() }) helpMenu.AddItem("About", func() { diff --git a/pkg/editor_ui_popups.go b/pkg/editor_ui_popups.go index aad8889..0e18dc6 100644 --- a/pkg/editor_ui_popups.go +++ b/pkg/editor_ui_popups.go @@ -10,6 +10,7 @@ import ( "git.kirsle.net/apps/doodle/pkg/doodads" "git.kirsle.net/apps/doodle/pkg/level" "git.kirsle.net/apps/doodle/pkg/level/publishing" + "git.kirsle.net/apps/doodle/pkg/license" "git.kirsle.net/apps/doodle/pkg/log" "git.kirsle.net/apps/doodle/pkg/modal" "git.kirsle.net/apps/doodle/pkg/windows" @@ -82,6 +83,27 @@ func (u *EditorUI) SetupPopups(d *Doodle) { window.Hide() } + // License Registration Window. + if u.licenseWindow == nil { + cfg := windows.License{ + Supervisor: u.Supervisor, + Engine: d.Engine, + OnCancel: func() { + u.licenseWindow.Hide() + }, + } + cfg.OnLicensed = func() { + // License status has changed, reload the window! + if u.licenseWindow != nil { + u.licenseWindow.Hide() + } + u.licenseWindow = windows.MakeLicenseWindow(d.width, d.height, cfg) + } + + cfg.OnLicensed() + u.licenseWindow.Hide() + } + // Doodad Dropper. if u.doodadWindow == nil { u.doodadWindow = windows.NewDoodadDropper(windows.DoodadDropper{ @@ -128,6 +150,19 @@ func (u *EditorUI) SetupPopups(d *Doodle) { Level: scene.Level, OnPublish: func(includeBuiltins bool) { + // XXX: Paid Version Only. + if !license.IsRegistered() { + if u.licenseWindow != nil { + u.licenseWindow.Show() + u.Supervisor.FocusWindow(u.licenseWindow) + } + d.Flash("Level Publishing is only available in the full version of the game.") + // modal.Alert( + // "This feature is only available in the full version of the game.", + // ).WithTitle("Please register") + return + } + log.Debug("OnPublish: include builtins=%+v", includeBuiltins) cwd, _ := os.Getwd() d.Prompt(fmt.Sprintf("File name (relative to %s)> ", cwd), func(answer string) { diff --git a/pkg/license/license.go b/pkg/license/license.go index fc7a106..07aa746 100644 --- a/pkg/license/license.go +++ b/pkg/license/license.go @@ -13,6 +13,11 @@ import ( "github.com/dgrijalva/jwt-go" ) +// Errors +var ( + ErrRegisteredFeature = errors.New("feature not available") +) + // Registration object encoded into a license key file. type Registration struct { Name string `json:"name"` diff --git a/pkg/uix/canvas_actors.go b/pkg/uix/canvas_actors.go index 12c1d48..2c91aa3 100644 --- a/pkg/uix/canvas_actors.go +++ b/pkg/uix/canvas_actors.go @@ -2,6 +2,7 @@ package uix import ( "errors" + "fmt" "strings" "git.kirsle.net/apps/doodle/pkg/doodads" @@ -20,7 +21,7 @@ func (w *Canvas) InstallActors(actors level.ActorMap) error { for id, actor := range actors { doodad, err := doodads.LoadFromEmbeddable(actor.Filename, w.level) if err != nil { - errs = append(errs, err.Error()) + errs = append(errs, fmt.Sprintf("%s: %s", actor.Filename, err.Error())) continue } diff --git a/pkg/windows/license_key.go b/pkg/windows/license_key.go index a31c18c..31be71b 100644 --- a/pkg/windows/license_key.go +++ b/pkg/windows/license_key.go @@ -7,6 +7,7 @@ import ( "git.kirsle.net/apps/doodle/pkg/balance" "git.kirsle.net/apps/doodle/pkg/branding" "git.kirsle.net/apps/doodle/pkg/license" + "git.kirsle.net/apps/doodle/pkg/log" "git.kirsle.net/apps/doodle/pkg/modal" "git.kirsle.net/apps/doodle/pkg/native" "git.kirsle.net/go/render" @@ -66,7 +67,7 @@ func NewLicenseWindow(cfg License) *ui.Window { window.Configure(ui.Config{ Width: windowWidth, Height: windowHeight, - Background: render.RGBA(200, 200, 255, 255), + Background: render.RGBA(255, 200, 255, 255), }) var rows = []struct { @@ -127,21 +128,21 @@ func NewLicenseWindow(cfg License) *ui.Window { { IfUnregistered: true, Button: ui.NewButton("Key Browse", ui.NewLabel(ui.Label{ - Text: "Upload License Key File", + Text: "Browse for License Key", Font: balance.UIFont, })), ButtonStyle: &balance.ButtonPrimary, Func: func() { filename, err := native.OpenFile("Select License File", "*.key *.txt") if err != nil { - modal.Alert(err.Error()) + log.Error(err.Error()) return } // Upload and validate the license key. reg, err := license.UploadLicenseFile(filename) if err != nil { - modal.Alert(err.Error()) + modal.Alert("That license key didn't seem quite right.").WithTitle("License Error") return }