mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
ebitenutil: Remove JoinStringsIntoPath; Always use slash for ebitenutil.OpenFile
#428
This commit is contained in:
parent
f773a33f2e
commit
80e4ee0998
@ -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...)
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user