mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
examples/keyboard: Embed keyboard.png (#552)
This commit is contained in:
parent
b08f259674
commit
420c4306d0
@ -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
|
||||
}
|
||||
|
||||
|
@ -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{
|
||||
|
6
examples/resources/images/keyboard/keyboard.go
Normal file
6
examples/resources/images/keyboard/keyboard.go
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user