summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2022-09-02 22:18:54 +0600
committerilotterytea <iltsu@alright.party>2022-09-02 22:18:54 +0600
commit9f8081ac609afd3fd59508542e5caa95ff8ce562 (patch)
treee2d5287a233c47c35a76baad31397c82ec71dd94 /core
parent2710ede841dd3833974fbfd37e6aa232de15f071 (diff)
Take screenshots
Diffstat (limited to 'core')
-rw-r--r--core/src/com/ilotterytea/maxoning/utils/ScreenshotFactory.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/core/src/com/ilotterytea/maxoning/utils/ScreenshotFactory.java b/core/src/com/ilotterytea/maxoning/utils/ScreenshotFactory.java
new file mode 100644
index 0000000..033c818
--- /dev/null
+++ b/core/src/com/ilotterytea/maxoning/utils/ScreenshotFactory.java
@@ -0,0 +1,51 @@
+package com.ilotterytea.maxoning.utils;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.files.FileHandle;
+import com.badlogic.gdx.graphics.Pixmap;
+import com.badlogic.gdx.graphics.PixmapIO;
+import com.ilotterytea.maxoning.MaxonConstants;
+
+import java.io.File;
+import java.nio.ByteBuffer;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.zip.Deflater;
+
+public class ScreenshotFactory {
+ /**
+ * Take a screenshot.
+ * Default without any compression. Y is flipped.
+ */
+ public static void takeScreenshot(){
+ _takeScreenshot(Deflater.NO_COMPRESSION, true);
+ }
+
+ /**
+ * Take a screenshot. It will be saved in the user data directory, it is different for each platform (Windows: %appdata%/.maxoning/screenshots/, Linux: ~/.local/share/maxoning/screenshots).
+ */
+ public static void takeScreenshot(int compression, boolean flipY){
+ _takeScreenshot(compression, flipY);
+ }
+
+ private static void _takeScreenshot(int compression, boolean flipY) {
+ File file = new File(MaxonConstants.GAME_SCREENSHOT_FOLDER);
+
+ if (!file.exists()) {
+ file.mkdirs();
+ }
+
+ DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy_MM_dd-HHmmss");
+ LocalDateTime now = LocalDateTime.now();
+ Pixmap pixmap = Pixmap.createFromFrameBuffer(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight());
+ ByteBuffer pixels = pixmap.getPixels();
+
+ int size = Gdx.graphics.getBackBufferWidth() * Gdx.graphics.getBackBufferHeight() * 4;
+ for (int i = 3; i < size; i += 4) {
+ pixels.put(i, (byte) 255);
+ }
+
+ PixmapIO.writePNG(new FileHandle(file.getPath() + String.format("/screenshot-%s.png", dtf.format(now))), pixmap, compression, flipY);
+ pixmap.dispose();
+ }
+} \ No newline at end of file