trying to fix a couple of bugs.
This commit is contained in:
@@ -40,16 +40,44 @@
|
|||||||
(defn has-one-of? [entities items]
|
(defn has-one-of? [entities items]
|
||||||
(seq (set/intersection (set (get-in entities [:state :inventory])) (set 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]
|
(defmacro get-script [entities & forms]
|
||||||
`(fn [starting-entities#]
|
`(fn [starting-entities#]
|
||||||
(let [~entities (atom starting-entities#)]
|
(let [~entities (atom starting-entities#)]
|
||||||
(thread ~@forms
|
(thread (do (change-script-state ~entities true)
|
||||||
(utils/save @~entities)))))
|
~@forms
|
||||||
|
(change-script-state ~entities false)
|
||||||
|
(utils/save @~entities))))))
|
||||||
|
|
||||||
(defmacro get-unsaved-script [entities & forms]
|
(defmacro get-unsaved-script [entities & forms]
|
||||||
`(fn [starting-entities#]
|
`(fn [starting-entities#]
|
||||||
(let [~entities (atom 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?]
|
(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))))
|
(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]}]
|
(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])
|
(let [{start-x :x start-y :y} (get-in @entities [:room :entities target-id])
|
||||||
@@ -488,6 +509,8 @@
|
|||||||
(let [[[target line]] pairs
|
(let [[[target line]] pairs
|
||||||
next-speaker-is-different (not= target (ffirst (next pairs)))
|
next-speaker-is-different (not= target (ffirst (next pairs)))
|
||||||
result (talk entities target line :stop? next-speaker-is-different)]
|
result (talk entities target line :stop? next-speaker-is-different)]
|
||||||
|
|
||||||
|
(Thread/sleep 200)
|
||||||
(if (seq (rest pairs))
|
(if (seq (rest pairs))
|
||||||
(recur (rest pairs))
|
(recur (rest pairs))
|
||||||
result))))
|
result))))
|
||||||
|
|||||||
@@ -124,7 +124,8 @@
|
|||||||
(rooms/make :music :town-2
|
(rooms/make :music :town-2
|
||||||
:interactions
|
:interactions
|
||||||
{:door {:box [258 100 281 160]
|
{:door {:box [258 100 281 160]
|
||||||
:script (actions/get-unsaved-script
|
:script
|
||||||
|
(actions/get-unsaved-script
|
||||||
entities
|
entities
|
||||||
(actions/walk-to entities :ego [267 90])
|
(actions/walk-to entities :ego [267 90])
|
||||||
(actions/talk entities :ego (str "Anyone home?"))
|
(actions/talk entities :ego (str "Anyone home?"))
|
||||||
|
|||||||
@@ -44,11 +44,12 @@
|
|||||||
(get-in entities [:room :interactions]))))
|
(get-in entities [:room :interactions]))))
|
||||||
|
|
||||||
(defn click-inventory [screen entities]
|
(defn click-inventory [screen entities]
|
||||||
(if (= (get-in entities [:cursor :current] ) :main)
|
(when (not (get-in entities [:actions :script-running?]))
|
||||||
(do
|
(if (= (get-in entities [:cursor :current] ) :main)
|
||||||
(screen! inventory-screen :show-screen :items (map (entities :all-items) (get-in entities [:state :inventory])))
|
(do
|
||||||
(assoc-in entities [:state :active?] false))
|
(screen! inventory-screen :show-screen :items (map (entities :all-items) (get-in entities [:state :inventory])))
|
||||||
(assoc-in entities [:cursor :current] :main)))
|
(assoc-in entities [:state :active?] false))
|
||||||
|
(assoc-in entities [:cursor :current] :main))))
|
||||||
|
|
||||||
|
|
||||||
(defn left-click [screen entities]
|
(defn left-click [screen entities]
|
||||||
@@ -61,8 +62,8 @@
|
|||||||
(:get-script %)
|
(:get-script %)
|
||||||
((:mouse-in? %) entities x y))
|
((:mouse-in? %) entities x y))
|
||||||
(vals (get-in entities [:room :entities])))))
|
(vals (get-in entities [:room :entities])))))
|
||||||
|
|
||||||
current-action (get-in entities [:actions :current])
|
current-action (get-in entities [:actions :current])
|
||||||
|
|
||||||
;; TODO - hacky way of resetting queue
|
;; TODO - hacky way of resetting queue
|
||||||
entities (if (and current-action (actions/can-skip? current-action screen entities))
|
entities (if (and current-action (actions/can-skip? current-action screen entities))
|
||||||
(let [terminated-entities (actions/terminate current-action screen entities)]
|
(let [terminated-entities (actions/terminate current-action screen entities)]
|
||||||
@@ -70,16 +71,17 @@
|
|||||||
(-> terminated-entities
|
(-> terminated-entities
|
||||||
(assoc-in [:actions :current] nil)
|
(assoc-in [:actions :current] nil)
|
||||||
(assoc-in [:actions :started?] false))))
|
(assoc-in [:actions :started?] false))))
|
||||||
(assoc-in entities [:actions :channel] (chan)))]
|
entities)]
|
||||||
|
|
||||||
(if current-action
|
(if (get-in entities [:actions :script-running?])
|
||||||
entities
|
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-script interaction) (or (when (:cursor interaction) :main)
|
||||||
(get-in entities [:cursor :current]))
|
(get-in entities [:cursor :current]))
|
||||||
[x y]))
|
[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))
|
((:get-script default-interaction) (get-in entities [:cursor :current]) [x y])) entities))
|
||||||
entities))))
|
entities))))
|
||||||
|
|
||||||
@@ -202,10 +204,10 @@
|
|||||||
(let [terminated (actions/terminate current screen entities)]
|
(let [terminated (actions/terminate current screen entities)]
|
||||||
(put! (actions/get-channel current) terminated)
|
(put! (actions/get-channel current) terminated)
|
||||||
(recur screen (assoc 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)))
|
(assoc-in entities [:actions :started?] true)))
|
||||||
(let [[current _] (alts!! [channel] :default nil)]
|
(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}]
|
(defn update-cursor [screen {{:keys [current override last]} :cursor :as entities}]
|
||||||
@@ -270,6 +272,7 @@
|
|||||||
:actions {:object nil
|
:actions {:object nil
|
||||||
:channel (chan)
|
:channel (chan)
|
||||||
:current nil
|
:current nil
|
||||||
|
:script-running? false
|
||||||
:started? false}
|
:started? false}
|
||||||
:cursor {:id "cursor"
|
:cursor {:id "cursor"
|
||||||
:current :main
|
:current :main
|
||||||
|
|||||||
Reference in New Issue
Block a user