diff --git a/adapters/main.go b/adapters/main.go
index 7a17e68..80f31c1 100644
--- a/adapters/main.go
+++ b/adapters/main.go
@@ -3,0 +4 @@ import (
+ "fmt"
@@ -44,0 +46 @@ func (a *Adapter) LoadTexture(id, t, key string, texture image.Image) {
+ fmt.Println("load", id, t)
@@ -54,0 +57 @@ func (a *Adapter) UnloadTexture(id, t string) {
+ fmt.Println("unload", id, t)
package adapter
import (
"grim/element"
"image"
"os"
"path/filepath"
)
type Adapter struct {
Init func(width int, height int)
Render func(state []element.State)
Load func(key string, texture image.Image)
Unload func(key string)
events map[string][]func(element.Event)
FileSystem FileSystem
// id -> type -> key
Textures map[string]map[string]string
}
func Init() {}
// Only render complex
func RenderType() {}
func (a *Adapter) AddEventListener(name string, callback func(element.Event)) {
if a.events == nil {
a.events = map[string][]func(element.Event){}
}
a.events[name] = append(a.events[name], callback)
}
func (a *Adapter) DispatchEvent(event element.Event) {
if a.events != nil {
evts := a.events[event.Name]
for _, v := range evts {
v(event)
}
}
}
// !ISSUE: Make a init function
func (a *Adapter) LoadTexture(id, t, key string, texture image.Image) {
a.Load(key, texture)
if a.Textures == nil {
a.Textures = map[string]map[string]string{}
}
if a.Textures[id] == nil {
a.Textures[id] = map[string]string{}
}
a.Textures[id][t] = key
}
func (a *Adapter) UnloadTexture(id, t string) {
a.Unload(a.Textures[id][t])
delete(a.Textures[id], t)
if len(a.Textures[id]) == 0 {
delete(a.Textures[id], t)
}
}
type FileSystem struct {
Paths []string
Sources []string
ReadFile func(path string) ([]byte, error)
WriteFile func(path string, data []byte)
}
func (fs *FileSystem) AddFile(path string) {
fs.Paths = append(fs.Paths, path)
}
// !ISSUE: Breaks fs rules
func (fs *FileSystem) AddDir(path string) error {
// Walk through the directory and collect all file paths
fs.Sources = append(fs.Sources, path)
err := filepath.Walk(path, func(filePath string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() { // Only add files, not directories
fs.Paths = append(fs.Paths, filePath)
}
return nil
})
return err
}