From 8e54c82979e7373560f505f9648af38adca6bc87 Mon Sep 17 00:00:00 2001 From: Remington Covert Date: Thu, 20 Nov 2014 17:10:02 -0800 Subject: [PATCH] rooms are beginning to be affected by state. --- desktop/src-common/advent/actions.clj | 10 +++++++++- .../src-common/advent/screens/rooms/behind_house.clj | 10 +++++++++- desktop/src-common/advent/screens/scene.clj | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index cb778172..711b9a1f 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -6,6 +6,7 @@ [clojure.pprint] [clojure.string :as s] [clojure.zip :as zip] + [clojure.set :as set] [advent.pathfind] [advent.actions :as actions] [advent.screens.dialogue :as dialogue] @@ -26,6 +27,9 @@ (defn has-item? [entities item] ((set (get-in entities [:state :inventory])) item)) +(defn has-one-of? [entities items] + (seq (set/intersection (set (get-in entities [:state :inventory])) (set items)))) + (defmacro get-script [entities & forms] `(fn [starting-entities#] (let [~entities (atom starting-entities#)] @@ -407,7 +411,11 @@ entities (-> entities (assoc-in [:room] (get-in entities [:rooms new-background])) (assoc-in [:room :entities :ego] ego)) - new-music (get-in entities [:room :music])] + new-music (get-in entities [:room :music]) + apply-state (get-in entities [:room :apply-state]) + entities (if apply-state + (apply-state entities) + entities)] (when (not= new-music old-music) (doseq [[k v] (:musics entities) :when (and v (not= new-music k))] diff --git a/desktop/src-common/advent/screens/rooms/behind_house.clj b/desktop/src-common/advent/screens/rooms/behind_house.clj index 9c887b75..8877073a 100644 --- a/desktop/src-common/advent/screens/rooms/behind_house.clj +++ b/desktop/src-common/advent/screens/rooms/behind_house.clj @@ -68,4 +68,12 @@ (actions/update-entity entities :peeling #(assoc % :opacity 0)) (actions/update-state entities (fn [state] (assoc state :opened-crack? true)))))))} :collision "behindhouse/collision.png" - :scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.00))) + :scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.00) + :apply-state (fn [entities] + (as-> entities entities + (if (get-in entities [:state :opened-crack?]) + (assoc-in entities [:room :entities :peeling :opacity] 0) + entities) + (if (actions/has-one-of? entities [items/stick items/cat-toy]) + (update-in entities [:room :entities] #(dissoc % :stick)) + entities))))) diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index 42a65329..8164901b 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -226,7 +226,7 @@ :inside-fangald (make-music "inside-fangald.ogg")} :state {:object nil :active? true - :inventory [items/grass ] + :inventory [items/grass] :clues #{} :mints-eaten 0} :actions {:object nil