save images.

This commit is contained in:
Bryce Covert
2015-11-02 21:01:58 -08:00
parent 94dab945a3
commit fec5264a28
2 changed files with 55 additions and 29 deletions

View File

@@ -62,6 +62,8 @@
atlas (texture-atlas "packed/pack.atlas")]
(texture (texture-atlas! atlas :find-region atlas-name))))
(defn save-screenshot-file-name [name]
(str "screenshot-" (clojure.core/name name) ".png" ))
(defn snapshot-list []
(let [prefs (.getPreferences (Gdx/app) "ticks-tales-saves")]
@@ -69,22 +71,26 @@
(edn/read-string (.getString prefs "snapshot-list"))
[])))
(defn snapshot-screenshots []
(for [snapshot (snapshot-list)]
[snapshot (try (Pixmap. (FileHandle. (save-screenshot-file-name (saves/name->save snapshot))) )
(catch Exception e
(Pixmap. 160 120 Pixmap$Format/RGB888)))]))
(defn snapshot-state [entities name]
(doto (.getPreferences (Gdx/app) "ticks-tales-saves")
(.putString (saves/saves name) (pr-str (entities :state)))
(.putString "snapshot-list" (pr-str (filter (complement #{"Autosave"})
(cons (saves/saves name)
(filter (complement #{(saves/saves name)})
(snapshot-list))))))
(.putString "snapshot-list" (pr-str (cons (saves/saves name)
(filter (complement #{(saves/saves name)})
(snapshot-list)))))
.flush)
(on-gl (let [f (FileHandle. (str "screenshot-" (clojure.core/name name) ".png" ))
(on-gl (let [f (FileHandle. (save-screenshot-file-name name))
_ (Pixmap/setFilter Pixmap$Filter/BiLinear)
#_#_[x y w h g-l g-r] [(.getScreenX viewport) (.getScreenY viewport) (.getScreenWidth viewport) (.getScreenHeight viewport)]
[x y w h] [0 0 1400 900]
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. 128 96 Pixmap$Format/RGB888)
_ (.drawPixmap resized pm 0 0 w h 0 0 128 96)
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)
@@ -289,8 +295,8 @@
(defn intersects? [e [x y]]
(and (:object e)
(< (:x e) x (+ (:x e) (or (:width e) (.getWidth ^Actor (:object e)))))
(< (:y e) y (+ (:y e) (or (:height e) (.getHeight ^Actor (:object e)))))))
(< (:x e) x (+ (:x e) (or (:width e) (when (actor? e) (.getWidth ^Actor (:object e))))))
(< (:y e) y (+ (:y e) (or (:height e) (when (actor? e) (.getHeight ^Actor (:object e))))))))
(defn get-current-music [entities]
(let [time (get-in entities [:state :time])