gl01/internal/asset/texture.go

44 lines
803 B
Go
Raw Permalink Normal View History

2022-01-20 21:58:50 +08:00
package asset
import (
_ "image/png"
"log"
"edgaru089.ink/go/gl01/internal/util"
2022-01-20 21:58:50 +08:00
)
// WorldTextureAtlas holds all the world block textures.
var WorldTextureAtlas util.Atlas
func InitWorldTextureAtlas() {
if WorldTextureAtlas.HasBuilt() {
return
}
files, err := FS.ReadDir("texture/world")
if err != nil {
panic("InitWorldTextureAtlas: embed.FS.ReadDir(\"texture/world\"): " + err.Error())
}
for _, f := range files {
if f.IsDir() {
continue
}
name := f.Name()
file, err := FS.Open("texture/world/" + name)
if err != nil { // Shouldn't be error?
panic(err)
}
err = WorldTextureAtlas.AddFile(name, file)
if err != nil {
log.Printf("WARN: InitWorldTextureAtlas: img %s failed to decode: %s", name, err)
}
}
WorldTextureAtlas.BuildTexture( /*false*/ )
}