From 5f75168235b0cfa4545b5157da7fb2722bdf21ec Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Wed, 17 Jun 2020 18:21:15 -0700 Subject: [PATCH] Command-line flag for window resolution * Added a --window flag to the game executable to specify the startup window resolution. Either specify an exact size (e.g. 1024x768) or a special keyword "desktop", "mobile" or "landscape" * Default size is "desktop" or 1024x768 * Mobile simulates a smartphone form factor of 375x812 * Landscape is mobile but flipped horizontally. * Doodle UX isn't great on mobile but this is a step towards working on mobile friendly UI --- cmd/doodle/main.go | 41 ++++++++++++++++++++++ etc/linux/net.kirsle.ProjectDoodle.desktop | 1 + scripts/fpm-bundle.sh | 3 ++ 3 files changed, 45 insertions(+) diff --git a/cmd/doodle/main.go b/cmd/doodle/main.go index e254705..1103de0 100644 --- a/cmd/doodle/main.go +++ b/cmd/doodle/main.go @@ -1,11 +1,14 @@ package main import ( + "errors" "fmt" "log" "os" + "regexp" "runtime" "sort" + "strconv" "time" doodle "git.kirsle.net/apps/doodle/pkg" @@ -65,6 +68,11 @@ func main() { Aliases: []string{"e"}, Usage: "edit the map given on the command line (instead of play it)", }, + &cli.StringFlag{ + Name: "window", + Aliases: []string{"w"}, + Usage: "set the window size (e.g. -w 1024x768) or special value: desktop, mobile, landscape", + }, &cli.BoolFlag{ Name: "guitest", Usage: "enter the GUI Test scene on startup", @@ -77,6 +85,13 @@ func main() { filename = c.Args().Get(0) } + // Setting a custom resolution? + if c.String("window") != "" { + if err := setResolution(c.String("window")); err != nil { + panic(err) + } + } + // SDL engine. engine := sdl.New( fmt.Sprintf("%s v%s", branding.AppName, branding.Version), @@ -124,3 +139,29 @@ func main() { log.Fatal(err) } } + +func setResolution(value string) error { + switch value { + case "desktop": + return nil + case "mobile": + balance.Width = 375 + balance.Height = 812 + case "landscape": + balance.Width = 812 + balance.Height = 375 + default: + var re = regexp.MustCompile(`^(\d+?)x(\d+?)$`) + m := re.FindStringSubmatch(value) + if len(m) == 0 { + return errors.New("--window: must be of the form WIDTHxHEIGHT, i.e. " + + "1024x768, or special keywords desktop, mobile, or landscape.") + } + + w, _ := strconv.Atoi(m[1]) + h, _ := strconv.Atoi(m[2]) + balance.Width = w + balance.Height = h + } + return nil +} diff --git a/etc/linux/net.kirsle.ProjectDoodle.desktop b/etc/linux/net.kirsle.ProjectDoodle.desktop index 6fdf39c..3db6da4 100755 --- a/etc/linux/net.kirsle.ProjectDoodle.desktop +++ b/etc/linux/net.kirsle.ProjectDoodle.desktop @@ -6,6 +6,7 @@ GenericName=Project Doodle X-GNOME-FullName=Project: Doodle - A drawing-based maze game Comment=A drawing-based maze game. Exec=/opt/project-doodle/doodle +Path=/opt/project-doodle Icon=project-doodle StartupNotify=true Keywords=game;maze; diff --git a/scripts/fpm-bundle.sh b/scripts/fpm-bundle.sh index 4b5c14f..101b15a 100755 --- a/scripts/fpm-bundle.sh +++ b/scripts/fpm-bundle.sh @@ -37,6 +37,9 @@ cp ../../etc/icons/64.png "root$ICON_ROOT/64x64/apps/project-doodle.png" cp ../../etc/icons/32.png "root$ICON_ROOT/32x32/apps/project-doodle.png" cp ../../etc/icons/16.png "root$ICON_ROOT/16x16/apps/project-doodle.png" +# Copy runtime package and guidebook +cp -r guidebook rtp "root$INSTALL_ROOT/" + echo ===================== echo Starting fpm package build. echo =====================