From 80e4ee0998df65e1da217683f1ab1acf0787ba20 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 29 Jan 2018 23:36:44 +0900 Subject: [PATCH] ebitenutil: Remove JoinStringsIntoPath; Always use slash for ebitenutil.OpenFile #428 --- ebitenutil/file_js.go | 5 ----- ebitenutil/file_notjs.go | 14 +++----------- examples/2048/2048/tile.go | 2 +- examples/additive/main.go | 2 +- examples/airship/main.go | 2 +- examples/alphablending/main.go | 2 +- examples/audio/main.go | 4 ++-- examples/blocks/blocks/font.go | 2 +- examples/blocks/blocks/gamescene.go | 2 +- examples/blocks/blocks/piece.go | 2 +- examples/blocks/blocks/titlescene.go | 2 +- examples/flood/main.go | 2 +- examples/hsv/main.go | 2 +- examples/hue/main.go | 2 +- examples/infinitescroll/main.go | 2 +- examples/keyboard/main.go | 2 +- examples/masking/main.go | 4 ++-- examples/mosaic/main.go | 2 +- examples/perspective/main.go | 2 +- examples/piano/main.go | 2 +- examples/platformer/main.go | 8 ++++---- examples/rotate/main.go | 2 +- examples/sprites/main.go | 2 +- examples/ui/main.go | 2 +- examples/wav/main.go | 2 +- examples/windowsize/main.go | 2 +- 26 files changed, 32 insertions(+), 45 deletions(-) diff --git a/ebitenutil/file_js.go b/ebitenutil/file_js.go index 820edf6b4..943669e47 100644 --- a/ebitenutil/file_js.go +++ b/ebitenutil/file_js.go @@ -20,7 +20,6 @@ import ( "bytes" "errors" "fmt" - "path" "github.com/gopherjs/gopherjs/js" ) @@ -63,7 +62,3 @@ func OpenFile(path string) (ReadSeekCloser, error) { f := &file{bytes.NewReader(data)} return f, nil } - -func JoinStringsIntoFilePath(elems ...string) string { - return path.Join(elems...) -} diff --git a/ebitenutil/file_notjs.go b/ebitenutil/file_notjs.go index f045de2b4..2a742a488 100644 --- a/ebitenutil/file_notjs.go +++ b/ebitenutil/file_notjs.go @@ -26,17 +26,9 @@ import ( // OpenFile opens a file and returns a stream for its data. // -// How to solve path depends on your environment. This varies on your desktop or web browser. +// The path parts should be separated with slash '/' on any environments. +// // Note that this doesn't work on mobiles. func OpenFile(path string) (ReadSeekCloser, error) { - return os.Open(path) -} - -// JoinStringsIntoFilePath joins any number of path elements into a single path, -// adding a Separator if necessary. -// -// This is basically same as filepath.Join, but the behavior is different on JavaScript. -// For browsers, path.Join is called instead of filepath.Join. -func JoinStringsIntoFilePath(elems ...string) string { - return filepath.Join(elems...) + return os.Open(filepath.FromSlash(path)) } diff --git a/examples/2048/2048/tile.go b/examples/2048/2048/tile.go index 0ade83bac..71b0e420d 100644 --- a/examples/2048/2048/tile.go +++ b/examples/2048/2048/tile.go @@ -40,7 +40,7 @@ var ( ) func init() { - f, err := ebitenutil.OpenFile(ebitenutil.JoinStringsIntoFilePath("_resources", "fonts", "mplus-1p-regular.ttf")) + f, err := ebitenutil.OpenFile("_resources/fonts/mplus-1p-regular.ttf") if err != nil { log.Fatal(err) } diff --git a/examples/additive/main.go b/examples/additive/main.go index c3c945c87..781837492 100644 --- a/examples/additive/main.go +++ b/examples/additive/main.go @@ -64,7 +64,7 @@ func update(screen *ebiten.Image) error { func main() { var err error - ebitenImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "ebiten.png"), ebiten.FilterNearest) + ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest) if err != nil { log.Fatal(err) } diff --git a/examples/airship/main.go b/examples/airship/main.go index 3e93f0fe8..5d619f866 100644 --- a/examples/airship/main.go +++ b/examples/airship/main.go @@ -51,7 +51,7 @@ var ( func init() { var err error - gophersImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterNearest) + gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) if err != nil { panic(err) } diff --git a/examples/alphablending/main.go b/examples/alphablending/main.go index 2256546c2..1c3bf11c1 100644 --- a/examples/alphablending/main.go +++ b/examples/alphablending/main.go @@ -67,7 +67,7 @@ func update(screen *ebiten.Image) error { func main() { var err error - ebitenImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "ebiten.png"), ebiten.FilterNearest) + ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest) if err != nil { log.Fatal(err) } diff --git a/examples/audio/main.go b/examples/audio/main.go index a94766757..a21a41055 100644 --- a/examples/audio/main.go +++ b/examples/audio/main.go @@ -105,11 +105,11 @@ func playerBarRect() (x, y, w, h int) { func NewPlayer(audioContext *audio.Context) (*Player, error) { const bytesPerSample = 4 // TODO: This should be defined in audio package - wavF, err := ebitenutil.OpenFile(ebitenutil.JoinStringsIntoFilePath("_resources", "audio", "jab.wav")) + wavF, err := ebitenutil.OpenFile("_resources/audio/jab.wav") if err != nil { return nil, err } - mp3F, err := ebitenutil.OpenFile(ebitenutil.JoinStringsIntoFilePath("_resources", "audio", "classic.mp3")) + mp3F, err := ebitenutil.OpenFile("_resources/audio/classic.mp3") if err != nil { return nil, err } diff --git a/examples/blocks/blocks/font.go b/examples/blocks/blocks/font.go index 3552d4bad..5aab6d754 100644 --- a/examples/blocks/blocks/font.go +++ b/examples/blocks/blocks/font.go @@ -39,7 +39,7 @@ var ( ) func init() { - f, err := ebitenutil.OpenFile(ebitenutil.JoinStringsIntoFilePath("_resources", "fonts", "arcade_n.ttf")) + f, err := ebitenutil.OpenFile("_resources/fonts/arcade_n.ttf") if err != nil { log.Fatal(err) } diff --git a/examples/blocks/blocks/gamescene.go b/examples/blocks/blocks/gamescene.go index 8becfb098..a22661c0b 100644 --- a/examples/blocks/blocks/gamescene.go +++ b/examples/blocks/blocks/gamescene.go @@ -70,7 +70,7 @@ func linesTextBoxPosition() (x, y int) { func init() { // Background var err error - imageGameBG, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterLinear) + imageGameBG, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterLinear) if err != nil { panic(err) } diff --git a/examples/blocks/blocks/piece.go b/examples/blocks/blocks/piece.go index d0f84d0ea..ec26e0281 100644 --- a/examples/blocks/blocks/piece.go +++ b/examples/blocks/blocks/piece.go @@ -27,7 +27,7 @@ var imageBlocks *ebiten.Image func init() { var err error - imageBlocks, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "blocks", "blocks.png"), ebiten.FilterNearest) + imageBlocks, _, err = ebitenutil.NewImageFromFile("_resources/images/blocks/blocks.png", ebiten.FilterNearest) if err != nil { panic(err) } diff --git a/examples/blocks/blocks/titlescene.go b/examples/blocks/blocks/titlescene.go index 934c4a37b..b0ebb5ad7 100644 --- a/examples/blocks/blocks/titlescene.go +++ b/examples/blocks/blocks/titlescene.go @@ -27,7 +27,7 @@ var imageBackground *ebiten.Image func init() { var err error - imageBackground, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "blocks", "background.png"), ebiten.FilterNearest) + imageBackground, _, err = ebitenutil.NewImageFromFile("_resources/images/blocks/background.png", ebiten.FilterNearest) if err != nil { panic(err) } diff --git a/examples/flood/main.go b/examples/flood/main.go index 597255af8..6418f4411 100644 --- a/examples/flood/main.go +++ b/examples/flood/main.go @@ -83,7 +83,7 @@ func update(screen *ebiten.Image) error { func main() { var err error - ebitenImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "ebiten.png"), ebiten.FilterNearest) + ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest) if err != nil { log.Fatal(err) } diff --git a/examples/hsv/main.go b/examples/hsv/main.go index a3e759ba7..e2cc68cf0 100644 --- a/examples/hsv/main.go +++ b/examples/hsv/main.go @@ -125,7 +125,7 @@ Inverted: %s [I]`, hue, saturation, value, msgInverted) func main() { var err error - gophersImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterNearest) + gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) if err != nil { log.Fatal(err) } diff --git a/examples/hue/main.go b/examples/hue/main.go index e6e5d89df..428b333cb 100644 --- a/examples/hue/main.go +++ b/examples/hue/main.go @@ -56,7 +56,7 @@ func update(screen *ebiten.Image) error { func main() { var err error - gophersImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterNearest) + gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) if err != nil { log.Fatal(err) } diff --git a/examples/infinitescroll/main.go b/examples/infinitescroll/main.go index 5a98fde86..8e53e420c 100644 --- a/examples/infinitescroll/main.go +++ b/examples/infinitescroll/main.go @@ -36,7 +36,7 @@ var ( func init() { var err error - bgImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "tile.png"), ebiten.FilterNearest) + bgImage, _, err = ebitenutil.NewImageFromFile("_resources/images/tile.png", ebiten.FilterNearest) if err != nil { log.Fatal(err) } diff --git a/examples/keyboard/main.go b/examples/keyboard/main.go index 18f1303dc..5b38e6ed9 100644 --- a/examples/keyboard/main.go +++ b/examples/keyboard/main.go @@ -34,7 +34,7 @@ var keyboardImage *ebiten.Image func init() { var err error - keyboardImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "keyboard", "keyboard.png"), ebiten.FilterNearest) + keyboardImage, _, err = ebitenutil.NewImageFromFile("_resources/images/keyboard/keyboard.png", ebiten.FilterNearest) if err != nil { log.Fatal(err) } diff --git a/examples/masking/main.go b/examples/masking/main.go index 8d66746c5..ddc508f85 100644 --- a/examples/masking/main.go +++ b/examples/masking/main.go @@ -45,12 +45,12 @@ var ( func init() { var err error - bgImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterNearest) + bgImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) if err != nil { log.Fatal(err) } - fgImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "fiveyears.jpg"), ebiten.FilterNearest) + fgImage, _, err = ebitenutil.NewImageFromFile("_resources/images/fiveyears.jpg", ebiten.FilterNearest) if err != nil { log.Fatal(err) } diff --git a/examples/mosaic/main.go b/examples/mosaic/main.go index 10f631c01..4ab621eda 100644 --- a/examples/mosaic/main.go +++ b/examples/mosaic/main.go @@ -38,7 +38,7 @@ var ( func init() { var err error - gophersImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterNearest) + gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) if err != nil { log.Fatal(err) } diff --git a/examples/perspective/main.go b/examples/perspective/main.go index 58db910eb..c0376008d 100644 --- a/examples/perspective/main.go +++ b/examples/perspective/main.go @@ -58,7 +58,7 @@ func update(screen *ebiten.Image) error { func main() { var err error - gophersImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterNearest) + gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) if err != nil { log.Fatal(err) } diff --git a/examples/piano/main.go b/examples/piano/main.go index 88ef1ae53..90fd484a8 100644 --- a/examples/piano/main.go +++ b/examples/piano/main.go @@ -41,7 +41,7 @@ var ( ) func init() { - f, err := ebitenutil.OpenFile(ebitenutil.JoinStringsIntoFilePath("_resources", "fonts", "arcade_n.ttf")) + f, err := ebitenutil.OpenFile("_resources/fonts/arcade_n.ttf") if err != nil { log.Fatal(err) } diff --git a/examples/platformer/main.go b/examples/platformer/main.go index dc270f8ab..77ca3316b 100644 --- a/examples/platformer/main.go +++ b/examples/platformer/main.go @@ -81,19 +81,19 @@ func update(screen *ebiten.Image) error { func main() { // Preload images var err error - rightSprite, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "platformer", "right.png"), ebiten.FilterNearest) + rightSprite, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/right.png", ebiten.FilterNearest) if err != nil { panic(err) } - leftSprite, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "platformer", "left.png"), ebiten.FilterNearest) + leftSprite, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/left.png", ebiten.FilterNearest) if err != nil { panic(err) } - idleSprite, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "platformer", "mainchar.png"), ebiten.FilterNearest) + idleSprite, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/mainchar.png", ebiten.FilterNearest) if err != nil { panic(err) } - backgroundImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "platformer", "background.png"), ebiten.FilterNearest) + backgroundImage, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/background.png", ebiten.FilterNearest) if err != nil { panic(err) } diff --git a/examples/rotate/main.go b/examples/rotate/main.go index 991824dae..61e407dc6 100644 --- a/examples/rotate/main.go +++ b/examples/rotate/main.go @@ -51,7 +51,7 @@ func update(screen *ebiten.Image) error { func main() { var err error - gophersImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterNearest) + gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) if err != nil { log.Fatal(err) } diff --git a/examples/sprites/main.go b/examples/sprites/main.go index f614f447b..d4580c3ea 100644 --- a/examples/sprites/main.go +++ b/examples/sprites/main.go @@ -126,7 +126,7 @@ Press <- or -> to change the number of sprites`, ebiten.CurrentFPS(), sprites.nu func main() { var err error - img, _, err := ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "ebiten.png"), ebiten.FilterNearest) + img, _, err := ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest) if err != nil { log.Fatal(err) } diff --git a/examples/ui/main.go b/examples/ui/main.go index 6ba5b32a9..ccb2fdb7c 100644 --- a/examples/ui/main.go +++ b/examples/ui/main.go @@ -43,7 +43,7 @@ var ( func init() { var err error - uiImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "ui.png"), ebiten.FilterNearest) + uiImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ui.png", ebiten.FilterNearest) if err != nil { log.Fatal(err) } diff --git a/examples/wav/main.go b/examples/wav/main.go index 9456b3187..fbf21c31b 100644 --- a/examples/wav/main.go +++ b/examples/wav/main.go @@ -43,7 +43,7 @@ func init() { log.Fatal(err) } - f, err := ebitenutil.OpenFile(ebitenutil.JoinStringsIntoFilePath("_resources", "audio", "jab.wav")) + f, err := ebitenutil.OpenFile("_resources/audio/jab.wav") if err != nil { log.Fatal(err) } diff --git a/examples/windowsize/main.go b/examples/windowsize/main.go index 3a57acbe1..eb26519b6 100644 --- a/examples/windowsize/main.go +++ b/examples/windowsize/main.go @@ -170,7 +170,7 @@ func main() { fmt.Printf("Device scale factor: %0.2f\n", ebiten.DeviceScaleFactor()) var err error - gophersImage, _, err = ebitenutil.NewImageFromFile(ebitenutil.JoinStringsIntoFilePath("_resources", "images", "gophers.jpg"), ebiten.FilterNearest) + gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) if err != nil { log.Fatal(err) }