Detect touchscreen and tweak some behaviors

This commit is contained in:
Noah 2022-09-24 17:45:54 -07:00
parent 6631d8d11c
commit 546b5705db
8 changed files with 71 additions and 24 deletions

View File

@ -1,6 +1,7 @@
# Building Doodle # 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) * [Detailed Instructions](#detailed-instructions)
* [Linux](#linux) * [Linux](#linux)
* [Flatpak for Linux](#flatpak-for-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: this section. You'll need the following git repositories:
* `git.kirsle.net/SketchyMaze/doodle` - the game engine. * `git.kirsle.net/SketchyMaze/doodle` - the game engine.
* `git.kirsle.net/apps/SketchyMaze/masters` - where built-in level files are kept, * `git.kirsle.net/SketchyMaze/assets` - where built-in level files are kept (optional)
as well as master GIMP drawings for sprites and such but only the levels * `git.kirsle.net/SketchyMaze/vendor` - vendored libraries for Windows (SDL2.dll etc.)
are necessary to build the app properly. Tho even then the app would * `git.kirsle.net/SketchyMaze/rtp` - runtime package (sounds and music mostly)
work fine with no levels built in! * `git.kirsle.net/SketchyMaze/doodads` - sources to compile the built-in doodads.
* `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)
The [docker](https://git.kirsle.net/SketchyMaze/docker) repo will The [docker](https://git.kirsle.net/SketchyMaze/docker) repo will
be more up-to-date than the instructions below, as that repo actually has be more up-to-date than the instructions below, as that repo actually has
@ -85,16 +84,17 @@ runnable code in the Dockerfile!
```bash ```bash
# Clone all the repos down to your project folder # Clone all the repos down to your project folder
git clone git@git.kirsle.net:apps/SketchyMaze/rtp rtp git clone https://git.kirsle.net/SketchyMaze/rtp rtp
git clone git@git.kirsle.net:apps/SketchyMaze/vendor vendor git clone https://git.kirsle.net/SketchyMaze/vendor vendor
git clone git@git.kirsle.net:apps/SketchyMaze/masters masters git clone https://git.kirsle.net/SketchyMaze/masters masters
git clone git@git.kirsle.net:apps/doodle doodle git clone https://git.kirsle.net/SketchyMaze/doodle doodle
git clone https://git.kirsle.net/SketchyMaze/doodads doodle/deps/doodads
# Enter doodle/ project # Enter doodle/ project
cd doodle/ cd doodle/
# Copy fonts and levels in # Copy fonts and levels in
cp ../masters/levels assets/levels cp ../assets/levelpacks assets/levelpacks
cp ../vendor/fonts assets/fonts cp ../vendor/fonts assets/fonts
mkdir rtp && cp -r ../rtp/* rtp/ mkdir rtp && cp -r ../rtp/* rtp/
@ -121,13 +121,27 @@ make mingw
make release make release
``` ```
The `make setup` command tries to do the above.
`make build` produces a local binary in the bin/ folder and `make dist` `make build` produces a local binary in the bin/ folder and `make dist`
will build an app for distribution in the dist/ folder. will build an app for distribution in the dist/ folder.
Levels should be copied in from the doodle-masters repo into the The bootstrap.py script does all of the above up to `make dist` so if you need
assets/levels/ folder before building the game. 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 ## Fonts
@ -195,7 +209,7 @@ brew install golang sdl2 sdl2_ttf sdl2_mixer pkg-config
## Flatpak for Linux ## Flatpak for Linux
The repo for this is at <https://code.sketchymaze.com/game/flatpak>. The repo for this is at <https://git.kirsle.net/SketchyMaze/flatpak>.
## Windows Cross-Compile from Linux ## Windows Cross-Compile from Linux

View File

@ -20,6 +20,7 @@ import (
"git.kirsle.net/SketchyMaze/doodle/pkg/gamepad" "git.kirsle.net/SketchyMaze/doodle/pkg/gamepad"
"git.kirsle.net/SketchyMaze/doodle/pkg/license" "git.kirsle.net/SketchyMaze/doodle/pkg/license"
"git.kirsle.net/SketchyMaze/doodle/pkg/log" "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/shmem"
"git.kirsle.net/SketchyMaze/doodle/pkg/sound" "git.kirsle.net/SketchyMaze/doodle/pkg/sound"
"git.kirsle.net/SketchyMaze/doodle/pkg/sprites" "git.kirsle.net/SketchyMaze/doodle/pkg/sprites"
@ -199,9 +200,10 @@ func main() {
game := doodle.New(c.Bool("debug"), engine) game := doodle.New(c.Bool("debug"), engine)
game.SetupEngine() game.SetupEngine()
// Hide the mouse cursor over the window, we draw our own // Hide the mouse cursor over the window, we draw our own sprite image for it.
// sprite image for it. if !native.HasTouchscreen(engine) {
engine.ShowCursor(false) engine.ShowCursor(false)
}
// Set the app window icon. // Set the app window icon.
if engine, ok := game.Engine.(*sdl.Renderer); ok { if engine, ok := game.Engine.(*sdl.Renderer); ok {
@ -235,6 +237,10 @@ func main() {
// Initialize the developer shell chatbot easter egg. // Initialize the developer shell chatbot easter egg.
chatbot.Setup() 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() game.Run()
return nil return nil
} }

View File

@ -9,7 +9,7 @@ import (
const ( const (
AppName = "Sketchy Maze" AppName = "Sketchy Maze"
Summary = "A drawing-based maze game" Summary = "A drawing-based maze game"
Version = "0.13.0" Version = "0.13.1"
Website = "https://www.sketchymaze.com" Website = "https://www.sketchymaze.com"
Copyright = "2022 Noah Petherbridge" Copyright = "2022 Noah Petherbridge"
Byline = "a game by Noah Petherbridge." Byline = "a game by Noah Petherbridge."

View File

@ -4,6 +4,7 @@ package cursor
import ( import (
"git.kirsle.net/SketchyMaze/doodle/pkg/balance" "git.kirsle.net/SketchyMaze/doodle/pkg/balance"
"git.kirsle.net/SketchyMaze/doodle/pkg/log" "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/shmem"
"git.kirsle.net/SketchyMaze/doodle/pkg/sprites" "git.kirsle.net/SketchyMaze/doodle/pkg/sprites"
"git.kirsle.net/go/render" "git.kirsle.net/go/render"
@ -22,8 +23,12 @@ var Current *Cursor
// NoCursor hides the cursor entirely. // NoCursor hides the cursor entirely.
var NoCursor = &Cursor{} 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) { func Draw(e render.Engine) {
if native.HasTouchscreen(e) {
return
}
if Current == nil { if Current == nil {
Current = NewPointer(e) Current = NewPointer(e)
} }

View File

@ -89,7 +89,7 @@ func (c *Chunker) MigrateZipfile(zf *zip.Writer) error {
} }
} }
} else { } 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 { if len(c.Chunks) == 0 {

View File

@ -1,3 +1,4 @@
//go:build !js
// +build !js // +build !js
package native package native
@ -14,6 +15,14 @@ import (
// Native render engine functions (SDL2 edition), // Native render engine functions (SDL2 edition),
// not for JavaScript/WASM yet. // 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. TextToImage takes an SDL2_TTF texture and makes it into a Go image.

View File

@ -8,6 +8,10 @@ import (
"git.kirsle.net/go/render" "git.kirsle.net/go/render"
) )
func HasTouchscreen(e render.Engine) bool {
return false
}
func TextToImage(e render.Engine, text render.Text) (image.Image, error) { func TextToImage(e render.Engine, text render.Text) (image.Image, error) {
return nil, errors.New("not supported on WASM") return nil, errors.New("not supported on WASM")
} }

View File

@ -18,6 +18,8 @@ import (
"path/filepath" "path/filepath"
"time" "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/SketchyMaze/doodle/pkg/userdir"
"git.kirsle.net/go/render" "git.kirsle.net/go/render"
) )
@ -53,7 +55,14 @@ var Current = Defaults()
// Defaults returns sensible default user settings. // Defaults returns sensible default user settings.
func Defaults() *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. // Filepath returns the path to the settings file.