diff --git a/cmd/doodad/commands/convert.go b/cmd/doodad/commands/convert.go index b2ad7cf..75873c4 100644 --- a/cmd/doodad/commands/convert.go +++ b/cmd/doodad/commands/convert.go @@ -155,7 +155,7 @@ func imageToDrawing(c *cli.Context, chroma render.Color, inputFiles []string, ou if doodad.Title == "" { doodad.Title = "Converted Doodad" } - doodad.Author = native.DefaultAuthor() + doodad.Author = native.DefaultAuthor // Write the first layer and gather its palette. log.Info("Converting first layer to drawing and getting the palette") @@ -195,7 +195,7 @@ func imageToDrawing(c *cli.Context, chroma render.Color, inputFiles []string, ou if lvl.Title == "" { lvl.Title = "Converted Level" } - lvl.Author = native.DefaultAuthor() + lvl.Author = native.DefaultAuthor palette, chunker := imageToChunker(images[0], chroma, nil, lvl.Chunker.Size) lvl.Palette = palette lvl.Chunker = chunker diff --git a/cmd/doodle/main.go b/cmd/doodle/main.go index c1b36c2..9f4082d 100644 --- a/cmd/doodle/main.go +++ b/cmd/doodle/main.go @@ -21,6 +21,7 @@ import ( "git.kirsle.net/SketchyMaze/doodle/pkg/log" "git.kirsle.net/SketchyMaze/doodle/pkg/native" "git.kirsle.net/SketchyMaze/doodle/pkg/plus/bootstrap" + "git.kirsle.net/SketchyMaze/doodle/pkg/plus/dpp" "git.kirsle.net/SketchyMaze/doodle/pkg/shmem" "git.kirsle.net/SketchyMaze/doodle/pkg/sound" "git.kirsle.net/SketchyMaze/doodle/pkg/sprites" @@ -118,6 +119,11 @@ func main() { app.Action = func(c *cli.Context) error { log.Info("Starting %s %s", app.Name, app.Version) + // Print registration information, + also this sets the DefaultAuthor field. + if reg, err := dpp.Driver.GetRegistration(); err == nil { + log.Info("Registered to %s", reg.Name) + } + // --chdir into a different working directory? e.g. for Flatpak especially. if doodlePath := c.String("chdir"); doodlePath != "" { if err := os.Chdir(doodlePath); err != nil { diff --git a/pkg/editor_scene.go b/pkg/editor_scene.go index bdb10d7..d69e82d 100644 --- a/pkg/editor_scene.go +++ b/pkg/editor_scene.go @@ -539,7 +539,7 @@ func (s *EditorScene) SaveLevel(filename string) error { m.Title = "Alpha" } if m.Author == "" { - m.Author = native.DefaultAuthor() + m.Author = native.DefaultAuthor } m.Palette = s.UI.Canvas.Palette @@ -641,7 +641,7 @@ func (s *EditorScene) SaveDoodad(filename string) error { d.Title = "Untitled Doodad" } if d.Author == "" { - d.Author = native.DefaultAuthor() + d.Author = native.DefaultAuthor } // TODO: is this copying necessary? diff --git a/pkg/level/types.go b/pkg/level/types.go index e32b536..efece3b 100644 --- a/pkg/level/types.go +++ b/pkg/level/types.go @@ -91,7 +91,7 @@ func New() *Level { Base: Base{ Version: 1, Title: "Untitled", - Author: native.DefaultAuthor(), + Author: native.DefaultAuthor, Files: NewFileSystem(), }, Chunker: NewChunker(balance.ChunkSize), diff --git a/pkg/native/username.go b/pkg/native/username.go index 2316f58..30150ca 100644 --- a/pkg/native/username.go +++ b/pkg/native/username.go @@ -2,28 +2,9 @@ package native import ( "os" - - "git.kirsle.net/SketchyMaze/doodle/pkg/plus/dpp" ) -var USER string = os.Getenv("USER") - -/* -DefaultAuthor will return the local user's name to be the default Author -for levels and doodads they create. - -If they have registered the game, use the name from their license JWT token. - -Otherwise fall back to their native operating system user. -*/ -func DefaultAuthor() string { - // Are we registered? TODO: get from registration - if dpp.Driver.IsRegistered() { - if reg, err := dpp.Driver.GetRegistration(); err == nil { - return reg.Name - } - } - - // Return OS username - return os.Getenv("USER") -} +var ( + USER string = os.Getenv("USER") + DefaultAuthor = USER +) diff --git a/pkg/plus/dpp/plus_dpp.go b/pkg/plus/dpp/plus_dpp.go index 9a3a69b..9bc4bc4 100644 --- a/pkg/plus/dpp/plus_dpp.go +++ b/pkg/plus/dpp/plus_dpp.go @@ -10,6 +10,7 @@ import ( "git.kirsle.net/SketchyMaze/doodle/pkg/filesystem" "git.kirsle.net/SketchyMaze/doodle/pkg/level" "git.kirsle.net/SketchyMaze/doodle/pkg/levelpack" + "git.kirsle.net/SketchyMaze/doodle/pkg/native" "git.kirsle.net/SketchyMaze/doodle/pkg/plus" "git.kirsle.net/SketchyMaze/dpp/embedding" "git.kirsle.net/SketchyMaze/dpp/license" @@ -46,11 +47,19 @@ func (Plugin) UploadLicenseFile(filename string) (plus.Registration, error) { // Hack: to translate JWT token types, easiest is to just encode/decode them (inner jwt.StandardClaims complexity). func translateLicenseStruct(reg license.Registration) (plus.Registration, error) { - jsonStr, err := json.Marshal(reg) + // Set the DefaultAuthor to the registered user's name. + if reg.Name != "" { + native.DefaultAuthor = reg.Name + } + + // Marshal to JSON and back to cast the type. + var ( + result plus.Registration + jsonStr, err = json.Marshal(reg) + ) if err != nil { return plus.Registration{}, err } - var result plus.Registration err = json.Unmarshal(jsonStr, &result) return result, err } diff --git a/pkg/plus/dpp/plus_foss.go b/pkg/plus/dpp/plus_foss.go index 0a00b2d..f122399 100644 --- a/pkg/plus/dpp/plus_foss.go +++ b/pkg/plus/dpp/plus_foss.go @@ -18,7 +18,11 @@ var ErrNotImplemented = errors.New("not implemented") type Plugin struct{} func (Plugin) LoadFromEmbeddable(filename string, fs filesystem.Embeddable, force bool) (*doodads.Doodad, error) { - return doodads.LoadFile(filename) + if result, err := doodads.LoadFile(filename); err != nil { + return nil, plus.ErrRegisteredFeature + } else { + return result, nil + } } func (Plugin) IsRegistered() bool {