mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
examples/keyboard: Embed keyboard.png (#552)
This commit is contained in:
parent
b08f259674
commit
420c4306d0
@ -24,6 +24,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
@ -174,7 +175,7 @@ func outputKeyboardImage() (map[string]image.Rectangle, error) {
|
|||||||
y += height
|
y += height
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.Create(filepath.Join("..", "..", "_resources", "images", "keyboard", "keyboard.png"))
|
f, err := ioutil.TempFile("", "ebiten")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -183,6 +184,17 @@ func outputKeyboardImage() (map[string]image.Rectangle, error) {
|
|||||||
if err := png.Encode(f, img); err != nil {
|
if err := png.Encode(f, img); err != nil {
|
||||||
return nil, err
|
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
|
return keyMap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,13 +17,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "image/png"
|
"bytes"
|
||||||
|
"image/png"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
|
||||||
"github.com/hajimehoshi/ebiten/examples/keyboard/keyboard"
|
"github.com/hajimehoshi/ebiten/examples/keyboard/keyboard"
|
||||||
|
rkeyabord "github.com/hajimehoshi/ebiten/examples/resources/images/keyboard"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -34,11 +35,12 @@ const (
|
|||||||
var keyboardImage *ebiten.Image
|
var keyboardImage *ebiten.Image
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var err error
|
img, err := png.Decode(bytes.NewReader(rkeyabord.Keyboard_png))
|
||||||
keyboardImage, _, err = ebitenutil.NewImageFromFile("_resources/images/keyboard/keyboard.png", ebiten.FilterDefault)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keyboardImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
||||||
}
|
}
|
||||||
|
|
||||||
var keyNames = map[ebiten.Key]string{
|
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