From c78cd38c1d91cd6b30a5d2f07abb6efa37fc9761 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Mon, 28 Dec 2020 18:28:18 -0800 Subject: [PATCH] Add chdir option for Flatpak * The --chdir CLI option to doodle will set a working directory for the game to switch to on startup. Flatpak builds place the files at /app/share/doodle where the ./rtp and ./guidebook files are relative to and this allows the game to find its sound effects and such. --- Building.md | 13 +++++++++++++ cmd/doodle/main.go | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Building.md b/Building.md index 6180462..da5dc8d 100644 --- a/Building.md +++ b/Building.md @@ -1,6 +1,7 @@ # Building Doodle * [Linux](#linux) +* [Flatpak for Linux](#flatpak-for-linux) * [Windows Cross-Compile from Linux](#windows-cross-compile-from-linux) * [Mac OS](#mac os) @@ -16,6 +17,14 @@ You'll need the following git repositories: The [doodle-docker](https://git.kirsle.net/apps/doodle-docker) repo will be more up-to-date than the instructions below. +The `bootstrap.py` script should attempt to git clone most dependencies into a +folder named `deps/` relative to the root of the doodle repo. For example, +`deps/render` would be a git clone of `git.kirsle.net/go/render`. By updating +Doodle's go.mod file to replace these dependencies, you can produce a fully +self-contained source directory that can fully build the app. The +[Flatpak repo](#flatpak-for-linux) makes use of this. Below is how you would +do this process very manually: + ```bash # Clone all the repos down to your project folder git clone git@git.kirsle.net:apps/doodle-rtp rtp @@ -147,6 +156,10 @@ sudo dnf -y install golang SDL2-devel SDL2_ttf-devel SDL2_mixer-devel sudo apt -y install golang libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-devel ``` +## Flatpak for Linux + +The repo for this is at . + ## Mac OS ```bash diff --git a/cmd/doodle/main.go b/cmd/doodle/main.go index c2b8f9d..3b285c8 100644 --- a/cmd/doodle/main.go +++ b/cmd/doodle/main.go @@ -63,6 +63,10 @@ func main() { Aliases: []string{"d"}, Usage: "enable debug level logging", }, + &cli.StringFlag{ + Name: "chdir", + Usage: "working directory for the game's runtime package", + }, &cli.BoolFlag{ Name: "edit", Aliases: []string{"e"}, @@ -84,6 +88,14 @@ func main() { } app.Action = func(c *cli.Context) error { + // --chdir into a different working directory? e.g. for Flatpak especially. + if doodlePath := c.String("chdir"); doodlePath != "" { + if err := os.Chdir(doodlePath); err != nil { + log.Error("--chdir: couldn't enter '%s': %s", doodlePath, err) + return err + } + } + var filename string if c.NArg() > 0 { filename = c.Args().Get(0) @@ -143,6 +155,10 @@ func main() { engine.Maximize() } + // Log what Doodle thinks its working directory is, for debugging. + pwd, _ := os.Getwd() + log.Debug("PWD: %s", pwd) + game.Run() return nil }