2017-10-27 01:03:11 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-04-10 02:17:56 +00:00
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
2017-10-27 02:26:54 +00:00
|
|
|
"runtime"
|
2019-04-10 02:17:56 +00:00
|
|
|
"sort"
|
|
|
|
"time"
|
2019-04-10 00:35:44 +00:00
|
|
|
|
|
|
|
doodle "git.kirsle.net/apps/doodle/pkg"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
2019-06-28 05:54:46 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/bindata"
|
2019-06-24 00:52:48 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/branding"
|
2019-12-31 02:13:28 +00:00
|
|
|
"git.kirsle.net/go/render/sdl"
|
2019-04-10 02:17:56 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
|
|
|
|
_ "image/png"
|
2017-10-27 01:03:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Build number is the git commit hash.
|
|
|
|
var (
|
2019-04-10 02:17:56 +00:00
|
|
|
Build = "<dynamic>"
|
|
|
|
BuildDate string
|
2017-10-27 01:03:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-04-10 02:17:56 +00:00
|
|
|
if BuildDate == "" {
|
|
|
|
BuildDate = time.Now().Format(time.RFC3339)
|
|
|
|
}
|
2019-05-07 00:06:40 +00:00
|
|
|
|
|
|
|
// Use all the CPU cores for collision detection and other load balanced
|
|
|
|
// goroutine work in the app.
|
|
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
2017-10-27 01:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2017-10-27 02:26:54 +00:00
|
|
|
runtime.LockOSThread()
|
2017-10-27 01:03:11 +00:00
|
|
|
|
2019-04-10 02:17:56 +00:00
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "doodle"
|
2019-06-24 00:52:48 +00:00
|
|
|
app.Usage = fmt.Sprintf("%s - %s", branding.AppName, branding.Summary)
|
2019-04-20 00:23:37 +00:00
|
|
|
|
|
|
|
var freeLabel string
|
|
|
|
if balance.FreeVersion {
|
|
|
|
freeLabel = " (shareware)"
|
|
|
|
}
|
|
|
|
|
|
|
|
app.Version = fmt.Sprintf("%s build %s%s. Built on %s",
|
2019-06-24 00:52:48 +00:00
|
|
|
branding.Version,
|
2019-04-10 02:17:56 +00:00
|
|
|
Build,
|
2019-04-20 00:23:37 +00:00
|
|
|
freeLabel,
|
2019-04-10 02:17:56 +00:00
|
|
|
BuildDate,
|
|
|
|
)
|
|
|
|
|
|
|
|
app.Flags = []cli.Flag{
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "debug, d",
|
|
|
|
Usage: "enable debug level logging",
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "edit, e",
|
|
|
|
Usage: "edit the map given on the command line (instead of play it)",
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "guitest",
|
|
|
|
Usage: "enter the GUI Test scene on startup",
|
|
|
|
},
|
2018-06-17 17:29:57 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 02:17:56 +00:00
|
|
|
app.Action = func(c *cli.Context) error {
|
|
|
|
var filename string
|
|
|
|
if c.NArg() > 0 {
|
|
|
|
filename = c.Args().Get(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SDL engine.
|
|
|
|
engine := sdl.New(
|
2019-06-24 00:52:48 +00:00
|
|
|
fmt.Sprintf("%s v%s", branding.AppName, branding.Version),
|
2019-04-10 02:17:56 +00:00
|
|
|
balance.Width,
|
|
|
|
balance.Height,
|
|
|
|
)
|
2018-07-22 00:12:22 +00:00
|
|
|
|
2019-06-28 05:54:46 +00:00
|
|
|
// Load the SDL fonts in from bindata storage.
|
|
|
|
if fonts, err := bindata.AssetDir("assets/fonts"); err == nil {
|
|
|
|
for _, file := range fonts {
|
|
|
|
data, err := bindata.Asset("assets/fonts/" + file)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
sdl.InstallFont(file, data)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2019-04-10 02:17:56 +00:00
|
|
|
game := doodle.New(c.Bool("debug"), engine)
|
|
|
|
game.SetupEngine()
|
|
|
|
if c.Bool("guitest") {
|
|
|
|
game.Goto(&doodle.GUITestScene{})
|
|
|
|
} else if filename != "" {
|
|
|
|
if c.Bool("edit") {
|
|
|
|
game.EditFile(filename)
|
|
|
|
} else {
|
|
|
|
game.PlayLevel(filename)
|
|
|
|
}
|
2018-06-21 02:00:46 +00:00
|
|
|
}
|
2019-04-10 02:17:56 +00:00
|
|
|
game.Run()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Sort(cli.FlagsByName(app.Flags))
|
|
|
|
sort.Sort(cli.CommandsByName(app.Commands))
|
|
|
|
|
|
|
|
err := app.Run(os.Args)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
2018-06-17 17:29:57 +00:00
|
|
|
}
|
2017-10-27 01:03:11 +00:00
|
|
|
}
|