From 2f5de3c2c15f345ec024234c58af6cf1d0bb7e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Antonio=20Pinochet=20Olave?= Date: Wed, 26 Jun 2024 18:36:09 -0400 Subject: [PATCH 1/2] Fix Windows file paths with embbeded FS (https://github.com/lafriks/go-tiled/issues/63) --- render/renderer.go | 7 ++++--- tiled.go | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/render/renderer.go b/render/renderer.go index 17f3a99..2058502 100644 --- a/render/renderer.go +++ b/render/renderer.go @@ -33,6 +33,7 @@ import ( "io" "io/fs" "os" + "path/filepath" "github.com/disintegration/imaging" "github.com/lafriks/go-tiled" @@ -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) { diff --git a/tiled.go b/tiled.go index 6748ab2..dbfc924 100644 --- a/tiled.go +++ b/tiled.go @@ -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 From eb3b66fbbcf9587f100d4a9529df12faa3d7cb46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Antonio=20Pinochet=20Olave?= Date: Wed, 26 Jun 2024 18:43:52 -0400 Subject: [PATCH 2/2] Fix linter --- tmx_wangset.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tmx_wangset.go b/tmx_wangset.go index 79445c3..1d44e78 100644 --- a/tmx_wangset.go +++ b/tmx_wangset.go @@ -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") @@ -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 {