added implementation in GO lang

This commit is contained in:
2026-05-22 13:00:28 +02:00
parent 67ee6c268c
commit ddac1d02cd
21 changed files with 1447 additions and 0 deletions

View File

@ -0,0 +1,49 @@
package assets
import (
"image"
_ "image/jpeg"
_ "image/png"
"os"
"path/filepath"
"github.com/hajimehoshi/ebiten/v2"
)
type Manager struct {
images map[string]*ebiten.Image
misses map[string]bool
}
func NewManager() *Manager {
return &Manager{
images: map[string]*ebiten.Image{},
misses: map[string]bool{},
}
}
func (m *Manager) Image(path string) (*ebiten.Image, bool) {
path = filepath.Clean(path)
if img, ok := m.images[path]; ok {
return img, true
}
if m.misses[path] {
return nil, false
}
f, err := os.Open(path)
if err != nil {
m.misses[path] = true
return nil, false
}
defer f.Close()
src, _, err := image.Decode(f)
if err != nil {
m.misses[path] = true
return nil, false
}
img := ebiten.NewImageFromImage(src)
m.images[path] = img
return img, true
}