diff --git a/desktop/src-common/advent/saves.clj b/desktop/src-common/advent/saves.clj index cb39d288..08a6c366 100644 --- a/desktop/src-common/advent/saves.clj +++ b/desktop/src-common/advent/saves.clj @@ -1,15 +1,5 @@ (ns advent.saves) -(def saves - {:autosave "Autosave" - :beginning "Our tale's beginning" - :after-dream "The dream is over" - :after-cat "The Cat Whisperer" - :after-strength "Pro (arm) Wrestler" - :after-wisdom "The Wise Guy" - :after-jail "Prisoner On The Loose" - :in-jail "In The Slammer"}) - (def chapters {:chapter-1 nil :chapter-2 nil @@ -17,5 +7,12 @@ :chapter-4 nil :chapter-5 nil}) -(def name->save - (into {} (map vector (vals saves) (keys saves)))) + +(def chapter-name + {:chapter-1 "Chapter 1: Our tale's beginning" + :chapter-2 "Chapter 2: To be a knight" + :chapter-3 "Chapter 3: In the slammer" + :chapter-4 "Chapter 4: Prisoner on the loose" + :chapter-5 "Chapter 5: Slingshot stew"}) + + diff --git a/desktop/src-common/advent/screens/rooms/outside_house.clj b/desktop/src-common/advent/screens/rooms/outside_house.clj index f9e49515..d9565d76 100644 --- a/desktop/src-common/advent/screens/rooms/outside_house.clj +++ b/desktop/src-common/advent/screens/rooms/outside_house.clj @@ -161,7 +161,8 @@ (actions/play-sound entities "outsidehouse/drop.ogg" 0.2) (actions/camera-shake entities 2) (Thread/sleep 500) - (actions/talk entities :ego "I poured it in. Now what?")) + (actions/talk entities :ego "I poured it in. Now what?") + (utils/save-chapter @entities :chapter-5)) (actions/get-script entities (actions/talk entities :ego "I don't want to put something in there unless I'm sure I need to.")))) diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index 279ae996..a93d9ba9 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -1321,7 +1321,7 @@ void main () :baseline 9000 :opacity 0.8) :save (assoc (utils/get-texture "save.png") - :x 286 :y 224 + :x 280 :y 224 :width 16 :height 16 :baseline 9000 :opacity 0.8) diff --git a/desktop/src-common/advent/screens/title.clj b/desktop/src-common/advent/screens/title.clj index 3cf388f4..30b8d0b1 100644 --- a/desktop/src-common/advent/screens/title.clj +++ b/desktop/src-common/advent/screens/title.clj @@ -181,9 +181,9 @@ is-starting? (= "Begin quest" start-playing-label)] (make-table [[ (make-button start-playing-label :key :continue-or-start) :height 32] :row - [ (make-button "Load" :key :chapters) :height 32] + [ (make-button "Load" :key :load) :height 32] :row - [ (make-button "Chapters") :height 32] + [ (make-button "Chapters" :key :chapters) :height 32] :row [(make-label "Music" (color :white)) :height 32] :row @@ -198,6 +198,25 @@ [(make-button "End quest" :key :end-quest) :height 32] ]))) +(defn chapters-menu [] + (let [chapters (utils/get-chapters)] + (make-table + (concat (mapcat identity + (for [chapter [:chapter-1 :chapter-2 :chapter-3 :chapter-4 :chapter-5]] + [[(doto (make-button (if (chapter chapters) + (saves/chapter-name chapter) + "---") + :chapter (chapter chapters)) + (text-button! :set-disabled (nil? (chapter chapters)))) :height 32] + :row])) + [[(ActorEntity. (Widget.)) :height 32] + :row + [(ActorEntity. (Widget.)) :height 32] + :row + [(ActorEntity. (Widget.)) :height 32] + :row + (make-button "Back" :key :back)])))) + (defn get-selected-save [entities [x y]] (first (filter (every-pred :save #(utils/intersects? % [x y])) @@ -347,54 +366,62 @@ :on-ui-changed (fn [{:keys [actor] :as screen} [entities]] (when-not (get-in entities [:tweens :fade-out]) - (let [e (-> actor .getUserObject) actor-key (:key e)] - (cond + (cond (= :music-volume-slider actor-key) + (do (swap! utils/settings assoc :music-volume (slider! e :get-value)) + (utils/save-settings!) + entities) - (= :music-volume-slider actor-key) - (do (swap! utils/settings assoc :music-volume (slider! e :get-value)) - (utils/save-settings!) - entities) + (= :sound-volume-slider actor-key) + (do (swap! utils/settings assoc :sound-volume (slider! e :get-value)) + (utils/save-settings!) + entities) - (= :sound-volume-slider actor-key) - (do (swap! utils/settings assoc :sound-volume (slider! e :get-value)) - (utils/save-settings!) - entities) + (#{:back } actor-key) + (-> entities + (dissoc :save-menu) + (dissoc :chapters-menu) + (assoc :main-menu (main-menu))) - (#{:back } actor-key) - (-> entities - (dissoc :save-menu) - (assoc :main-menu (main-menu))) + (= :load actor-key) + (-> entities + (dissoc :main-menu) + (assoc :save-menu (saves-menu entities))) - (= :chapters actor-key) - (-> entities - (dissoc :main-menu) - (assoc :save-menu (saves-menu entities))) + (= :chapters actor-key) + (-> entities + (dissoc :main-menu) + (assoc :chapters-menu (chapters-menu ))) - (= :toggle-fullscreen actor-key) - (utils/toggle-fullscreen!) + (= :toggle-fullscreen actor-key) + (utils/toggle-fullscreen!) - (= :end-quest actor-key) - (quit screen entities) + (= :end-quest actor-key) + (quit screen entities) - (= :continue-or-start actor-key) - (start-playing screen entities (if (= "Begin quest" (quest-label)) - nil - (first (utils/snapshot-list)))) + (= :continue-or-start actor-key) + (start-playing screen entities (if (= "Begin quest" (quest-label)) + nil + (first (utils/snapshot-list)))) + (= :continue actor-key) + (start-playing screen entities (:selected-save entities)) - (= :continue actor-key) - (start-playing screen entities (:selected-save entities)) + (= :continue actor-key) + (start-playing screen entities (:selected-save entities)) - (:save e) - (do - (label! (-> entities :save-menu :save-label) :set-text (:name (:save e))) - (text-button! (-> entities :save-menu :continue-button) :set-disabled false) - (assoc entities :selected-save (:save e))) + (:save e) + (do + (label! (-> entities :save-menu :save-label) :set-text (:name (:save e))) + (text-button! (-> entities :save-menu :continue-button) :set-disabled false) + (assoc entities :selected-save (:save e))) - :else - entities)))) + (:chapter e) + (start-playing screen entities (:chapter e)) + + :else + entities)))) :on-resize (fn [{:keys [viewport width height]} [entities]] (.update viewport width height false) diff --git a/desktop/src-common/advent/utils.clj b/desktop/src-common/advent/utils.clj index 65d945db..edc87265 100644 --- a/desktop/src-common/advent/utils.clj +++ b/desktop/src-common/advent/utils.clj @@ -83,10 +83,16 @@ chapters (if (.contains prefs "chapters") (edn/read-string (.getString prefs "chapters")) saves/chapters) - chapters (assoc chapters chapter (entities :state))] + chapters (assoc chapters chapter {:state (entities :state)})] (.putString prefs "chapters" (pr-str chapters)) (.flush prefs))) +(defn get-chapters [] + (let [prefs (.getPreferences (Gdx/app) "ticks-tales-saves")] + (if (.contains prefs "chapters") + (edn/read-string (.getString prefs "chapters")) + saves/chapters))) + (defn save [entities id name] (let [prefs (.getPreferences (Gdx/app) "ticks-tales-saves") saves (if (.contains prefs "saves")