started revamping actions some more for making interactions simple.
This commit is contained in:
@@ -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))))
|
||||
(<!! c))
|
||||
(reset! entities (<!! c)))
|
||||
entities)))
|
||||
|
||||
(defn get-text-duration [text]
|
||||
@@ -101,7 +100,7 @@
|
||||
(defn talk [entities target-id text]
|
||||
(let [c (chan)
|
||||
initial-time (atom nil)]
|
||||
(put! (get-in entities [:actions :channel])
|
||||
(put! (get-in @entities [:actions :channel])
|
||||
(reify
|
||||
IAction
|
||||
(begin [this screen entities]
|
||||
@@ -127,11 +126,11 @@
|
||||
(put! c entities)
|
||||
(run! dialogue/talking-screen :stop-talk :target-id target-id)
|
||||
(stop screen entities target-id))))
|
||||
(<!! c)))
|
||||
(reset! entities (<!! c))))
|
||||
|
||||
(defn give [entities target-id item]
|
||||
(let [c (chan)]
|
||||
(put! (get-in entities [:actions :channel])
|
||||
(put! (get-in @entities [:actions :channel])
|
||||
(reify
|
||||
IAction
|
||||
(begin [this screen entities]
|
||||
@@ -149,4 +148,4 @@
|
||||
(terminate [this screen entities]
|
||||
(put! c entities)
|
||||
entities)))
|
||||
(<!! c)))
|
||||
(reset! entities (<!! c))))
|
||||
|
||||
@@ -24,18 +24,16 @@
|
||||
(cursor-override [this]))
|
||||
|
||||
(defprotocol IInteractable
|
||||
(interact [this screen entities location]))
|
||||
(get-script [this location]))
|
||||
|
||||
(def default-interaction
|
||||
(reify
|
||||
IInteractable
|
||||
(interact [_ screen entities [x y]]
|
||||
(actions/get-script
|
||||
(get-script [_ [x y]]
|
||||
(actions/get-script entities
|
||||
(actions/walk-to entities :ego [x y])))))
|
||||
|
||||
|
||||
|
||||
|
||||
(defn find-override [screen entities [x y]]
|
||||
(first (filter #(and (mouse-in? % [x y])
|
||||
(satisfies? ICursorOverridable %))
|
||||
@@ -51,10 +49,10 @@
|
||||
:actions {:channel (chan) :current nil :started? false})
|
||||
entities)
|
||||
script (or (when interaction
|
||||
(interact interaction screen entities [x y]))
|
||||
(interact default-interaction screen entities [x y]))]
|
||||
(get-script interaction [x y]))
|
||||
(get-script default-interaction [x y]))]
|
||||
|
||||
(script (get-in entities [:actions :channel]))
|
||||
(script entities)
|
||||
entities))
|
||||
|
||||
(defn get-ego [screen]
|
||||
@@ -108,8 +106,8 @@
|
||||
(mouse-in? [_ location]
|
||||
(apply (apply zone/box (:box spec)) location))
|
||||
IInteractable
|
||||
(interact [_ screen entities location]
|
||||
((:script spec) entities))
|
||||
(get-script [_ location]
|
||||
(:script spec))
|
||||
ICursorOverridable
|
||||
(cursor-override [this] (:cursor spec)))
|
||||
)]
|
||||
@@ -144,39 +142,38 @@
|
||||
:sheep (assoc (animation->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)
|
||||
|
||||
Reference in New Issue
Block a user