From ffb38876a01e54a7582f0c16a009b58c99155e4d Mon Sep 17 00:00:00 2001
From: Denis GERMAIN
Date: Mon, 31 Jul 2023 15:58:55 +0200
Subject: [PATCH] chore: add diary
---
developpement_diary/2023-07-31.md | 76 ++++++++++++++++++++++++++++++-
1 file changed, 75 insertions(+), 1 deletion(-)
diff --git a/developpement_diary/2023-07-31.md b/developpement_diary/2023-07-31.md
index f2b1553..104e46d 100644
--- a/developpement_diary/2023-07-31.md
+++ b/developpement_diary/2023-07-31.md
@@ -1,3 +1,77 @@
## 2023-07-31
-Fixed a few open issues
\ No newline at end of file
+Since a big milestone has been delivered yesterday (save/load game), today I started by fixing a few open issues in order to limit the "backlog".
+
+[Following this documentation (cross-compiling)](https://developer.fyne.io/started/cross-compiling), I was able understand why I couldn't build ARM64, windows or darwin targets. For each GOOS/GOARCH, you need to use a specific compiler and other prerequisites (like macOS SDK). If I want to use goreleaser (like I was starting to do), I'll need to download a lot of things...
+
+Hopefully, there is a way to create packaged files automagically by installing fyne-cross. I was also able to generate both a AMD64 and ARM64 binary for linux, which is cool since ARM64 was not working on my machine, and a windows .exe binary as well.
+
+```console
+go install github.com/fyne-io/fyne-cross@latest
+~/go/bin/fyne-cross windows -app-id fr.zwindler.gocastle
+~/go/bin/fyne-cross linux -arch=amd64,arm64 -app-id fr.zwindler.gocastle
+```
+
+For darwin, I get an error saying that you need a macOSX SDK path. That's a bit weird since fyne-cross should have everything it needs...
+
+> The tool recommended by the Fyne developers is fyne-cross. It has been inspired by xgo and uses a docker image built on top of the golang-cross image, that includes the MinGW compiler for windows, and a macOS SDK, along with the Fyne requirements.
+
+Taking a look at [fyne-cross](https://github.com/fyne-io/fyne-cross) github repository gave me the reason:
+
+> cross-compile from NOT darwin (i.e. linux) to darwin: requires a copy of the macOS SDK on the host. The fyne-cross darwin-sdk-extractor command can be used to extract the SDK from the XCode CLI Tool file
+
+But what surprised me even more is that fyne can also build Android APKs!
+
+```console
+~/go/bin/fyne-cross android -arch=arm64 -app-id fr.zwindler.gocastle
+```
+
+I hit a little issue as all my programs built this way where crashing when opening the game screen. This is maybe related to the fact that ALL images are missing from binary. I have to find how to include all static files INSIDE the game binary.
+
+See
+* https://stackoverflow.com/questions/17796043/how-to-embed-files-into-go-binaries
+* https://pkg.go.dev/embed@master
+
+So I create a new package called "utils/", in wich I move the whole static folder. I then created a new utils/embed.go file:
+
+```go
+package utils
+
+import (
+ "embed"
+ "image"
+ "image/png"
+ "log"
+)
+
+//go:embed static/*
+var EmbeddedImages embed.FS
+
+func GetImageFromEmbed(path string) image.Image {
+ // Read the embedded image file
+ file, err := EmbeddedImages.Open(path)
+ if err != nil {
+ log.Fatal("Error opening embedded image:", err)
+ }
+ defer file.Close()
+
+ // Decode the image using the png package
+ img, err := png.Decode(file)
+ if err != nil {
+ log.Fatal("Error decoding embedded image:", err)
+ }
+
+ return img
+}
+```
+
+I then had to replace all the calls opening images like this:
+
+```diff
+- backgroundImage := canvas.NewImageFromFile("static/castle_back.png")
++ backgroundImage := canvas.NewImageFromImage(utils.GetImageFromEmbed("static/castle_back.png"))
+```
+
+The modification app wide was relatively easy, it fits in this little commit 4cf7cd89a6e5f1cbb8e83eb2e1910f16e61c3ec7
+
+Now, linux and android app (YES) are working. You can't do anything with the android app though because screen isn't designed to fit the smartphone format and you'd need a keyboard. But this feels incredible...
\ No newline at end of file