From 44c90b42d4e23e5c8205519c60043eb84d0d590a Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 14 Oct 2022 03:16:02 +0900 Subject: [PATCH] ebiten: implement imageDumper for mobiles This is a provisional implementation to clean up the code. --- imagedumper_notmobile.go => imagedumper.go | 21 ++++++++++++--- imagedumper_mobile.go | 31 ---------------------- 2 files changed, 18 insertions(+), 34 deletions(-) rename imagedumper_notmobile.go => imagedumper.go (88%) delete mode 100644 imagedumper_mobile.go diff --git a/imagedumper_notmobile.go b/imagedumper.go similarity index 88% rename from imagedumper_notmobile.go rename to imagedumper.go index 8079542b1..6b241aa89 100644 --- a/imagedumper_notmobile.go +++ b/imagedumper.go @@ -12,14 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !android && !ios -// +build !android,!ios - package ebiten import ( "fmt" "os" + "path/filepath" + "runtime" "time" "github.com/hajimehoshi/ebiten/v2/internal/debug" @@ -34,6 +33,14 @@ func datetimeForFilename() string { func takeScreenshot(screen *Image) error { name := "screenshot_" + datetimeForFilename() + ".png" + // Use the home directory for mobiles as a provisional implementation. + if runtime.GOOS == "android" || runtime.GOOS == "ios" { + home, err := os.UserHomeDir() + if err != nil { + return err + } + name = filepath.Join(home, name) + } blackbg := !IsScreenTransparent() dumpedName, err := screen.image.DumpScreenshot(name, blackbg) if err != nil { @@ -50,6 +57,14 @@ func dumpInternalImages() error { if err != nil { return err } + // Use the home directory for mobiles as a provisional implementation. + if runtime.GOOS == "android" || runtime.GOOS == "ios" { + home, err := os.UserHomeDir() + if err != nil { + return err + } + dumpedDir = filepath.Join(home, dumpedDir) + } if _, err := fmt.Fprintf(os.Stderr, "Dumped the internal images at: %s\n", dumpedDir); err != nil { return err } diff --git a/imagedumper_mobile.go b/imagedumper_mobile.go deleted file mode 100644 index ff2451290..000000000 --- a/imagedumper_mobile.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2018 The Ebiten Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build android || ios -// +build android ios - -package ebiten - -type imageDumper struct { -} - -func (i *imageDumper) update() error { - // Do nothing - return nil -} - -func (i *imageDumper) dump(screen *Image) error { - // Do nothing - return nil -}