examples/keyboard/keyboard: use go:embed

Updates #1258
This commit is contained in:
Hajime Hoshi 2022-09-15 22:45:30 +09:00
parent 5404e4d68a
commit 6e6145541d
3 changed files with 23 additions and 13 deletions

View File

@ -18,13 +18,11 @@
package main package main
import ( import (
"bytes"
"image" "image"
"image/color" "image/color"
"image/png" "image/png"
"log" "log"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"text/template" "text/template"
@ -234,18 +232,13 @@ func outputKeyboardImage() (map[ebiten.Key]image.Rectangle, error) {
y += height y += height
} }
var buf bytes.Buffer out, err := os.Create(filepath.Join("..", "..", "resources", "images", "keyboard", "keyboard.png"))
if err := png.Encode(&buf, img); err != nil { if err != nil {
return nil, err return nil, err
} }
defer out.Close()
cmd := exec.Command("go", "run", "github.com/hajimehoshi/file2byteslice/cmd/file2byteslice@v1.0.0", if err := png.Encode(out, img); err != nil {
"-output", "../../resources/images/keyboard/keyboard.go",
"-package", "keyboard",
"-var", "Keyboard_png")
cmd.Stdin = &buf
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return nil, err return nil, err
} }

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB