mirror of
https://github.com/BigJk/end_of_eden.git
synced 2026-02-06 10:48:09 +00:00
Allow loadable images in mods.
This commit is contained in:
parent
71e915e7ce
commit
0f9987d305
@ -268,6 +268,10 @@ func (s *Session) GetResources() *ResourcesManager {
|
||||
return s.resources
|
||||
}
|
||||
|
||||
func (s *Session) GetLoadedMods() []string {
|
||||
return s.loadedMods
|
||||
}
|
||||
|
||||
//
|
||||
// Internal
|
||||
//
|
||||
|
||||
@ -1,12 +1,30 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/BigJk/imeji"
|
||||
"github.com/BigJk/imeji/charmaps"
|
||||
"github.com/muesli/termenv"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// TODO: Better decoupling in relation to session
|
||||
|
||||
var searchPaths []string
|
||||
|
||||
func init() {
|
||||
ResetSearchPaths()
|
||||
}
|
||||
|
||||
func AddSearchPaths(paths ...string) {
|
||||
searchPaths = append(searchPaths, paths...)
|
||||
}
|
||||
|
||||
func ResetSearchPaths() {
|
||||
searchPaths = []string{"./assets/images/"}
|
||||
}
|
||||
|
||||
// Fetch fetches an image from ./assets/images and converts it to an ansi string.
|
||||
//
|
||||
// env EOE_IMG_SIMPLE = 1: Forces the usage of a simpler character set. Can be used for stock cmd on windows.
|
||||
@ -29,9 +47,11 @@ func Fetch(name string, options ...imeji.Option) (string, error) {
|
||||
options = append(options, imeji.WithTrueColor())
|
||||
}
|
||||
|
||||
res, err := imeji.FileString("./assets/images/"+name, options...)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for i := range searchPaths {
|
||||
res, err := imeji.FileString(filepath.Join(searchPaths[i], name), options...)
|
||||
if err == nil {
|
||||
return res, nil
|
||||
}
|
||||
}
|
||||
return res, nil
|
||||
return "", errors.New("could not load image")
|
||||
}
|
||||
|
||||
@ -16,3 +16,21 @@ register_enemy(
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
register_event("TEST_EVENT", {
|
||||
name = "Test Test",
|
||||
description = [[!!mod_test.png
|
||||
|
||||
Testing loading a image from mod folder.]],
|
||||
choices = {
|
||||
{
|
||||
description = "Go...",
|
||||
callback = function()
|
||||
return nil
|
||||
end
|
||||
}
|
||||
},
|
||||
on_end = function()
|
||||
return GAME_STATE_RANDOM
|
||||
end
|
||||
})
|
||||
BIN
mods/example_mod/images/mod_test.png
Normal file
BIN
mods/example_mod/images/mod_test.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 236 KiB |
@ -1,6 +1,7 @@
|
||||
package mainmenu
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/BigJk/end_of_eden/audio"
|
||||
"github.com/BigJk/end_of_eden/game"
|
||||
"github.com/BigJk/end_of_eden/image"
|
||||
@ -75,6 +76,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
game.WithLogging(log.New(f, "SESSION ", log.Ldate|log.Ltime|log.Lshortfile)),
|
||||
lo.Ternary(os.Getenv("EOE_DEBUG") == "1", game.WithDebugEnabled(8272), nil),
|
||||
)
|
||||
image.ResetSearchPaths()
|
||||
image.AddSearchPaths(lo.Map(session.GetLoadedMods(), func(item string, index int) string {
|
||||
return fmt.Sprintf("./mods/%s/images/", item)
|
||||
})...)
|
||||
|
||||
err = session.GobDecode(saved)
|
||||
if err != nil {
|
||||
@ -94,6 +99,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
image.ResetSearchPaths()
|
||||
image.AddSearchPaths(lo.Map(settings.LoadedSettings.Mods, func(item string, index int) string {
|
||||
return fmt.Sprintf("./mods/%s/images/", item)
|
||||
})...)
|
||||
|
||||
m.choices = m.choices.Clear()
|
||||
return m, root.Push(gameview.New(m, m.zones, game.NewSession(
|
||||
game.WithLogging(log.New(f, "SESSION ", log.Ldate|log.Ltime|log.Lshortfile)),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user