save screenshots.

This commit is contained in:
Bryce Covert
2015-11-21 17:59:07 -08:00
parent 5da5995894
commit 04a03f281b
2 changed files with 23 additions and 8 deletions

View File

@@ -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))))

View File

@@ -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))