Use the library style of file2byteslice

This commit is contained in:
Hajime Hoshi 2020-08-14 00:44:04 +09:00
parent e96a1fb1c7
commit d73472f4f2
6 changed files with 36 additions and 27 deletions

View File

@ -17,6 +17,7 @@
package main
import (
"bytes"
"errors"
"image"
"image/color"
@ -24,11 +25,11 @@ import (
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"text/template"
"github.com/golang/freetype/truetype"
"github.com/hajimehoshi/file2byteslice"
"golang.org/x/image/font"
"github.com/hajimehoshi/ebiten"
@ -237,26 +238,20 @@ func outputKeyboardImage() (map[ebiten.Key]image.Rectangle, error) {
y += height
}
f, err := ioutil.TempFile("", "ebiten")
var buf bytes.Buffer
if err := png.Encode(&buf, img); err != nil {
return nil, err
}
out, err := os.Create("../../resources/images/keyboard/keyboard.go")
if err != nil {
return nil, err
}
defer f.Close()
defer out.Close()
if err := png.Encode(f, img); err != nil {
if err := file2byteslice.Write(out, &buf, false, "", "keyboard", "Keyboard_png"); 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

@ -44,3 +44,11 @@
//go:generate gofmt -s -w .
package resources
import (
// Dummy imports for go.mod for some Go files with 'ignore' tags. For example, `go mod tidy` does not
// recognize Go files with 'ignore' build tag.
//
// Note that this affects only importing this package, but not 'file2byteslice' commands in //go:generate.
_ "github.com/hajimehoshi/file2byteslice"
)

View File

@ -1,5 +1,4 @@
// Code generated by file2byteslice. DO NOT EDIT.
// (gofmt is fine after generating)
package keyboard

1
go.mod
View File

@ -7,6 +7,7 @@ require (
github.com/gofrs/flock v0.7.1
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/hajimehoshi/bitmapfont v1.2.0
github.com/hajimehoshi/file2byteslice v0.0.0-20200812174855-0e5e8a80490e
github.com/hajimehoshi/go-mp3 v0.3.0
github.com/hajimehoshi/oto v0.6.3
github.com/jakecoffman/cp v1.0.0

3
go.sum
View File

@ -7,6 +7,8 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF0
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/hajimehoshi/bitmapfont v1.2.0 h1:hw6OjRGdgmHUe56BPju/KU/QD/KLOiTQ+6t+TJpfSfU=
github.com/hajimehoshi/bitmapfont v1.2.0/go.mod h1:h9QrPk6Ktb2neObTlAbma6Ini1xgMjbJ3w7ysmD7IOU=
github.com/hajimehoshi/file2byteslice v0.0.0-20200812174855-0e5e8a80490e h1:4IP7CPObI35+mQShFOYg2JMHDJKciLTW5599inhFfkA=
github.com/hajimehoshi/file2byteslice v0.0.0-20200812174855-0e5e8a80490e/go.mod h1:CqqAHp7Dk/AqQiwuhV1yT2334qbA/tFWQW0MD2dGqUE=
github.com/hajimehoshi/go-mp3 v0.3.0 h1:fTM5DXjp/DL2G74HHAs/aBGiS9Tg7wnp+jkU38bHy4g=
github.com/hajimehoshi/go-mp3 v0.3.0/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
github.com/hajimehoshi/oto v0.6.1 h1:7cJz/zRQV4aJvMSSRqzN2TImoVVMpE0BCY4nrNJaDOM=
@ -53,6 +55,7 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -24,6 +24,7 @@ import (
"sort"
"strings"
"github.com/hajimehoshi/file2byteslice"
"golang.org/x/sync/errgroup"
)
@ -106,18 +107,20 @@ func run() error {
return err
}
args = []string{
"-input",
dll,
"-output",
fmt.Sprintf("glfwdll_windows_%s.go", arch),
"-package",
"glfw",
"-var",
"glfwDLLCompressed",
"-compress",
in, err := os.Open(dll)
if err != nil {
return err
}
if err := execCommand("file2byteslice", args...); err != nil {
defer in.Close()
out, err := os.Create(fmt.Sprintf("glfwdll_windows_%s.go", arch))
if err != nil {
return err
}
defer out.Close()
// As the file name already specified the build environment, buildtags are not requried.
if err := file2byteslice.Write(out, in, true, "", "glfw", "glfwDLLCompressed"); err != nil {
return err
}