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