From 04a03f281b8e9c0967833efe3f8523ad22d84731 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sat, 21 Nov 2015 17:59:07 -0800 Subject: [PATCH] save screenshots. --- desktop/src-common/advent/steam.clj | 21 ++++++++++++++++++++- desktop/src-common/advent/utils.clj | 10 +++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/desktop/src-common/advent/steam.clj b/desktop/src-common/advent/steam.clj index 08fb8dba..0c7d1e91 100644 --- a/desktop/src-common/advent/steam.clj +++ b/desktop/src-common/advent/steam.clj @@ -1,7 +1,10 @@ (ns advent.steam (:require [play-clj.core :refer :all] [clojure.edn :as edn]) - (:import [java.nio ByteBuffer CharBuffer])) + (:import [java.nio ByteBuffer CharBuffer] + [java.io ByteArrayOutputStream] + [com.badlogic.gdx.graphics PixmapIO$PNG] + )) (def has-steam? (try @@ -90,5 +93,21 @@ bytes# (make-array Byte/TYPE len#)] (do (.fileRead rs# ~filename bb# len#) (.get bb# bytes#) + (println (count bytes#)) bytes#))) (.readBytes (files! :local filename)))) + +(defn save-screenshot [pm filename] + (if has-steam? + (let [rs (SteamRemoteStorage. nil) + png (PixmapIO$PNG. (* (.getWidth pm) (.getHeight pm) 1.5)) + baos (ByteArrayOutputStream. (* (.getWidth pm) (.getHeight pm) 1.5)) + _ (.write png baos pm) + bytes (.toByteArray baos) + bb (ByteBuffer/allocateDirect (count bytes))] + (.put bb bytes) + (.fileWrite rs filename bb (count bytes))) + (let [f (files! :local filename) + png (PixmapIO$PNG. (* (.getWidth pm) (.getHeight pm) 1.5))] + (.write png f pm) + (.dispose png)))) diff --git a/desktop/src-common/advent/utils.clj b/desktop/src-common/advent/utils.clj index a792daaa..6c4e0b34 100644 --- a/desktop/src-common/advent/utils.clj +++ b/desktop/src-common/advent/utils.clj @@ -114,17 +114,13 @@ :y (get-in entities [:room :entities :ego :y])) :blurb (or blurb name)}] (write-file (save-file-name id) save) - (on-gl (let [f (files! :local (save-screenshot-file-name id)) - _ (Pixmap/setFilter Pixmap$Filter/BiLinear) + (on-gl (let [_ (Pixmap/setFilter Pixmap$Filter/BiLinear) viewport (-> @ (resolve 'advent.screens.scene/scene) :screen deref :viewport) [x y w h g-l g-r] [(.getScreenX viewport) (.getScreenY viewport) (.getScreenWidth viewport) (.getScreenHeight viewport)] pm (ScreenUtils/getFrameBufferPixmap x y w h) resized (Pixmap. 160 120 Pixmap$Format/RGB888) - _ (.drawPixmap resized pm 0 0 w h 0 0 160 120) - png (PixmapIO$PNG. (* w h 1.5))] - (.write png f resized) - (.dispose png) - (steam/add-screenshot (save-screenshot-file-name id)))))) + _ (.drawPixmap resized pm 0 0 w h 0 0 160 120)] + (steam/save-screenshot resized (save-screenshot-file-name id)))))) (defn remove-save [id] (on-gl (doseq [f [(files! :local (save-screenshot-file-name id))