Merge branch 'background_scripts'
This commit is contained in:
@@ -180,7 +180,7 @@ void main ()
|
||||
|
||||
|
||||
(defn click-inventory [screen entities]
|
||||
(when (not (get-in entities [:actions :script-running?]))
|
||||
(when (not (get-in entities [:fg-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])))
|
||||
@@ -189,23 +189,22 @@ void main ()
|
||||
(assoc-in [:cursor :override] nil)))
|
||||
(assoc-in entities [:cursor :current] :main))))
|
||||
|
||||
|
||||
|
||||
(defn skip-action [screen entities]
|
||||
(let [current-action (get-in entities [:actions :current])]
|
||||
(let [current-action (get-in entities [:fg-actions :current])]
|
||||
(cond (= :skip (actions/skip-type current-action screen entities))
|
||||
(let [terminated-entities (actions/terminate current-action screen entities)]
|
||||
(do (put! (actions/get-channel current-action) terminated-entities)
|
||||
(-> terminated-entities
|
||||
(assoc-in [:actions :current] nil)
|
||||
(assoc-in [:actions :started?] false))))
|
||||
(assoc-in [:fg-actions :current] nil)
|
||||
(assoc-in [:fg-actions :started?] false))))
|
||||
|
||||
(= :end (actions/skip-type current-action screen entities))
|
||||
(let [terminated-entities (actions/terminate current-action screen entities)]
|
||||
(println "trying to end")
|
||||
(do (put! (actions/get-channel current-action) :end)
|
||||
(-> terminated-entities
|
||||
(assoc-in [:actions :script-running?] false)
|
||||
(assoc-in [:actions :current] nil)
|
||||
(assoc-in [:actions :started?] false))))
|
||||
(actions/force-end terminated-entities current-action :fg-actions)
|
||||
)
|
||||
:else
|
||||
entities)))
|
||||
|
||||
@@ -229,7 +228,7 @@ void main ()
|
||||
_ (println "clicked " x y)
|
||||
interaction (get-interaction entities x y)
|
||||
interacting-entity (get-interacting-entity entities x y)
|
||||
current-action (get-in entities [:actions :current])
|
||||
current-action (get-in entities [:fg-actions :current])
|
||||
|
||||
;; TODO - hacky way of resetting queue
|
||||
|
||||
@@ -239,7 +238,8 @@ void main ()
|
||||
(skip-action screen entities)
|
||||
entities)]
|
||||
|
||||
(when (and (not (get-in entities [:actions :script-running?]))
|
||||
|
||||
(when (and (not (get-in entities [:fg-actions :script-running?]))
|
||||
(= (get-in entities [:cursor :down-target])
|
||||
(or (:id interacting-entity) (:id interaction) nil)))
|
||||
((or (when interacting-entity
|
||||
@@ -768,32 +768,40 @@ void main ()
|
||||
(merge (animation->texture screen (:stand (:right ego))) ego)
|
||||
:stand)))
|
||||
|
||||
(defn start-script-if-necessary [screen {{:keys [script-running? script-chan]} :actions :as entities}]
|
||||
(if script-running?
|
||||
entities
|
||||
(let [[next-script] (alts!! [script-chan] :default nil)]
|
||||
(if next-script
|
||||
(do
|
||||
(next-script entities)
|
||||
(println "starting script")
|
||||
|
||||
(assoc-in entities [:actions :script-running?] true))
|
||||
entities))))
|
||||
(defn start-script-if-necessary [screen entities key]
|
||||
(let [{{:keys [script-running? script-chan]} key} entities]
|
||||
(if script-running?
|
||||
entities
|
||||
(let [[next-script] (alts!! [script-chan] :default nil)]
|
||||
(if next-script
|
||||
(do
|
||||
(next-script entities)
|
||||
(println "starting script")
|
||||
|
||||
(assoc-in entities [key :script-running?] true))
|
||||
entities)))))
|
||||
|
||||
(defn update-from-script [screen {{:keys [current started? channel script-chan]} :actions :as entities}]
|
||||
(if current
|
||||
(let [entities (if started? entities (actions/begin current screen entities))
|
||||
entities (actions/continue current screen entities)]
|
||||
(if (actions/done? current screen entities)
|
||||
(let [terminated (actions/terminate current screen entities)]
|
||||
(put! (actions/get-channel current) terminated)
|
||||
(recur screen (assoc terminated
|
||||
:actions {:channel channel :script-chan (get-in entities [:actions :script-chan]) :current nil :started? false :script-running? (get-in entities [:actions :script-running?]) :last-skip-type (get-in entities [:actions :last-skip-type])})))
|
||||
(assoc-in entities [:actions :started?] true)))
|
||||
(let [[current _] (alts!! [channel] :default nil)]
|
||||
(assoc entities :actions {:script-chan (get-in entities [:actions :script-chan]) :channel channel :current current :started? false :script-running? (get-in entities [:actions :script-running?]) :last-skip-type (if current
|
||||
(actions/skip-type current screen entities)
|
||||
(get-in entities [:actions :last-skip-type]))}))))
|
||||
(defn update-from-script [screen entities key]
|
||||
(let [{{:keys [current started? channel script-chan script-running?]} key} entities]
|
||||
|
||||
(if current
|
||||
(let [entities (if started? entities (actions/begin current screen entities))
|
||||
entities (actions/continue current screen entities)]
|
||||
(if (actions/done? current screen entities)
|
||||
(let [terminated (actions/terminate current screen entities)]
|
||||
(put! (actions/get-channel current) terminated)
|
||||
(recur screen
|
||||
(update-in terminated [key] assoc :current nil :started? false)
|
||||
key))
|
||||
(assoc-in entities [key :started?] true)))
|
||||
(let [[current _] (alts!! [channel] :default nil)]
|
||||
|
||||
(-> entities
|
||||
(assoc-in [key :started?] false)
|
||||
(assoc-in [key :last-skip-type] (if current
|
||||
(actions/skip-type current screen entities)
|
||||
(get-in entities [key :last-skip-type])))
|
||||
(assoc-in [key :current] current))))))
|
||||
|
||||
|
||||
(defn update-from-hotspots [screen entities]
|
||||
@@ -1104,12 +1112,18 @@ void main ()
|
||||
:origin-y 0
|
||||
:x -20
|
||||
:y -20)
|
||||
:actions {:object nil
|
||||
:fg-actions {:object nil
|
||||
:channel (chan)
|
||||
:current nil
|
||||
:script-running? false
|
||||
:started? false
|
||||
:script-chan (chan (dropping-buffer 1))}
|
||||
:script-chan (chan (dropping-buffer 1))}
|
||||
:bg-actions {:object nil
|
||||
:channel (chan)
|
||||
:current nil
|
||||
:script-running? false
|
||||
:started? false
|
||||
:script-chan (chan (dropping-buffer 1))}
|
||||
:volume {:object nil
|
||||
:value 0.0}
|
||||
:music-override {:object nil
|
||||
@@ -1171,8 +1185,10 @@ void main ()
|
||||
(let [entities (fade-in-first-time-if-necessary screen entities)
|
||||
entities (utils/apply-tweens screen entities (:tweens entities))
|
||||
entities (update-cursor screen entities)
|
||||
entities (start-script-if-necessary screen entities)
|
||||
entities (update-from-script screen entities)
|
||||
entities (start-script-if-necessary screen entities :fg-actions)
|
||||
entities (update-from-script screen entities :fg-actions)
|
||||
entities (start-script-if-necessary screen entities :bg-actions)
|
||||
entities (update-from-script screen entities :bg-actions)
|
||||
entities (update-from-room screen entities)
|
||||
entities (update-from-hotspots screen entities)
|
||||
entities (assoc-in entities [:room :entities :ego :last-frame] (get-in entities [:room :entities :ego :object]))
|
||||
@@ -1292,7 +1308,7 @@ void main ()
|
||||
:on-show-inventory (fn [screen [entities]]
|
||||
(click-inventory screen entities))
|
||||
:on-save (fn [screen [entities]]
|
||||
(when-not (get-in entities [:actions :script-running?])
|
||||
(when-not (get-in entities [:fg-actions :script-running?])
|
||||
(let [date (.format (java.text.SimpleDateFormat. "MM/dd/YY") (java.util.Date.))
|
||||
save-name (str (-> entities :room :name) " - " date)]
|
||||
(utils/save entities
|
||||
@@ -1363,7 +1379,7 @@ void main ()
|
||||
)
|
||||
(defn hud-interactable? []
|
||||
(let [[scene-entities] (-> scene :entities deref)]
|
||||
(and (not (get-in scene-entities [:actions :script-running?]))
|
||||
(and (not (get-in scene-entities [:fg-actions :script-running?]))
|
||||
(get-in scene-entities [:state :active?])
|
||||
(= 0.0 (get-in scene-entities [:fade :opacity])))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user