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