mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 18:52:44 +01:00
graphics: Changed screenshot image location for consistency
This commit is contained in:
parent
613f384cb5
commit
a36bb5dffd
3
doc.go
3
doc.go
@ -40,8 +40,7 @@
|
|||||||
// The EBITEN_SCREENSHOT_KEY environment variable specifies the key
|
// The EBITEN_SCREENSHOT_KEY environment variable specifies the key
|
||||||
// to take a screenshot. For example, if you run your game with
|
// to take a screenshot. For example, if you run your game with
|
||||||
// `EBITEN_SCREENSHOT_KEY=q`, you can take a game screen's screenshot
|
// `EBITEN_SCREENSHOT_KEY=q`, you can take a game screen's screenshot
|
||||||
// by pressing Q key. The image file is saved at the current directory
|
// by pressing Q key.
|
||||||
// with the name screen*.png.
|
|
||||||
//
|
//
|
||||||
// The EBITEN_DUMP_IMAGES_KEY environment variable specifies the key
|
// The EBITEN_DUMP_IMAGES_KEY environment variable specifies the key
|
||||||
// to dump all the internal images.
|
// to dump all the internal images.
|
||||||
|
30
run.go
30
run.go
@ -160,29 +160,33 @@ func (i *imageDumper) update(screen *Image) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if i.toTakeScreenshot {
|
if i.toTakeScreenshot {
|
||||||
filename := "screenshot.png"
|
dump := func() (string, error) {
|
||||||
idx := 0
|
f, err := ioutil.TempFile("", "ebiten_screenshot_")
|
||||||
for {
|
if err != nil {
|
||||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
return "", err
|
||||||
break
|
|
||||||
}
|
}
|
||||||
idx++
|
defer f.Close()
|
||||||
filename = fmt.Sprintf("screenshot%d.png", idx)
|
|
||||||
|
if err := png.Encode(f, screen); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return f.Name(), nil
|
||||||
}
|
}
|
||||||
f, err := os.Create(filename)
|
|
||||||
|
name, err := dump()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
if err := os.Rename(name, name+".png"); err != nil {
|
||||||
|
|
||||||
if err := png.Encode(f, screen); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
i.toTakeScreenshot = false
|
i.toTakeScreenshot = false
|
||||||
|
fmt.Fprintf(os.Stderr, "Saved screenshot: %s.png\n", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if i.toDumpImages {
|
if i.toDumpImages {
|
||||||
dir, err := ioutil.TempDir("", "ebiten_textures")
|
dir, err := ioutil.TempDir("", "ebiten_textures_")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -213,7 +217,7 @@ func (i *imageDumper) update(screen *Image) error {
|
|||||||
|
|
||||||
i.toDumpImages = false
|
i.toDumpImages = false
|
||||||
|
|
||||||
fmt.Fprintf(os.Stderr, "Dumped texture at: %s\n", dir)
|
fmt.Fprintf(os.Stderr, "Dumped the internal images at: %s\n", dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user