graphics: Changed screenshot image location for consistency

This commit is contained in:
Hajime Hoshi 2018-04-28 22:19:24 +09:00
parent 613f384cb5
commit a36bb5dffd
2 changed files with 18 additions and 15 deletions

3
doc.go
View File

@ -40,8 +40,7 @@
// The EBITEN_SCREENSHOT_KEY environment variable specifies the key
// to take a screenshot. For example, if you run your game with
// `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
// with the name screen*.png.
// by pressing Q key.
//
// The EBITEN_DUMP_IMAGES_KEY environment variable specifies the key
// to dump all the internal images.

30
run.go
View File

@ -160,29 +160,33 @@ func (i *imageDumper) update(screen *Image) error {
}
if i.toTakeScreenshot {
filename := "screenshot.png"
idx := 0
for {
if _, err := os.Stat(filename); os.IsNotExist(err) {
break
dump := func() (string, error) {
f, err := ioutil.TempFile("", "ebiten_screenshot_")
if err != nil {
return "", err
}
idx++
filename = fmt.Sprintf("screenshot%d.png", idx)
defer f.Close()
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 {
return err
}
defer f.Close()
if err := png.Encode(f, screen); err != nil {
if err := os.Rename(name, name+".png"); err != nil {
return err
}
i.toTakeScreenshot = false
fmt.Fprintf(os.Stderr, "Saved screenshot: %s.png\n", name)
}
if i.toDumpImages {
dir, err := ioutil.TempDir("", "ebiten_textures")
dir, err := ioutil.TempDir("", "ebiten_textures_")
if err != nil {
return err
}
@ -213,7 +217,7 @@ func (i *imageDumper) update(screen *Image) error {
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