diff --git a/adapters/main.go b/adapters/main.go
index e6ea5cd..c31ced3 100644
--- a/adapters/main.go
+++ b/adapters/main.go
@@ -4 +3,0 @@ import (
- "fmt"
@@ -6 +5 @@ import (
- "image"
+ "grim/library"
@@ -14,2 +13 @@ type Adapter struct {
- Load func(key string, texture image.Image)
- Unload func(key string)
+ Load func(state []element.State)
@@ -16,0 +15 @@ type Adapter struct {
+ Library *library.Shelf
@@ -18,2 +16,0 @@ type Adapter struct {
- // id -> type -> key
- Textures map[string]map[string]string
@@ -38,19 +34,0 @@ func (a *Adapter) DispatchEvent(event element.Event) {
-// !ISSUE: Make a init function
-func (a *Adapter) LoadTexture(id, t, key string, texture image.Image) {
- a.Load(key, texture)
- fmt.Println(id, t)
- 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) {
- fmt.Println(id, t)
- a.Unload(a.Textures[id][t])
- delete(a.Textures[id], t)
-}
-
package adapter
import (
"fmt"
"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 (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)
fmt.Println(id, t)
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) {
fmt.Println(id, t)
a.Unload(a.Textures[id][t])
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
}