WIP Doodle++ #93

Merged
kirsle merged 4 commits from dpp into master 2024-04-19 05:49:41 +00:00
7 changed files with 31 additions and 31 deletions
Showing only changes of commit a79601f983 - Show all commits

View File

@ -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

View File

@ -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 {

View File

@ -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?

View File

@ -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),

View File

@ -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
)

View File

@ -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
}

View File

@ -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 {