Add Branding Module for Centralized Game Info

* Moves the game's Title, Summary and Version into pkg/branding where it
  is centrally controlled.
This commit is contained in:
Noah 2019-06-23 17:52:48 -07:00
parent 99eab19c5b
commit 1150d6d3e9
11 changed files with 34 additions and 16 deletions

View File

@ -12,7 +12,7 @@ import (
"image/png" "image/png"
"git.kirsle.net/apps/doodle/lib/render" "git.kirsle.net/apps/doodle/lib/render"
doodle "git.kirsle.net/apps/doodle/pkg" "git.kirsle.net/apps/doodle/pkg/branding"
"git.kirsle.net/apps/doodle/pkg/doodads" "git.kirsle.net/apps/doodle/pkg/doodads"
"git.kirsle.net/apps/doodle/pkg/level" "git.kirsle.net/apps/doodle/pkg/level"
"git.kirsle.net/apps/doodle/pkg/log" "git.kirsle.net/apps/doodle/pkg/log"
@ -146,7 +146,7 @@ func imageToDrawing(c *cli.Context, chroma render.Color, inputFiles []string, ou
case extDoodad: case extDoodad:
log.Info("Output is a Doodad file (chunk size %d): %s", chunkSize, outputFile) log.Info("Output is a Doodad file (chunk size %d): %s", chunkSize, outputFile)
doodad := doodads.New(chunkSize) doodad := doodads.New(chunkSize)
doodad.GameVersion = doodle.Version doodad.GameVersion = branding.Version
doodad.Title = c.String("title") doodad.Title = c.String("title")
if doodad.Title == "" { if doodad.Title == "" {
doodad.Title = "Converted Doodad" doodad.Title = "Converted Doodad"
@ -184,7 +184,7 @@ func imageToDrawing(c *cli.Context, chroma render.Color, inputFiles []string, ou
} }
lvl := level.New() lvl := level.New()
lvl.GameVersion = doodle.Version lvl.GameVersion = branding.Version
lvl.Title = c.String("title") lvl.Title = c.String("title")
if lvl.Title == "" { if lvl.Title == "" {
lvl.Title = "Converted Level" lvl.Title = "Converted Level"

View File

@ -9,8 +9,8 @@ import (
"time" "time"
"git.kirsle.net/apps/doodle/cmd/doodad/commands" "git.kirsle.net/apps/doodle/cmd/doodad/commands"
doodle "git.kirsle.net/apps/doodle/pkg"
"git.kirsle.net/apps/doodle/pkg/balance" "git.kirsle.net/apps/doodle/pkg/balance"
"git.kirsle.net/apps/doodle/pkg/branding"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -37,7 +37,7 @@ func main() {
} }
app.Version = fmt.Sprintf("%s build %s%s. Built on %s", app.Version = fmt.Sprintf("%s build %s%s. Built on %s",
doodle.Version, branding.Version,
Build, Build,
freeLabel, freeLabel,
BuildDate, BuildDate,

View File

@ -11,6 +11,7 @@ import (
"git.kirsle.net/apps/doodle/lib/render/sdl" "git.kirsle.net/apps/doodle/lib/render/sdl"
doodle "git.kirsle.net/apps/doodle/pkg" doodle "git.kirsle.net/apps/doodle/pkg"
"git.kirsle.net/apps/doodle/pkg/balance" "git.kirsle.net/apps/doodle/pkg/balance"
"git.kirsle.net/apps/doodle/pkg/branding"
"github.com/urfave/cli" "github.com/urfave/cli"
_ "image/png" _ "image/png"
@ -37,7 +38,7 @@ func main() {
app := cli.NewApp() app := cli.NewApp()
app.Name = "doodle" app.Name = "doodle"
app.Usage = "command line interface for Doodle" app.Usage = fmt.Sprintf("%s - %s", branding.AppName, branding.Summary)
var freeLabel string var freeLabel string
if balance.FreeVersion { if balance.FreeVersion {
@ -45,7 +46,7 @@ func main() {
} }
app.Version = fmt.Sprintf("%s build %s%s. Built on %s", app.Version = fmt.Sprintf("%s build %s%s. Built on %s",
doodle.Version, branding.Version,
Build, Build,
freeLabel, freeLabel,
BuildDate, BuildDate,
@ -74,7 +75,7 @@ func main() {
// SDL engine. // SDL engine.
engine := sdl.New( engine := sdl.New(
"Doodle v"+doodle.Version, fmt.Sprintf("%s v%s", branding.AppName, branding.Version),
balance.Width, balance.Width,
balance.Height, balance.Height,
) )

8
pkg/branding/branding.go Normal file
View File

@ -0,0 +1,8 @@
package branding
// Constants for branding and version information.
const (
AppName = "Project: Doodle"
Summary = "A drawing-based maze game"
Version = "0.0.8-alpha"
)

View File

@ -6,6 +6,7 @@ import (
"io/ioutil" "io/ioutil"
"strings" "strings"
"git.kirsle.net/apps/doodle/pkg/branding"
"git.kirsle.net/apps/doodle/pkg/enum" "git.kirsle.net/apps/doodle/pkg/enum"
"git.kirsle.net/apps/doodle/pkg/filesystem" "git.kirsle.net/apps/doodle/pkg/filesystem"
"git.kirsle.net/apps/doodle/pkg/log" "git.kirsle.net/apps/doodle/pkg/log"
@ -62,6 +63,10 @@ func (d *Doodad) WriteFile(filename string) error {
filename += enum.DoodadExt filename += enum.DoodadExt
} }
// Set the version information.
d.Version = 1
d.GameVersion = branding.Version
// bin, err := m.ToBinary() // bin, err := m.ToBinary()
bin, err := d.ToJSON() bin, err := d.ToJSON()
if err != nil { if err != nil {

View File

@ -14,9 +14,6 @@ import (
) )
const ( const (
// Version number.
Version = "0.0.7-alpha"
// TargetFPS is the frame rate to cap the game to. // TargetFPS is the frame rate to cap the game to.
TargetFPS = 1000 / 60 // 60 FPS TargetFPS = 1000 / 60 // 60 FPS

View File

@ -257,8 +257,7 @@ func (s *EditorScene) SaveDoodad(filename string) error {
// Save it to their profile directory. // Save it to their profile directory.
filename = userdir.DoodadPath(filename) filename = userdir.DoodadPath(filename)
log.Info("Write Doodad: %s", filename) log.Info("Write Doodad: %s", filename)
err := d.WriteJSON(filename) return d.WriteFile(filename)
return err
} }
// Destroy the scene. // Destroy the scene.

View File

@ -9,6 +9,7 @@ import (
"git.kirsle.net/apps/doodle/lib/render" "git.kirsle.net/apps/doodle/lib/render"
"git.kirsle.net/apps/doodle/lib/ui" "git.kirsle.net/apps/doodle/lib/ui"
"git.kirsle.net/apps/doodle/pkg/balance" "git.kirsle.net/apps/doodle/pkg/balance"
"git.kirsle.net/apps/doodle/pkg/branding"
"git.kirsle.net/apps/doodle/pkg/doodads" "git.kirsle.net/apps/doodle/pkg/doodads"
"git.kirsle.net/apps/doodle/pkg/enum" "git.kirsle.net/apps/doodle/pkg/enum"
"git.kirsle.net/apps/doodle/pkg/level" "git.kirsle.net/apps/doodle/pkg/level"
@ -564,7 +565,7 @@ func (u *EditorUI) SetupStatusBar(d *Doodle) *ui.Frame {
shareware = " (shareware)" shareware = " (shareware)"
} }
extraLabel := ui.NewLabel(ui.Label{ extraLabel := ui.NewLabel(ui.Label{
Text: "Doodle v" + Version + shareware, Text: fmt.Sprintf("%s v%s%s", branding.AppName, branding.Version, shareware),
Font: balance.StatusFont, Font: balance.StatusFont,
}) })
extraLabel.Configure(ui.Config{ extraLabel.Configure(ui.Config{

View File

@ -7,6 +7,7 @@ import (
"git.kirsle.net/apps/doodle/lib/render" "git.kirsle.net/apps/doodle/lib/render"
"git.kirsle.net/apps/doodle/lib/ui" "git.kirsle.net/apps/doodle/lib/ui"
"git.kirsle.net/apps/doodle/pkg/balance" "git.kirsle.net/apps/doodle/pkg/balance"
"git.kirsle.net/apps/doodle/pkg/branding"
"git.kirsle.net/apps/doodle/pkg/log" "git.kirsle.net/apps/doodle/pkg/log"
) )
@ -258,7 +259,7 @@ func (s *GUITestScene) Draw(d *Doodle) error {
d.Engine.Clear(render.White) d.Engine.Clear(render.White)
label := ui.NewLabel(ui.Label{ label := ui.NewLabel(ui.Label{
Text: "GUITest Doodle v" + Version, Text: fmt.Sprintf("GUITest %s v%s", branding.AppName, branding.Version),
Font: render.Text{ Font: render.Text{
Size: 26, Size: 26,
Color: render.Pink, Color: render.Pink,

View File

@ -6,6 +6,7 @@ import (
"io/ioutil" "io/ioutil"
"strings" "strings"
"git.kirsle.net/apps/doodle/pkg/branding"
"git.kirsle.net/apps/doodle/pkg/enum" "git.kirsle.net/apps/doodle/pkg/enum"
"git.kirsle.net/apps/doodle/pkg/filesystem" "git.kirsle.net/apps/doodle/pkg/filesystem"
"git.kirsle.net/apps/doodle/pkg/log" "git.kirsle.net/apps/doodle/pkg/log"
@ -47,6 +48,10 @@ func (m *Level) WriteFile(filename string) error {
filename += enum.LevelExt filename += enum.LevelExt
} }
// Set the version information.
m.Version = 1
m.GameVersion = branding.Version
// bin, err := m.ToBinary() // bin, err := m.ToBinary()
bin, err := m.ToJSON() bin, err := m.ToJSON()
if err != nil { if err != nil {

View File

@ -5,6 +5,7 @@ import (
"git.kirsle.net/apps/doodle/lib/render" "git.kirsle.net/apps/doodle/lib/render"
"git.kirsle.net/apps/doodle/lib/ui" "git.kirsle.net/apps/doodle/lib/ui"
"git.kirsle.net/apps/doodle/pkg/balance" "git.kirsle.net/apps/doodle/pkg/balance"
"git.kirsle.net/apps/doodle/pkg/branding"
) )
// MainScene implements the main menu of Doodle. // MainScene implements the main menu of Doodle.
@ -67,7 +68,7 @@ func (s *MainScene) Draw(d *Doodle) error {
d.Engine.Clear(render.White) d.Engine.Clear(render.White)
label := ui.NewLabel(ui.Label{ label := ui.NewLabel(ui.Label{
Text: "Doodle v" + Version, Text: branding.AppName,
Font: render.Text{ Font: render.Text{
Size: 26, Size: 26,
Color: render.Pink, Color: render.Pink,