nearly there on steam integration.
This commit is contained in:
@@ -13,26 +13,30 @@
|
||||
(catch Exception e
|
||||
false)))
|
||||
|
||||
(defmacro steamify [steam-version & [regular-version]]
|
||||
(if has-steam?
|
||||
steam-version
|
||||
regular-version))
|
||||
|
||||
(defn init []
|
||||
(when has-steam?
|
||||
(eval `(SteamAPI/init))))
|
||||
(steamify
|
||||
(SteamAPI/init)))
|
||||
|
||||
(defn update []
|
||||
(when (and has-steam? (eval `(SteamAPI/isSteamRunning)))
|
||||
(eval `(SteamAPI/runCallbacks))))
|
||||
(steamify
|
||||
(when (SteamAPI/isSteamRunning)
|
||||
(SteamAPI/runCallbacks))))
|
||||
|
||||
(defn achievement-fn [f achievement]
|
||||
(when has-steam?
|
||||
(eval `(let [stats# (atom nil)]
|
||||
(reset! stats# (SteamUserStats. (reify SteamUserStatsCallback
|
||||
(onUserStatsReceived [this# game-id# steam-user-id# result#]
|
||||
(~f @stats# ~achievement)
|
||||
)
|
||||
(onUserStatsStored [this# gameId# result#]
|
||||
)
|
||||
(onUserAchievementStored [_ _ _ _ _ _]
|
||||
))))
|
||||
(.requestCurrentStats @stats#)))))
|
||||
(steamify
|
||||
(let [stats (atom nil)]
|
||||
(reset! stats (SteamUserStats. (reify SteamUserStatsCallback
|
||||
(onUserStatsReceived [_ _ _ _]
|
||||
(f @stats achievement)
|
||||
)
|
||||
(onUserStatsStored [_ _ _])
|
||||
(onUserAchievementStored [_ _ _ _ _ _]))))
|
||||
(.requestCurrentStats @stats))))
|
||||
|
||||
(def set-achievement (partial achievement-fn
|
||||
(fn [stats achievement]
|
||||
@@ -51,54 +55,53 @@
|
||||
|
||||
(defn write-file [filename edn]
|
||||
(let [edn (pr-str edn)]
|
||||
(if has-steam?
|
||||
(eval `(let [rs# (SteamRemoteStorage. nil)
|
||||
v# ~edn
|
||||
bb# (ByteBuffer/allocateDirect (* 2 (count v#)))]
|
||||
(-> bb# .asCharBuffer (.put v#) )
|
||||
|
||||
(.fileWrite rs# ~filename bb# (* 2 (count v#)))))
|
||||
(let [f (files! :local filename)]
|
||||
(.writeString f edn false)))))
|
||||
(steamify
|
||||
(let [rs (SteamRemoteStorage. nil)
|
||||
v edn
|
||||
bb (ByteBuffer/allocateDirect (* 2 (count v)))]
|
||||
(-> bb .asCharBuffer (.put v) )
|
||||
|
||||
(.fileWrite rs filename bb (* 2 (count v))))
|
||||
(let [f (files! :local filename)]
|
||||
(.writeString f edn false)))))
|
||||
|
||||
(defn snapshot-list []
|
||||
(if has-steam?
|
||||
(eval `(let [rs# (SteamRemoteStorage. nil)]
|
||||
(for [i# (range (.getFileCount rs#))
|
||||
:let [len# (* 1024 1024)
|
||||
n# (.getFileNameAndSize rs# i# (make-array Integer/TYPE 1))
|
||||
bb# (ByteBuffer/allocateDirect len#)]
|
||||
:when (.endsWith n# ".edn")]
|
||||
(do (println n#)
|
||||
(.fileRead rs# n# bb# len#)
|
||||
(-> bb# .asCharBuffer .toString edn/read-string)))))
|
||||
(steamify
|
||||
(let [rs (SteamRemoteStorage. nil)]
|
||||
(for [i (range (.getFileCount rs))
|
||||
:let [len (* 1024 1024)
|
||||
n (.getFileNameAndSize rs i (make-array Integer/TYPE 1))
|
||||
bb (ByteBuffer/allocateDirect len)]
|
||||
:when (.endsWith n ".edn")]
|
||||
(.fileRead rs n bb len)
|
||||
(-> bb .asCharBuffer .toString edn/read-string)))
|
||||
(for [save-file (.list (files! :local ".") ".edn")]
|
||||
(edn/read-string (.readString save-file)))))
|
||||
|
||||
|
||||
(defn add-screenshot [filename]
|
||||
(when has-steam?
|
||||
(eval `(let [rs# (SteamRemoteStorage. nil)
|
||||
bytes# (.readBytes (files! :local ~filename))
|
||||
bb# (ByteBuffer/allocateDirect (count bytes#))]
|
||||
(steamify
|
||||
(let [rs (SteamRemoteStorage. nil)
|
||||
bytes (.readBytes (files! :local filename))
|
||||
bb (ByteBuffer/allocateDirect (count bytes))]
|
||||
|
||||
(.put bb# bytes#)
|
||||
(.fileWrite rs# ~filename bb# (count bytes#))))))
|
||||
(.put bb bytes)
|
||||
(.fileWrite rs filename bb (count bytes)))))
|
||||
|
||||
(defn get-screenshot-bytes [filename]
|
||||
(if has-steam?
|
||||
(eval `(let [rs# (SteamRemoteStorage. nil)
|
||||
len# (.getFileSize rs# ~filename)
|
||||
bb# (ByteBuffer/allocateDirect len#)
|
||||
bytes# (make-array Byte/TYPE len#)]
|
||||
(do (.fileRead rs# ~filename bb# len#)
|
||||
(.get bb# bytes#)
|
||||
(println (count bytes#))
|
||||
bytes#)))
|
||||
(.readBytes (files! :local filename))))
|
||||
(steamify
|
||||
(let [rs (SteamRemoteStorage. nil)
|
||||
len (.getFileSize rs filename)
|
||||
bb (ByteBuffer/allocateDirect len)
|
||||
bytes (make-array Byte/TYPE len)]
|
||||
(.fileRead rs filename bb len)
|
||||
(.get bb bytes)
|
||||
bytes)
|
||||
(.readBytes (files! :local filename))))
|
||||
|
||||
|
||||
(defn save-screenshot [pm filename]
|
||||
(if has-steam?
|
||||
(steamify
|
||||
(let [rs (SteamRemoteStorage. nil)
|
||||
png (PixmapIO$PNG. (* (.getWidth pm) (.getHeight pm) 1.5))
|
||||
baos (ByteArrayOutputStream. (* (.getWidth pm) (.getHeight pm) 1.5))
|
||||
@@ -109,5 +112,6 @@
|
||||
(.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