ScreenshotAppState little modifications submission

Proposed:

The proposed changes add the following:

The ability to tell the state if the screenshot is numbered and specifying the screenshot file name (some_name.png).

Methods and fields:

New:
numbered (boolean)

Rename
appName to shotName

2 new constructors where the file name is parametrized.

2 new methods: setFileName(String filename) and setIsNumbered(boolean numberedWanted)

Javadoc fix.


By default the class works the way it was before.

Why those changes?

I’m using that state to create a screenshot of the main viewport when user save the game, but the way things were, it made it nearly impossible to properly fetch the image from where it should be found. Depending on the order those screenshots were taken it could be appended with many possible number. It was very inconvenient.

That “old” way was fine for simple screenshots dumped into a directory, but not any other way.

This hopefully would make it easier to use this app state in a different way.

Full diff:

[java]

This patch file was generated by NetBeans IDE

It uses platform neutral UTF-8 encoding and \n newlines.

— Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -59,10 +59,11 @@
private static final Logger logger = Logger.getLogger(ScreenshotAppState.class.getName());
private String filePath = null;
private boolean capture = false;

  • private boolean numbered = true;
    private Renderer renderer;
    private RenderManager rm;
    private ByteBuffer outBuf;
  • private String appName;
  • private String shotName;
    private long shotIndex = 0;
    private int width, height;

@@ -79,19 +80,32 @@
* Include the seperator at the end of the path.
* Use an emptry string to use the application folder. Use NULL to use the system
* default storage folder.

  • * @param file The screenshot file path to use. Include the seperator at the end of the path.
    
  • * @param filePath The screenshot file path to use. Include the seperator at the end of the path.
    */
    

    public ScreenshotAppState(String filePath) {
    this.filePath = filePath;
    }

    /**

  • * This constructor allows you to specify the output file path of the screenshot.
    
  • * Include the seperator at the end of the path.
    
  • * Use an emptry string to use the application folder. Use NULL to use the system
    
  • * default storage folder.
    
  • * @param filePath The screenshot file path to use. Include the seperator at the end of the path.
    
  • * @param fileName The name of the file to save the screeshot as.
    
  • */
    
  • public ScreenshotAppState(String filePath, String fileName) {

  •    this.filePath = filePath;
    
  •    this.shotName = fileName;
    
  • }

  • /**

    • This constructor allows you to specify the output file path of the screenshot and
    • a base index for the shot index.
    • Include the seperator at the end of the path.
    • Use an emptry string to use the application folder. Use NULL to use the system
    • default storage folder.
  • * @param file The screenshot file path to use. Include the seperator at the end of the path.
    
  • * @param filePath The screenshot file path to use. Include the seperator at the end of the path.
    * @param shotIndex The base index for screen shots.  The first screen shot will have
    *                  shotIndex + 1 appended, the next shotIndex + 2, and so on.
    */
    

@@ -101,23 +115,52 @@
}

 /**
  • * This constructor allows you to specify the output file path of the screenshot and
    
  • * a base index for the shot index.
    
  • * Include the seperator at the end of the path.
    
  • * Use an emptry string to use the application folder. Use NULL to use the system
    
  • * default storage folder.
    
  • * @param filePath The screenshot file path to use. Include the seperator at the end of the path.
    
  • * @param fileName The name of the file to save the screeshot as.
    
  • * @param shotIndex The base index for screen shots.  The first screen shot will have
    
  • *                  shotIndex + 1 appended, the next shotIndex + 2, and so on.
    
  • */
    
  • public ScreenshotAppState(String filePath, String fileName, long shotIndex) {
  •    this.filePath = filePath;
    
  •    this.shotName = fileName;
    
  •    this.shotIndex = shotIndex;
    
  • }
  • /**
    • Set the file path to store the screenshot.
    • Include the seperator at the end of the path.
    • Use an emptry string to use the application folder. Use NULL to use the system
    • default storage folder.
  • * @param file File path to use to store the screenshot. Include the seperator at the end of the path.
    
  • * @param filePath File path to use to store the screenshot. Include the seperator at the end of the path.
    */
    

    public void setFilePath(String filePath) {
    this.filePath = filePath;
    }

    /**

  • * Set the file name of the screenshot.
    
  • * @param fileName File name to save the screenshot as.
    
  • */
    
  • public void setFileName(String fileName) {

  •    this.shotName = fileName;
    
  • }

  • /**

    • Sets the base index that will used for subsequent screen shots.
      */
      public void setShotIndex(long index) {
      this.shotIndex = index;
      }
  • public void setIsNumbered(boolean numberedWanted) {

  •    this.numbered = numberedWanted;
    
  • }

  • @Override
    public void initialize(AppStateManager stateManager, Application app) {
    if (!super.isInitialized()){
    @@ -129,8 +172,10 @@
    ViewPort last = vps.get(vps.size()-1);
    last.addProcessor(this);

  •        appName = app.getClass().getSimpleName();
    
  •        if (shotName == null) {
    
  •            shotName = app.getClass().getSimpleName();
       }
    
  •    }
    
       super.initialize(stateManager, app);
    
    }
    @@ -171,7 +216,6 @@
    public void postFrame(FrameBuffer out) {
    if (capture){
    capture = false;
  •        shotIndex++;
    
           Camera curCamera = rm.getCurrentCamera();
           int viewX = (int) (curCamera.getViewPortLeft() * curCamera.getWidth());
    

@@ -184,10 +228,18 @@
renderer.setViewPort(viewX, viewY, viewWidth, viewHeight);

         File file;
  •        String filename;
    
  •        if (numbered) {
    
  •            shotIndex++;
    
  •            filename = shotName + shotIndex;
    
  •        } else {
    
  •            filename = shotName;
    
  •        }
    
  •        if (filePath == null) {
    
  •            file = new File(JmeSystem.getStorageFolder() + File.separator + appName + shotIndex + ".png").getAbsoluteFile();
    
  •            file = new File(JmeSystem.getStorageFolder() + File.separator + filename + ".png").getAbsoluteFile();
           } else {
    
  •            file = new File(filePath + appName + shotIndex + ".png").getAbsoluteFile();
    
  •            file = new File(filePath + filename + ".png").getAbsoluteFile();
           }
           logger.log(Level.FINE, "Saving ScreenShot to: {0}", file.getAbsolutePath());
    

[/java]

I’ll commit soon after getting the ok if it’s deemed to be of value.

2 Likes

Looks fine.
I guess that can be convenient. also that’s good that you kept the current way as default.
You have my vote for the commit. :wink:

Yeah, looks good, go ahead if you want. Thanks!

Thanks.

My thinking is that many games use a screenshot as it’s a visual clue that helps get back into your current game right away. Not always, but sometimes. But that app state can also be used to dump screenies in a directory.

Keeping the old behavior was important. We don’t want to break “old” stuff. :wink:

Edit: It’s been committed.

1 Like