first attempt at saving/loading.
This commit is contained in:
@@ -33,7 +33,8 @@
|
||||
(defmacro get-script [entities & forms]
|
||||
`(fn [starting-entities#]
|
||||
(let [~entities (atom starting-entities#)]
|
||||
(thread ~@forms))))
|
||||
(thread ~@forms
|
||||
(utils/save @~entities)))))
|
||||
|
||||
|
||||
(defn jump-to [screen entities entity [x y] update-baseline?]
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
[play-clj.g2d :refer :all]
|
||||
[clojure.zip :as zip]
|
||||
[clojure.pprint]
|
||||
[clojure.java.io :as io]
|
||||
[advent.pathfind]
|
||||
[advent.actions :as actions]
|
||||
[advent.zone :as zone]
|
||||
@@ -204,6 +205,14 @@
|
||||
(defn make-music [r]
|
||||
(doto (music r) (music! :set-looping true)))
|
||||
|
||||
(defn get-state []
|
||||
(if (.exists (io/file "save.edn"))
|
||||
(utils/load)
|
||||
{:object nil
|
||||
:active? true
|
||||
:inventory [items/grass items/carrot]
|
||||
:clues #{}
|
||||
:mints-eaten 0}))
|
||||
(defscreen scene
|
||||
:on-show
|
||||
(fn [screen entities]
|
||||
@@ -217,31 +226,28 @@
|
||||
:inside-castle (rooms.inside-castle/make screen)
|
||||
:inside-cafeteria (rooms.inside-cafeteria/make screen)
|
||||
:inside-antique (rooms.inside-antique/make screen)
|
||||
:outside-castle (rooms.outside-castle/make screen)}]
|
||||
{:rooms rooms
|
||||
:musics {:object nil
|
||||
:inside-antique (make-music "inside-antique.ogg")
|
||||
:town-1 (make-music "town-music-1.ogg")
|
||||
:town-2 (doto (make-music "town-music-2.ogg") play-sound)
|
||||
:inside-fangald (make-music "inside-fangald.ogg")}
|
||||
:state {:object nil
|
||||
:active? true
|
||||
:inventory [items/grass items/carrot]
|
||||
:clues #{}
|
||||
:mints-eaten 0}
|
||||
:actions {:object nil
|
||||
:channel (chan)
|
||||
:current nil
|
||||
:started? false}
|
||||
:cursor {:id "cursor"
|
||||
:current :main
|
||||
:last :main
|
||||
:override nil}
|
||||
:room (assoc-in (:outside-house rooms)
|
||||
[:entities :ego] (get-ego screen))
|
||||
:inventory (assoc (texture "inventory.png") :x 278 :y 0 :baseline 9000
|
||||
:mouse-in? (zone/box 278 0 320 42))
|
||||
:fps (assoc (label "0" (color :white) ) :x 5 :baseline 0)})))
|
||||
:outside-castle (rooms.outside-castle/make screen)}
|
||||
entities {:rooms rooms
|
||||
:musics {:object nil
|
||||
:inside-antique (make-music "inside-antique.ogg")
|
||||
:town-1 (make-music "town-music-1.ogg")
|
||||
:town-2 (doto (make-music "town-music-2.ogg") play-sound)
|
||||
:inside-fangald (make-music "inside-fangald.ogg")}
|
||||
:state (get-state)
|
||||
:actions {:object nil
|
||||
:channel (chan)
|
||||
:current nil
|
||||
:started? false}
|
||||
:cursor {:id "cursor"
|
||||
:current :main
|
||||
:last :main
|
||||
:override nil}
|
||||
:room (assoc-in (:outside-house rooms)
|
||||
[:entities :ego] (get-ego screen))
|
||||
:inventory (assoc (texture "inventory.png") :x 278 :y 0 :baseline 9000
|
||||
:mouse-in? (zone/box 278 0 320 42))
|
||||
:fps (assoc (label "0" (color :white) ) :x 5 :baseline 0)}]
|
||||
((get-in entities [:room :apply-state]) entities))))
|
||||
|
||||
:on-render
|
||||
(fn [screen [entities]]
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
(:require [play-clj.core :refer :all]
|
||||
[play-clj.ui :refer :all]
|
||||
[play-clj.utils :refer :all]
|
||||
[play-clj.g2d :refer :all])
|
||||
[play-clj.g2d :refer :all]
|
||||
[clojure.edn :as edn])
|
||||
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
|
||||
[com.badlogic.gdx.graphics.g2d TextureRegion]
|
||||
[java.lang Object]))
|
||||
@@ -25,6 +26,11 @@
|
||||
0 0 target-width target-height)
|
||||
resized ))
|
||||
|
||||
(defn save [entities]
|
||||
(spit "save.edn" (entities :state)))
|
||||
|
||||
(defn load []
|
||||
(edn/read-string (slurp "save.edn")))
|
||||
|
||||
(defn get-font [filename]
|
||||
(let [font (bitmap-font filename)
|
||||
|
||||
Reference in New Issue
Block a user