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
modals
Noah 2020-06-17 18:21:15 -07:00
parent dabf88dff8
commit 5f75168235
3 changed files with 45 additions and 0 deletions

View File

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

View File

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

View File

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