saving retries if it fails.

This commit is contained in:
Bryce Covert
2016-02-16 09:19:28 -08:00
parent f446dfd2bf
commit 2eef8e63a9

View File

@@ -100,7 +100,16 @@
(edn/read-string (.getString prefs "chapters")) (edn/read-string (.getString prefs "chapters"))
saves/chapters))) saves/chapters)))
(defn try-times [fn times]
(first (drop-while #{:fail}
(repeatedly times
#(try (fn)
(catch Exception e
(log/error "Could not save!" e)
:fail))))))
(defn save [entities id name & [blurb]] (defn save [entities id name & [blurb]]
(let [save-fn (fn []
(log/info "Saving " id name) (log/info "Saving " id name)
(let [save {:name name (let [save {:name name
:id id :id id
@@ -117,7 +126,8 @@
pm (ScreenUtils/getFrameBufferPixmap x y w h) pm (ScreenUtils/getFrameBufferPixmap x y w h)
resized (Pixmap. 160 120 Pixmap$Format/RGB888) resized (Pixmap. 160 120 Pixmap$Format/RGB888)
_ (.drawPixmap resized pm 0 0 w h 0 0 160 120)] _ (.drawPixmap resized pm 0 0 w h 0 0 160 120)]
(steam/save-screenshot resized (steam/save-screenshot-file-name id)))))) (steam/save-screenshot resized (steam/save-screenshot-file-name id))))))]
(try-times save-fn 3)))
(defn remove-save [id] (defn remove-save [id]
(doseq [f [(steam/save-screenshot-file-name id) (doseq [f [(steam/save-screenshot-file-name id)