Skip to content

Commit

Permalink
now it's actually asynchronous
Browse files Browse the repository at this point in the history
Though with the caveat of unsaved screenshots not being saved after state change
  • Loading branch information
Lasercar committed Feb 6, 2025
1 parent eb4b8c2 commit c8faa0a
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions source/funkin/util/plugins/ScreenshotPlugin.hx
Original file line number Diff line number Diff line change
Expand Up @@ -536,26 +536,28 @@ class ScreenshotPlugin extends FlxBasic
previousScreenshotName = newTargetPath;
targetPath = getScreenshotPath() + newTargetPath + '.' + Std.string(Preferences.saveFormat).toLowerCase();
}
var pngData = encode(bitmap);

if (pngData == null)
{
trace('[WARN] Failed to encode ${Preferences.saveFormat} data');
previousScreenshotName = null;
return;
}
else
{
// TODO: Make this work on browser.
// Maybe save the images into a buffer that you can download as a zip or something? That'd work
// TODO: Make this work on browser.
// Maybe save the images into a buffer that you can download as a zip or something? That'd work

/* Unhide the FlxTimer here to space out the screenshot saving some more,
though note that when the state changes any screenshots not already saved will be lost */

new FlxTimer().start(screenShotNum + 1, function(_) {
var pngData = encode(bitmap);

/* Unhide the FlxTimer here to space out the screenshot saving some more,
though note that when the state changes any screenshots not already saved will be lost */
trace('Saving screenshot to: ' + targetPath);
new FlxTimer().start(screenShotNum + 1, function(_) {
if (pngData == null)
{
trace('[WARN] Failed to encode ${Preferences.saveFormat} data');
previousScreenshotName = null;
return;
}
else
{
trace('Saving screenshot to: ' + targetPath);
FileUtil.writeBytesToPath(targetPath, pngData);
});
}
}
});
}

// I' m very happy with this code, all of it just works
Expand Down

0 comments on commit c8faa0a

Please sign in to comment.