trying to fix a couple of bugs.
This commit is contained in:
@@ -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 (<!! c#)))))
|
||||
|
||||
(defn change-script-state [entities state]
|
||||
(run-action entities
|
||||
(begin [this screen entities]
|
||||
(assoc-in entities [:actions :script-running?] state))
|
||||
|
||||
(continue [this screen entities] entities)
|
||||
|
||||
(done? [this screen entities]
|
||||
true)
|
||||
|
||||
(terminate [this screen entities]
|
||||
entities)
|
||||
(can-skip? [this screen entities]
|
||||
false)))
|
||||
|
||||
(defmacro get-script [entities & forms]
|
||||
`(fn [starting-entities#]
|
||||
(let [~entities (atom starting-entities#)]
|
||||
(thread ~@forms
|
||||
(utils/save @~entities)))))
|
||||
(thread (do (change-script-state ~entities true)
|
||||
~@forms
|
||||
(change-script-state ~entities false)
|
||||
(utils/save @~entities))))))
|
||||
|
||||
(defmacro get-unsaved-script [entities & forms]
|
||||
`(fn [starting-entities#]
|
||||
(let [~entities (atom starting-entities#)]
|
||||
(thread ~@forms))))
|
||||
(thread (change-script-state ~entities true)
|
||||
~@forms
|
||||
(change-script-state ~entities false)))))
|
||||
|
||||
|
||||
(defn jump-to [screen entities entity [x y] update-baseline?]
|
||||
@@ -80,14 +108,7 @@
|
||||
(update-in entities [:room :entities target-id] (comp #(start-animation screen % :stand) (if face #(assoc % :facing face) identity))))
|
||||
|
||||
|
||||
(defmacro run-action [entities & forms]
|
||||
`(let [c# (chan)]
|
||||
(do
|
||||
(put! (get-in (deref ~entities) [:actions :channel])
|
||||
(reify IAction
|
||||
(get-channel [_] c#)
|
||||
~@forms))
|
||||
(reset! ~entities (<!! c#)))))
|
||||
|
||||
|
||||
(defn walk-straight-to [entities target-id [final-x final-y] & {:keys [update-baseline? face speed]}]
|
||||
(let [{start-x :x start-y :y} (get-in @entities [:room :entities target-id])
|
||||
@@ -488,6 +509,8 @@
|
||||
(let [[[target line]] pairs
|
||||
next-speaker-is-different (not= target (ffirst (next pairs)))
|
||||
result (talk entities target line :stop? next-speaker-is-different)]
|
||||
|
||||
(Thread/sleep 200)
|
||||
(if (seq (rest pairs))
|
||||
(recur (rest pairs))
|
||||
result))))
|
||||
|
||||
@@ -124,7 +124,8 @@
|
||||
(rooms/make :music :town-2
|
||||
:interactions
|
||||
{:door {:box [258 100 281 160]
|
||||
:script (actions/get-unsaved-script
|
||||
:script
|
||||
(actions/get-unsaved-script
|
||||
entities
|
||||
(actions/walk-to entities :ego [267 90])
|
||||
(actions/talk entities :ego (str "Anyone home?"))
|
||||
|
||||
@@ -44,11 +44,12 @@
|
||||
(get-in entities [:room :interactions]))))
|
||||
|
||||
(defn click-inventory [screen entities]
|
||||
(if (= (get-in entities [:cursor :current] ) :main)
|
||||
(do
|
||||
(screen! inventory-screen :show-screen :items (map (entities :all-items) (get-in entities [:state :inventory])))
|
||||
(assoc-in entities [:state :active?] false))
|
||||
(assoc-in entities [:cursor :current] :main)))
|
||||
(when (not (get-in entities [:actions :script-running?]))
|
||||
(if (= (get-in entities [:cursor :current] ) :main)
|
||||
(do
|
||||
(screen! inventory-screen :show-screen :items (map (entities :all-items) (get-in entities [:state :inventory])))
|
||||
(assoc-in entities [:state :active?] false))
|
||||
(assoc-in entities [:cursor :current] :main))))
|
||||
|
||||
|
||||
(defn left-click [screen entities]
|
||||
@@ -61,8 +62,8 @@
|
||||
(:get-script %)
|
||||
((:mouse-in? %) entities x y))
|
||||
(vals (get-in entities [:room :entities])))))
|
||||
|
||||
current-action (get-in entities [:actions :current])
|
||||
|
||||
;; TODO - hacky way of resetting queue
|
||||
entities (if (and current-action (actions/can-skip? current-action screen entities))
|
||||
(let [terminated-entities (actions/terminate current-action screen entities)]
|
||||
@@ -70,16 +71,17 @@
|
||||
(-> 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
|
||||
|
||||
Reference in New Issue
Block a user