save screenshots.
This commit is contained in:
@@ -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))))
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user