diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index a11c38c3..7a55fc31 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -18,8 +18,10 @@ (continue [this screen entities]) (terminate [this screen entities])) -(defmacro get-script [& forms] - `(fn [action-channel#] (thread ~@forms ))) +(defmacro get-script [entities & forms] + `(fn [starting-entities#] + (let [~entities (atom starting-entities#)] + (thread ~@forms)))) (defn jump-to [screen entities entity [x y]] @@ -45,11 +47,11 @@ (defn walk-to [entities target-id [final-x final-y]] (let [c (chan) - {start-x :x start-y :y} (entities target-id) + {start-x :x start-y :y} (@entities target-id) final-x (int final-x) final-y (int final-y) path (vec (take-nth 5 (advent.pathfind/visit-all - (:collision (:background entities)) + (:collision (:background @entities)) [(int start-x) (int start-y)] [final-x final-y]))) path (if (seq path) @@ -58,14 +60,11 @@ targets-left (atom path)] (if (seq path) (do - (put! (get-in entities [:actions :channel]) + (put! (get-in @entities [:actions :channel]) (reify IAction (begin [this screen entities] - entities - #_(let [{from-x :x from-y :y :keys [left right anim]} (entities target-id)] - (let [delta-x (- target-x from-x)] - (assoc-in entities [target-id :anim] (if (< delta-x 0) left right))))) + entities) (continue [this screen entities] (let [{from-x :x from-y :y :keys [left right] :as target-entity} (entities target-id) @@ -92,7 +91,7 @@ (let [entities (stop screen entities target-id)] (put! c entities) entities)))) - (texture screen sheep) :x 38 :y 160 :baseline 160 :anim sheep) :background (make-background :interactions {:door {:box [258 100 281 160] - :script (fn [entities] - (actions/get-script - (actions/walk-to entities :ego [262 88]) - (actions/talk entities :ego (str "Anyone home?"))))} + :script (actions/get-script + entities + (actions/walk-to entities :ego [262 88]) + (actions/talk entities :ego (str "Anyone home?")))} :sword {:box [274 55 305 88] - :script (fn [entities] - (actions/get-script - (actions/talk entities :ego (str "It's the coolest sword I've ever seen!")) - (actions/walk-to entities :ego [290 66]) - (actions/talk entities :ego "Maybe I can pull it out.")))} + :script (actions/get-script + entities + (actions/talk entities :ego (str "It's the coolest sword I've ever seen!")) + (actions/walk-to entities :ego [290 66]) + (actions/talk entities :ego "Maybe I can pull it out."))} :sheep {:box [38 160 71 181] - :script (fn [entities] - (actions/get-script - (if ((get-in entities [:ego :inventory]) :wool) - (actions/talk entities :ego "The sheep has given me enough wool.") - (do (actions/give entities :ego :wool) - (actions/talk entities :ego "I guess his wool is shedding.")))))} + :script (actions/get-script + entities + (if ((get-in @entities [:ego :inventory]) :wool) + (actions/talk entities :ego "The sheep has given me enough wool.") + (do (actions/give entities :ego :wool) + (actions/talk entities :ego "I guess his wool is shedding."))))} :right-dir {:box [300 131 320 224] - :script (fn [entities] - (actions/get-script - (actions/walk-to entities :ego [319 160]))) + :script (actions/get-script + entities + (actions/walk-to entities :ego [319 160])) :cursor :right} :up-dir {:box [60 180 224 240] - :script (fn [entities] - (actions/get-script - (actions/walk-to entities :ego [137 204]))) + :script (actions/get-script + entities + (actions/walk-to entities :ego [137 204])) :cursor :up} - :left-dir {:box [0 40 20 140] - :script (fn [entities] - (actions/get-script - (actions/walk-to entities :ego [0 80]))) - :cursor :left}} + :script (actions/get-script + entities + (actions/walk-to entities :ego [0 80])) + :cursor :left}} :layers [(assoc background :x 0 :y 0 :baseline 0) (assoc house :x 0 :y 0 :baseline 122)