started revamping actions some more for making interactions simple.

This commit is contained in:
=
2014-09-16 13:01:54 -07:00
parent c91e0d7f52
commit 0f7ac68195
2 changed files with 46 additions and 50 deletions

View File

@@ -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))))