Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Implemented code generation using go-bindata to remove external assets
Browse files Browse the repository at this point in the history
  • Loading branch information
eth0net committed Feb 8, 2021
1 parent 3fed258 commit 9608cb6
Show file tree
Hide file tree
Showing 7 changed files with 708 additions and 15 deletions.
9 changes: 9 additions & 0 deletions assets/assets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package assets

import (
// go-bindata required for code generation
_ "github.com/go-bindata/go-bindata"
)

//go:generate go-bindata -pkg=assets ./...
//go:generate gofmt -s -w .
664 changes: 664 additions & 0 deletions assets/bindata.go

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions entities/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package entities

import (
"github.com/EngoEngine/ecs"
"github.com/EngoEngine/engo"
"github.com/EngoEngine/engo/common"
"github.com/raziel2244/magicgame/systems"
)
Expand Down Expand Up @@ -39,12 +38,6 @@ type Player struct {
systems.SpeedComponent
}

// PreloadPlayer preloads the assets required for Player entities.
// Call it in Scene.Preload.
func PreloadPlayer() error {
return engo.Files.Load(spritesheetURL)
}

// NewPlayerOptions provides control
// options when calling NewPlayer.
// type NewPlayerOptions struct {
Expand Down
11 changes: 7 additions & 4 deletions game.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import (

func main() {
opts := engo.RunOptions{
Title: "Magic Game",
Width: 800,
Height: 600,
GlobalScale: engo.Point{X: 2, Y: 2},
Title: "Magic Game",
Width: 800,
Height: 600,
GlobalScale: engo.Point{X: 2, Y: 2},
ApplicationMajorVersion: 0,
ApplicationMinorVersion: 1,
ApplicationRevisionVersion: 0,
}

engo.Run(opts, &scenes.GameScene{})
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/EngoEngine/ecs v1.0.5
github.com/EngoEngine/engo v1.0.5
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-bindata/go-bindata v3.1.2+incompatible
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20201108214237-06ea97f0c265 // indirect
github.com/go-gl/mathgl v1.0.0 // indirect
github.com/hajimehoshi/go-mp3 v0.3.1 // indirect
Expand All @@ -16,6 +17,7 @@ require (
github.com/vulkan-go/vulkan v0.0.0-20201213112254-a536091a798a // indirect
golang.org/x/exp v0.0.0-20210201131500-d352d2db2ceb // indirect
golang.org/x/image v0.0.0-20201208152932-35266b937fa6 // indirect
golang.org/x/mobile v0.0.0-20210208171126-f462b3930c8f // indirect
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
golang.org/x/text v0.3.5 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw=
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down Expand Up @@ -109,10 +111,13 @@ golang.org/x/mobile v0.0.0-20200329125638-4c31acba0007 h1:JxsyO7zPDWn1rBZW8FV5RF
golang.org/x/mobile v0.0.0-20200329125638-4c31acba0007/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4=
golang.org/x/mobile v0.0.0-20201217150744-e6ae53a27f4f h1:kgfVkAEEQXXQ0qc6dH7n6y37NAYmTFmz0YRwrRjgxKw=
golang.org/x/mobile v0.0.0-20201217150744-e6ae53a27f4f/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4=
golang.org/x/mobile v0.0.0-20210208171126-f462b3930c8f h1:aEcjdTsycgPqO/caTgnxfR9xwWOltP/21vtJyFztEy0=
golang.org/x/mobile v0.0.0-20210208171126-f462b3930c8f/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.1.1-0.20191209134235-331c550502dd/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449 h1:xUIPaMhvROX9dhPvRCenIJtU78+lbEenGbgqB5hfHCQ=
golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand Down Expand Up @@ -145,6 +150,7 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200117012304-6edc0a871e69/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa h1:5E4dL8+NgFOgjwbTKz+OOEGGhP+ectTmF842l6KjupQ=
golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
24 changes: 20 additions & 4 deletions scenes/game.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package scenes

import (
"bytes"
"log"

"github.com/EngoEngine/ecs"
"github.com/EngoEngine/engo"
"github.com/EngoEngine/engo/common"
"github.com/raziel2244/magicgame/assets"
"github.com/raziel2244/magicgame/entities"
"github.com/raziel2244/magicgame/systems"
"github.com/raziel2244/magicgame/util"
Expand Down Expand Up @@ -43,11 +45,25 @@ type GameScene struct {

// Preload is called before loading resources.
func (g *GameScene) Preload() {
err := engo.Files.Load(tilemapURL)
if err != nil {
panic(err)
files := []string{
"spritesheets/player.png",
"tilesets/BaseChip.png",
"tilesets/Dirt1.png",
"tilesets/Grass1-Dirt1.png",
"tilesets/Grass1.png",
"tilesets/Water1.png",
"tilemaps/fantasy1-min.tmx",
}
for _, file := range files {
data, err := assets.Asset(file)
if err != nil {
log.Fatalf("Unable to locate asset with URL: %v\n", file)
}
err = engo.Files.LoadReaderData(file, bytes.NewReader(data))
if err != nil {
log.Fatalf("Unable to load asset with URL: %v\n At %v", file, g.Type())
}
}
entities.PreloadPlayer()
}

// Setup is called before the main loop.
Expand Down

0 comments on commit 9608cb6

Please sign in to comment.