examples/keyboard: Embed keyboard.png (#552)

This commit is contained in:
Hajime Hoshi 2018-03-14 04:04:29 +09:00
parent b08f259674
commit 420c4306d0
3 changed files with 25 additions and 5 deletions

View File

@ -24,6 +24,7 @@ import (
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"text/template"
@ -174,7 +175,7 @@ func outputKeyboardImage() (map[string]image.Rectangle, error) {
y += height
}
f, err := os.Create(filepath.Join("..", "..", "_resources", "images", "keyboard", "keyboard.png"))
f, err := ioutil.TempFile("", "ebiten")
if err != nil {
return nil, err
}
@ -183,6 +184,17 @@ func outputKeyboardImage() (map[string]image.Rectangle, error) {
if err := png.Encode(f, img); err != nil {
return nil, err
}
args := []string{
"-package=keyboard",
"-input=" + f.Name(),
"-output=../../resources/images/keyboard/keyboard.go",
"-var=Keyboard_png",
}
if err := exec.Command("file2byteslice", args...).Run(); err != nil {
return nil, err
}
return keyMap, nil
}

View File

@ -17,13 +17,14 @@
package main
import (
_ "image/png"
"bytes"
"image/png"
"log"
"strconv"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil"
"github.com/hajimehoshi/ebiten/examples/keyboard/keyboard"
rkeyabord "github.com/hajimehoshi/ebiten/examples/resources/images/keyboard"
)
const (
@ -34,11 +35,12 @@ const (
var keyboardImage *ebiten.Image
func init() {
var err error
keyboardImage, _, err = ebitenutil.NewImageFromFile("_resources/images/keyboard/keyboard.png", ebiten.FilterDefault)
img, err := png.Decode(bytes.NewReader(rkeyabord.Keyboard_png))
if err != nil {
log.Fatal(err)
}
keyboardImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
}
var keyNames = map[ebiten.Key]string{

File diff suppressed because one or more lines are too long