package asset

import (
	_ "image/png"

	"log"

	"edgaru089.ink/go/gl01/internal/util"
)

// 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*/ )
}
