diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index 64131e29..93511532 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -40,16 +40,44 @@ (defn has-one-of? [entities items] (seq (set/intersection (set (get-in entities [:state :inventory])) (set items)))) +(defmacro run-action [entities & forms] + `(let [c# (chan)] + (do + (put! (get-in (deref ~entities) [:actions :channel]) + (reify IAction + (get-channel [_] c#) + ~@forms)) + (reset! ~entities ( terminated-entities (assoc-in [:actions :current] nil) (assoc-in [:actions :started?] false)))) - (assoc-in entities [:actions :channel] (chan)))] + entities)] - (if current-action + (if (get-in entities [:actions :script-running?]) entities - ((or (when interaction + ((or (when interacting-entity + ((:get-script interacting-entity) (get-in entities [:cursor :current]) [x y])) + (when interaction ((:get-script interaction) (or (when (:cursor interaction) :main) (get-in entities [:cursor :current])) [x y])) - (when interacting-entity - ((:get-script interacting-entity) (get-in entities [:cursor :current]) [x y])) + ((:get-script default-interaction) (get-in entities [:cursor :current]) [x y])) entities)) entities)))) @@ -202,10 +204,10 @@ (let [terminated (actions/terminate current screen entities)] (put! (actions/get-channel current) terminated) (recur screen (assoc terminated - :actions {:channel channel :current nil :started? false}))) + :actions {:channel channel :current nil :started? false :script-running? (get-in entities [:actions :script-running?])}))) (assoc-in entities [:actions :started?] true))) (let [[current _] (alts!! [channel] :default nil)] - (assoc entities :actions {:channel channel :current current :started? false})))) + (assoc entities :actions {:channel channel :current current :started? false :script-running? (get-in entities [:actions :script-running?])})))) (defn update-cursor [screen {{:keys [current override last]} :cursor :as entities}] @@ -270,6 +272,7 @@ :actions {:object nil :channel (chan) :current nil + :script-running? false :started? false} :cursor {:id "cursor" :current :main