Replaced go/embed with rice again.
This commit is contained in:
parent
9991c5a6f0
commit
4ee8fd52d1
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
.vscode/launch.json
|
||||
|
||||
scripts/build
|
||||
cmd/tins2021/rice-box.go
|
||||
|
26
README.md
26
README.md
@ -19,6 +19,7 @@
|
||||
* [go-colurful](###go-colurful)
|
||||
* [resize](###resize)
|
||||
* [testify](###testify)
|
||||
* [go.rice](###rice)
|
||||
|
||||
## Introduction
|
||||
|
||||
@ -387,3 +388,28 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
### rice
|
||||
|
||||
Copyright (c) 2013, Geert-Johan Riemer
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
@ -16,10 +16,10 @@ type appContext struct {
|
||||
}
|
||||
|
||||
func newAppContext(ctx ui.Context, setView func(ui.Control)) *appContext {
|
||||
newAnimatedTexture(ctx, "star", "resources/images/star.png", func() image.Image {
|
||||
newAnimatedTexture(ctx, "star", "images/star.png", func() image.Image {
|
||||
return tins2021.AnimatePolygon(tins2021.CreateStar(5), tins2021.Yellow, tins2021.NewRotateAnimation(defaultAnimationFrames))
|
||||
})
|
||||
newAnimatedTexture(ctx, "heart", "resources/images/heart.png", func() image.Image {
|
||||
newAnimatedTexture(ctx, "heart", "images/heart.png", func() image.Image {
|
||||
return tins2021.AnimatePolygon(tins2021.CreateHeart(), tins2021.Red, tins2021.NewRotateAnimation(defaultAnimationFrames))
|
||||
})
|
||||
|
||||
@ -31,13 +31,13 @@ func newAppContext(ctx ui.Context, setView func(ui.Control)) *appContext {
|
||||
tins2021.MonsterTypeChaser: "chasing-monster",
|
||||
},
|
||||
}
|
||||
newAnimatedTexture(ctx, app.MonsterTextureNames[tins2021.MonsterTypeStraight], "resources/images/monster-straight.png", func() image.Image {
|
||||
newAnimatedTexture(ctx, app.MonsterTextureNames[tins2021.MonsterTypeStraight], "images/monster-straight.png", func() image.Image {
|
||||
return tins2021.AnimatePolygon(tins2021.CreateHexagon(), tins2021.Green, tins2021.NewWobbleAnimation(defaultAnimationFrames, 30))
|
||||
})
|
||||
newAnimatedTexture(ctx, app.MonsterTextureNames[tins2021.MonsterTypeRandom], "resources/images/monster-random.png", func() image.Image {
|
||||
newAnimatedTexture(ctx, app.MonsterTextureNames[tins2021.MonsterTypeRandom], "images/monster-random.png", func() image.Image {
|
||||
return tins2021.AnimatePolygon(tins2021.CreateHexagon(), tins2021.Blue, tins2021.NewWobbleAnimation(defaultAnimationFrames, 30))
|
||||
})
|
||||
newAnimatedTexture(ctx, app.MonsterTextureNames[tins2021.MonsterTypeChaser], "resources/images/monster-chaser.png", func() image.Image {
|
||||
newAnimatedTexture(ctx, app.MonsterTextureNames[tins2021.MonsterTypeChaser], "images/monster-chaser.png", func() image.Image {
|
||||
return tins2021.AnimatePolygon(tins2021.CreateHexagon(), tins2021.Purple, tins2021.NewWobbleAnimation(defaultAnimationFrames, 30))
|
||||
})
|
||||
return app
|
||||
|
@ -58,6 +58,8 @@ func newCredits(app *appContext, ctx ui.Context) *credits {
|
||||
" - https://github.com/nfnt/resize", "",
|
||||
"testify: a testing library for Go",
|
||||
" - https://github.com/stretchr/testify", "",
|
||||
"rice: a library for embedding files in Go",
|
||||
" - https://github.com/GeertJohan/go.rice", "",
|
||||
"",
|
||||
"# THANKS",
|
||||
"",
|
||||
|
@ -1,11 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
rice "github.com/GeertJohan/go.rice"
|
||||
)
|
||||
|
||||
func copyFile(path string, file fs.File) error {
|
||||
@ -20,19 +21,19 @@ func copyFile(path string, file fs.File) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func copyBoxToDisk(resources embed.FS) error {
|
||||
return fs.WalkDir(resources, "", func(path string, entry fs.DirEntry, err error) error {
|
||||
func copyBoxToDisk() error {
|
||||
box := rice.MustFindBox(`resources`)
|
||||
return box.Walk("", func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if entry.IsDir() {
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
src, err := resources.Open(path)
|
||||
src, err := box.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer src.Close()
|
||||
return copyFile(filepath.Join(`resources`, path), src)
|
||||
return copyFile(filepath.Join(box.Name(), path), src)
|
||||
})
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"flag"
|
||||
"image/color"
|
||||
"log"
|
||||
|
||||
rice "github.com/GeertJohan/go.rice"
|
||||
"opslag.de/schobers/geom"
|
||||
"opslag.de/schobers/tins2021"
|
||||
"opslag.de/schobers/zntg"
|
||||
"opslag.de/schobers/zntg/addons/embedres"
|
||||
"opslag.de/schobers/zntg/addons/riceres"
|
||||
"opslag.de/schobers/zntg/ui"
|
||||
)
|
||||
|
||||
//go:embed resources/*
|
||||
var resources embed.FS
|
||||
//go:generate go get -u github.com/GeertJohan/go.rice/rice
|
||||
//go:generate rice embed
|
||||
|
||||
func main() {
|
||||
err := run()
|
||||
@ -24,8 +24,9 @@ func main() {
|
||||
}
|
||||
|
||||
func openResources() ui.Resources {
|
||||
embedded := embedres.New(resources)
|
||||
return ui.NewFallbackResources(ui.NewPathResources(nil, `resources`), embedded)
|
||||
box := rice.MustFindBox(`resources`)
|
||||
embedded := riceres.New(box)
|
||||
return ui.NewFallbackResources(ui.NewPathResources(nil, box.Name()), embedded)
|
||||
}
|
||||
|
||||
func run() error {
|
||||
@ -34,7 +35,7 @@ func run() error {
|
||||
flag.Parse()
|
||||
|
||||
if extract {
|
||||
return copyBoxToDisk(resources)
|
||||
return copyBoxToDisk()
|
||||
}
|
||||
res := openResources()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user