mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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
|
||||
// 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
30
run.go
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user