Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows file paths with embbeded FS #90

Merged
merged 2 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions render/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"io"
"io/fs"
"os"
"path/filepath"

"github.com/disintegration/imaging"
"github.com/lafriks/go-tiled"
Expand Down Expand Up @@ -86,10 +87,10 @@ func NewRendererWithFileSystem(m *tiled.Map, fs fs.FS) (*Renderer, error) {
}

func (r *Renderer) open(f string) (io.ReadCloser, error) {
if r.fs != nil {
return r.fs.Open(f)
if r.fs == nil {
return os.Open(filepath.FromSlash(f))
}
return os.Open(f)
return r.fs.Open(filepath.ToSlash(f))
}

func (r *Renderer) getTileImage(tile *tiled.LayerTile) (image.Image, error) {
Expand Down
4 changes: 2 additions & 2 deletions tiled.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func newLoader(options ...LoaderOption) *loader {
// if l or l.FileSystem is nil.
func (l *loader) open(name string) (fs.File, error) {
if l == nil || l.FileSystem == nil {
return os.Open(name)
return os.Open(filepath.FromSlash(name))
}
return l.FileSystem.Open(name)
return l.FileSystem.Open(filepath.ToSlash(name))
}

// WithFileSystem returns an option to load level from a passed filesystem
Expand Down
10 changes: 5 additions & 5 deletions tmx_wangset.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ func (w *WangSet) GetWangColors(tileID uint32) (map[WangPosition]*WangColor, err
}

// convert from CSV to array of strings
wangIdsString := strings.Split(tile.WangID, ",")
wangIDsString := strings.Split(tile.WangID, ",")

// convert from array of strings to slice of uint32
var wangIds []uint32 // will contain a slice of the wangIds
for _, v := range wangIdsString {
var wangIDs []uint32 // will contain a slice of the wangIDs
for _, v := range wangIDsString {
id64, err := strconv.ParseUint(v, 10, 32)
if err != nil {
return nil, errors.New("internal error")
Expand All @@ -112,12 +112,12 @@ func (w *WangSet) GetWangColors(tileID uint32) (map[WangPosition]*WangColor, err
// uint64 to uint32
id := uint32(id64)

wangIds = append(wangIds, id)
wangIDs = append(wangIDs, id)
}

wangColors := make(map[WangPosition]*WangColor)

for i, id := range wangIds {
for i, id := range wangIDs {
if id == 0 { // no color assigned if id is 0, set to nil
wangColors[WangPosition(i)] = nil
} else {
Expand Down
Loading