From 546b5705dbe29c1ceff6964c7603c4ab1a4293e5 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sat, 24 Sep 2022 17:45:54 -0700 Subject: [PATCH] Detect touchscreen and tweak some behaviors --- Building.md | 48 +++++++++++++++++++++++------------- cmd/doodle/main.go | 12 ++++++--- pkg/branding/branding.go | 2 +- pkg/cursor/cursor.go | 7 +++++- pkg/level/chunker_zipfile.go | 2 +- pkg/native/engine_sdl.go | 9 +++++++ pkg/native/engine_wasm.go | 4 +++ pkg/usercfg/usercfg.go | 11 ++++++++- 8 files changed, 71 insertions(+), 24 deletions(-) diff --git a/Building.md b/Building.md index faba3cd..35ca127 100644 --- a/Building.md +++ b/Building.md @@ -1,6 +1,7 @@ # Building Doodle -* [Quickstart](#quickstart-with-bootstrap-py) +* [Automated Release Scripts](#automated-release-scripts) +* [Quickstart with bootstrap.py](#quickstart-with-bootstrap-py) * [Detailed Instructions](#detailed-instructions) * [Linux](#linux) * [Flatpak for Linux](#flatpak-for-linux) @@ -72,12 +73,10 @@ For building the app the hard way, and in-depth instructions, read this section. You'll need the following git repositories: * `git.kirsle.net/SketchyMaze/doodle` - the game engine. -* `git.kirsle.net/apps/SketchyMaze/masters` - where built-in level files are kept, - as well as master GIMP drawings for sprites and such but only the levels - are necessary to build the app properly. Tho even then the app would - work fine with no levels built in! -* `git.kirsle.net/apps/SketchyMaze/vendor` - vendored libraries for Windows (SDL2.dll etc.) -* `git.kirsle.net/apps/SketchyMaze/rtp` - runtime package (sounds and music mostly) +* `git.kirsle.net/SketchyMaze/assets` - where built-in level files are kept (optional) +* `git.kirsle.net/SketchyMaze/vendor` - vendored libraries for Windows (SDL2.dll etc.) +* `git.kirsle.net/SketchyMaze/rtp` - runtime package (sounds and music mostly) +* `git.kirsle.net/SketchyMaze/doodads` - sources to compile the built-in doodads. The [docker](https://git.kirsle.net/SketchyMaze/docker) repo will be more up-to-date than the instructions below, as that repo actually has @@ -85,16 +84,17 @@ runnable code in the Dockerfile! ```bash # Clone all the repos down to your project folder -git clone git@git.kirsle.net:apps/SketchyMaze/rtp rtp -git clone git@git.kirsle.net:apps/SketchyMaze/vendor vendor -git clone git@git.kirsle.net:apps/SketchyMaze/masters masters -git clone git@git.kirsle.net:apps/doodle doodle +git clone https://git.kirsle.net/SketchyMaze/rtp rtp +git clone https://git.kirsle.net/SketchyMaze/vendor vendor +git clone https://git.kirsle.net/SketchyMaze/masters masters +git clone https://git.kirsle.net/SketchyMaze/doodle doodle +git clone https://git.kirsle.net/SketchyMaze/doodads doodle/deps/doodads # Enter doodle/ project cd doodle/ # Copy fonts and levels in -cp ../masters/levels assets/levels +cp ../assets/levelpacks assets/levelpacks cp ../vendor/fonts assets/fonts mkdir rtp && cp -r ../rtp/* rtp/ @@ -121,13 +121,27 @@ make mingw make release ``` -The `make setup` command tries to do the above. - `make build` produces a local binary in the bin/ folder and `make dist` will build an app for distribution in the dist/ folder. -Levels should be copied in from the doodle-masters repo into the -assets/levels/ folder before building the game. +The bootstrap.py script does all of the above up to `make dist` so if you need +fully release the game by hand (e.g. on a macOS host) you can basically get away +with: + +1. Clone the doodle repo and cd into it +2. Run `bootstrap.py` to fully set up your OS with dependencies and build a + release quality version of the game with all latest assets (the script finishes + with a `make dist`). +3. Run `make release` to package the dist/ artifact into platform specific + release artifacts (.rpm/.deb/.tar.gz bundles for Linux, .zip for Windows, + .dmg if running on macOS) which output into the dist/release/ folder. + +Before step 3 you may want to download the latest Guidebook to bundle with +the game (optional). Grab and extract the tarball and run `make dist && make release`: + +```bash +wget -O - https://download.sketchymaze.com/guidebook.tar.gz | tar -xzvf - +``` ## Fonts @@ -195,7 +209,7 @@ brew install golang sdl2 sdl2_ttf sdl2_mixer pkg-config ## Flatpak for Linux -The repo for this is at . +The repo for this is at . ## Windows Cross-Compile from Linux diff --git a/cmd/doodle/main.go b/cmd/doodle/main.go index 30ce2f6..0957e8d 100644 --- a/cmd/doodle/main.go +++ b/cmd/doodle/main.go @@ -20,6 +20,7 @@ import ( "git.kirsle.net/SketchyMaze/doodle/pkg/gamepad" "git.kirsle.net/SketchyMaze/doodle/pkg/license" "git.kirsle.net/SketchyMaze/doodle/pkg/log" + "git.kirsle.net/SketchyMaze/doodle/pkg/native" "git.kirsle.net/SketchyMaze/doodle/pkg/shmem" "git.kirsle.net/SketchyMaze/doodle/pkg/sound" "git.kirsle.net/SketchyMaze/doodle/pkg/sprites" @@ -199,9 +200,10 @@ func main() { game := doodle.New(c.Bool("debug"), engine) game.SetupEngine() - // Hide the mouse cursor over the window, we draw our own - // sprite image for it. - engine.ShowCursor(false) + // Hide the mouse cursor over the window, we draw our own sprite image for it. + if !native.HasTouchscreen(engine) { + engine.ShowCursor(false) + } // Set the app window icon. if engine, ok := game.Engine.(*sdl.Renderer); ok { @@ -235,6 +237,10 @@ func main() { // Initialize the developer shell chatbot easter egg. chatbot.Setup() + // Log some basic environment details. + w, h := engine.WindowSize() + log.Info("Has touchscreen? %+v Window size: %dx%d", native.HasTouchscreen(engine), w, h) + game.Run() return nil } diff --git a/pkg/branding/branding.go b/pkg/branding/branding.go index 0bff209..6492910 100644 --- a/pkg/branding/branding.go +++ b/pkg/branding/branding.go @@ -9,7 +9,7 @@ import ( const ( AppName = "Sketchy Maze" Summary = "A drawing-based maze game" - Version = "0.13.0" + Version = "0.13.1" Website = "https://www.sketchymaze.com" Copyright = "2022 Noah Petherbridge" Byline = "a game by Noah Petherbridge." diff --git a/pkg/cursor/cursor.go b/pkg/cursor/cursor.go index ee50c83..0698b8f 100644 --- a/pkg/cursor/cursor.go +++ b/pkg/cursor/cursor.go @@ -4,6 +4,7 @@ package cursor import ( "git.kirsle.net/SketchyMaze/doodle/pkg/balance" "git.kirsle.net/SketchyMaze/doodle/pkg/log" + "git.kirsle.net/SketchyMaze/doodle/pkg/native" "git.kirsle.net/SketchyMaze/doodle/pkg/shmem" "git.kirsle.net/SketchyMaze/doodle/pkg/sprites" "git.kirsle.net/go/render" @@ -22,8 +23,12 @@ var Current *Cursor // NoCursor hides the cursor entirely. var NoCursor = &Cursor{} -// Draw the cursor on screen. +// Draw the cursor on screen. NOTE: Does not draw on touchscreen devices. func Draw(e render.Engine) { + if native.HasTouchscreen(e) { + return + } + if Current == nil { Current = NewPointer(e) } diff --git a/pkg/level/chunker_zipfile.go b/pkg/level/chunker_zipfile.go index fba697d..e29e528 100644 --- a/pkg/level/chunker_zipfile.go +++ b/pkg/level/chunker_zipfile.go @@ -89,7 +89,7 @@ func (c *Chunker) MigrateZipfile(zf *zip.Writer) error { } } } else { - log.Warn("Chunker.MigrateZipfile: the drawing did not give me a zipfile!") + log.Debug("Chunker.MigrateZipfile: the drawing did not give me a zipfile!") } if len(c.Chunks) == 0 { diff --git a/pkg/native/engine_sdl.go b/pkg/native/engine_sdl.go index 6ceb8c0..b38d747 100644 --- a/pkg/native/engine_sdl.go +++ b/pkg/native/engine_sdl.go @@ -1,3 +1,4 @@ +//go:build !js // +build !js package native @@ -14,6 +15,14 @@ import ( // Native render engine functions (SDL2 edition), // not for JavaScript/WASM yet. +// HasTouchscreen checks if the device has at least one SDL_GetNumTouchDevices. +func HasTouchscreen(e render.Engine) bool { + if _, ok := e.(*sdl.Renderer); ok { + return sdl2.GetNumTouchDevices() > 0 + } + return false +} + /* TextToImage takes an SDL2_TTF texture and makes it into a Go image. diff --git a/pkg/native/engine_wasm.go b/pkg/native/engine_wasm.go index 5fecec5..5d156b5 100644 --- a/pkg/native/engine_wasm.go +++ b/pkg/native/engine_wasm.go @@ -8,6 +8,10 @@ import ( "git.kirsle.net/go/render" ) +func HasTouchscreen(e render.Engine) bool { + return false +} + func TextToImage(e render.Engine, text render.Text) (image.Image, error) { return nil, errors.New("not supported on WASM") } diff --git a/pkg/usercfg/usercfg.go b/pkg/usercfg/usercfg.go index 8cabe22..4d07c95 100644 --- a/pkg/usercfg/usercfg.go +++ b/pkg/usercfg/usercfg.go @@ -18,6 +18,8 @@ import ( "path/filepath" "time" + "git.kirsle.net/SketchyMaze/doodle/pkg/native" + "git.kirsle.net/SketchyMaze/doodle/pkg/shmem" "git.kirsle.net/SketchyMaze/doodle/pkg/userdir" "git.kirsle.net/go/render" ) @@ -53,7 +55,14 @@ var Current = Defaults() // Defaults returns sensible default user settings. func Defaults() *Settings { - return &Settings{} + settings := &Settings{} + + // If not a touchscreen device, disable touchscreen hints as default. + if !native.HasTouchscreen(shmem.CurrentRenderEngine) { + settings.HideTouchHints = true + } + + return settings } // Filepath returns the path to the settings file.