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))))
|
||||
|
||||
Reference in New Issue
Block a user