background script pt 1
This commit is contained in:
@@ -50,7 +50,7 @@
|
|||||||
(defmacro run-action [entities & forms]
|
(defmacro run-action [entities & forms]
|
||||||
`(let [c# (chan)]
|
`(let [c# (chan)]
|
||||||
(do
|
(do
|
||||||
(put! (get-in (deref ~entities) [:actions :channel])
|
(put! (get-in (deref ~entities) [:fg-actions :channel])
|
||||||
(reify IAction
|
(reify IAction
|
||||||
(get-channel [_] c#)
|
(get-channel [_] c#)
|
||||||
~@forms))
|
~@forms))
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
(defn change-script-state [entities state]
|
(defn change-script-state [entities state]
|
||||||
(run-action entities
|
(run-action entities
|
||||||
(begin [this screen entities]
|
(begin [this screen entities]
|
||||||
(update-in entities [:actions] assoc :script-running? state :last-skip-type (if state :end nil)))
|
(update-in entities [:fg-actions] assoc :script-running? state :last-skip-type (if state :end nil)))
|
||||||
|
|
||||||
(continue [this screen entities] entities)
|
(continue [this screen entities] entities)
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@
|
|||||||
|
|
||||||
(defmacro get-script [entities & forms]
|
(defmacro get-script [entities & forms]
|
||||||
`(fn [starting-entities#]
|
`(fn [starting-entities#]
|
||||||
(put! (get-in starting-entities# [:actions :script-chan])
|
(put! (get-in starting-entities# [:fg-actions :script-chan])
|
||||||
(fn [starting-entities#]
|
(fn [starting-entities#]
|
||||||
(let [~entities (atom starting-entities#)]
|
(let [~entities (atom starting-entities#)]
|
||||||
(thread (do
|
(thread (do
|
||||||
@@ -88,7 +88,7 @@
|
|||||||
|
|
||||||
(defmacro get-unsaved-script [entities & forms]
|
(defmacro get-unsaved-script [entities & forms]
|
||||||
`(fn [starting-entities#]
|
`(fn [starting-entities#]
|
||||||
(put! (get-in starting-entities# [:actions :script-chan])
|
(put! (get-in starting-entities# [:fg-actions :script-chan])
|
||||||
(fn [starting-entities#]
|
(fn [starting-entities#]
|
||||||
(let [~entities (atom starting-entities#)]
|
(let [~entities (atom starting-entities#)]
|
||||||
(thread (do
|
(thread (do
|
||||||
|
|||||||
@@ -281,7 +281,7 @@
|
|||||||
(defn return-from-island [screen entities]
|
(defn return-from-island [screen entities]
|
||||||
|
|
||||||
|
|
||||||
(when (and (not (get-in entities [:actions :script-running?]))
|
(when (and (not (get-in entities [:fg-actions :script-running?]))
|
||||||
(get-in entities [:state :active?])
|
(get-in entities [:state :active?])
|
||||||
(get-in entities [:room :entities :fairy-godfather :distracted?]))
|
(get-in entities [:room :entities :fairy-godfather :distracted?]))
|
||||||
(if (> (get-in entities [:room :entities :fairy-godfather :distracted-time] 0) 15)
|
(if (> (get-in entities [:room :entities :fairy-godfather :distracted-time] 0) 15)
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
(actions/update-entities entities (fn [e] (assoc-in e [:room :bloodclot-timer] 0))))}]}))
|
(actions/update-entities entities (fn [e] (assoc-in e [:room :bloodclot-timer] 0))))}]}))
|
||||||
|
|
||||||
(defn add-second [screen entities]
|
(defn add-second [screen entities]
|
||||||
(when (and (not (get-in entities [:actions :script-running?]))
|
(when (and (not (get-in entities [:fg-actions :script-running?]))
|
||||||
(get-in entities [:state :active?]))
|
(get-in entities [:state :active?]))
|
||||||
(if (> (get-in entities [:room :bloodclot-timer] 0) 7)
|
(if (> (get-in entities [:room :bloodclot-timer] 0) 7)
|
||||||
(do
|
(do
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
[play-clj.g2d :refer :all]))
|
[play-clj.g2d :refer :all]))
|
||||||
|
|
||||||
(defn brian [screen entities]
|
(defn brian [screen entities]
|
||||||
(when (and (not (get-in entities [:actions :script-running?]))
|
(when (and (not (get-in entities [:fg-actions :script-running?]))
|
||||||
(get-in entities [:state :active?])
|
(get-in entities [:state :active?])
|
||||||
(get-in entities [:room :entities :game-player]))
|
(get-in entities [:room :entities :game-player]))
|
||||||
((actions/get-script entities
|
((actions/get-script entities
|
||||||
|
|||||||
@@ -334,7 +334,7 @@
|
|||||||
(get-in entities [:room :entities :ego :right :walk])} (get-in entities [:room :entities :ego :anim]))]
|
(get-in entities [:room :entities :ego :right :walk])} (get-in entities [:room :entities :ego :anim]))]
|
||||||
(if is-walking?
|
(if is-walking?
|
||||||
(let [entities (-> entities
|
(let [entities (-> entities
|
||||||
(update-in [:actions] #(assoc % :channel (chan) :current nil :started? false :script-running? false))
|
(update-in [:fg-actions] #(assoc % :channel (chan) :current nil :started? false :script-running? false))
|
||||||
(update-in [:room :entities :ego] #(actions/start-animation screen % :stand)))]
|
(update-in [:room :entities :ego] #(actions/start-animation screen % :stand)))]
|
||||||
((actions/get-script entities
|
((actions/get-script entities
|
||||||
(actions/stop-walking entities :ego)
|
(actions/stop-walking entities :ego)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
[play-clj.g2d :refer :all]))
|
[play-clj.g2d :refer :all]))
|
||||||
|
|
||||||
(defn taunt [screen entities]
|
(defn taunt [screen entities]
|
||||||
(when (and (not (get-in entities [:actions :script-running?]))
|
(when (and (not (get-in entities [:fg-actions :script-running?]))
|
||||||
(get-in entities [:state :active?])
|
(get-in entities [:state :active?])
|
||||||
(not (get-in entities [:state :blergh-dead?]))
|
(not (get-in entities [:state :blergh-dead?]))
|
||||||
(not (actions/has-item? entities :magic-slingshot)))
|
(not (actions/has-item? entities :magic-slingshot)))
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
nil)
|
nil)
|
||||||
|
|
||||||
(defn shock [screen entities]
|
(defn shock [screen entities]
|
||||||
(when (and (not (get-in entities [:actions :script-running?]))
|
(when (and (not (get-in entities [:fg-actions :script-running?]))
|
||||||
(get-in entities [:state :active?])
|
(get-in entities [:state :active?])
|
||||||
(not (get-in entities [:state :blergh-dead?]))
|
(not (get-in entities [:state :blergh-dead?]))
|
||||||
(actions/has-item? entities :magic-slingshot))
|
(actions/has-item? entities :magic-slingshot))
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ void main ()
|
|||||||
|
|
||||||
|
|
||||||
(defn click-inventory [screen entities]
|
(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)
|
(if (= (get-in entities [:cursor :current] ) :main)
|
||||||
(do
|
(do
|
||||||
(screen! inventory-screen :show-screen :items (map (entities :all-items) (get-in entities [:state :inventory])))
|
(screen! inventory-screen :show-screen :items (map (entities :all-items) (get-in entities [:state :inventory])))
|
||||||
@@ -190,22 +190,22 @@ void main ()
|
|||||||
(assoc-in entities [:cursor :current] :main))))
|
(assoc-in entities [:cursor :current] :main))))
|
||||||
|
|
||||||
(defn skip-action [screen entities]
|
(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))
|
(cond (= :skip (actions/skip-type current-action screen entities))
|
||||||
(let [terminated-entities (actions/terminate current-action screen entities)]
|
(let [terminated-entities (actions/terminate current-action screen entities)]
|
||||||
(do (put! (actions/get-channel current-action) terminated-entities)
|
(do (put! (actions/get-channel current-action) terminated-entities)
|
||||||
(-> terminated-entities
|
(-> terminated-entities
|
||||||
(assoc-in [:actions :current] nil)
|
(assoc-in [:fg-actions :current] nil)
|
||||||
(assoc-in [:actions :started?] false))))
|
(assoc-in [:fg-actions :started?] false))))
|
||||||
|
|
||||||
(= :end (actions/skip-type current-action screen entities))
|
(= :end (actions/skip-type current-action screen entities))
|
||||||
(let [terminated-entities (actions/terminate current-action screen entities)]
|
(let [terminated-entities (actions/terminate current-action screen entities)]
|
||||||
(println "trying to end")
|
(println "trying to end")
|
||||||
(do (put! (actions/get-channel current-action) :end)
|
(do (put! (actions/get-channel current-action) :end)
|
||||||
(-> terminated-entities
|
(-> terminated-entities
|
||||||
(assoc-in [:actions :script-running?] false)
|
(assoc-in [:fg-actions :script-running?] false)
|
||||||
(assoc-in [:actions :current] nil)
|
(assoc-in [:fg-actions :current] nil)
|
||||||
(assoc-in [:actions :started?] false))))
|
(assoc-in [:fg-actions :started?] false))))
|
||||||
:else
|
:else
|
||||||
entities)))
|
entities)))
|
||||||
|
|
||||||
@@ -229,7 +229,7 @@ void main ()
|
|||||||
_ (println "clicked " x y)
|
_ (println "clicked " x y)
|
||||||
interaction (get-interaction entities x y)
|
interaction (get-interaction entities x y)
|
||||||
interacting-entity (get-interacting-entity 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
|
;; TODO - hacky way of resetting queue
|
||||||
|
|
||||||
@@ -239,7 +239,8 @@ void main ()
|
|||||||
(skip-action screen entities)
|
(skip-action screen entities)
|
||||||
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])
|
(= (get-in entities [:cursor :down-target])
|
||||||
(or (:id interacting-entity) (:id interaction) nil)))
|
(or (:id interacting-entity) (:id interaction) nil)))
|
||||||
((or (when interacting-entity
|
((or (when interacting-entity
|
||||||
@@ -768,32 +769,40 @@ void main ()
|
|||||||
(merge (animation->texture screen (:stand (:right ego))) ego)
|
(merge (animation->texture screen (:stand (:right ego))) ego)
|
||||||
:stand)))
|
:stand)))
|
||||||
|
|
||||||
(defn start-script-if-necessary [screen {{:keys [script-running? script-chan]} :actions :as entities}]
|
(defn start-script-if-necessary [screen entities key]
|
||||||
(if script-running?
|
(let [{{:keys [script-running? script-chan]} key} entities]
|
||||||
entities
|
(if script-running?
|
||||||
(let [[next-script] (alts!! [script-chan] :default nil)]
|
entities
|
||||||
(if next-script
|
(let [[next-script] (alts!! [script-chan] :default nil)]
|
||||||
(do
|
(if next-script
|
||||||
(next-script entities)
|
(do
|
||||||
(println "starting script")
|
(next-script entities)
|
||||||
|
(println "starting script")
|
||||||
(assoc-in entities [:actions :script-running?] true))
|
|
||||||
entities))))
|
(assoc-in entities [key :script-running?] true))
|
||||||
|
entities)))))
|
||||||
|
|
||||||
(defn update-from-script [screen {{:keys [current started? channel script-chan]} :actions :as entities}]
|
(defn update-from-script [screen entities key]
|
||||||
(if current
|
(let [{{:keys [current started? channel script-chan script-running?]} key} entities]
|
||||||
(let [entities (if started? entities (actions/begin current screen entities))
|
|
||||||
entities (actions/continue current screen entities)]
|
(if current
|
||||||
(if (actions/done? current screen entities)
|
(let [entities (if started? entities (actions/begin current screen entities))
|
||||||
(let [terminated (actions/terminate current screen entities)]
|
entities (actions/continue current screen entities)]
|
||||||
(put! (actions/get-channel current) terminated)
|
(if (actions/done? current screen entities)
|
||||||
(recur screen (assoc terminated
|
(let [terminated (actions/terminate current screen entities)]
|
||||||
: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])})))
|
(put! (actions/get-channel current) terminated)
|
||||||
(assoc-in entities [:actions :started?] true)))
|
(recur screen
|
||||||
(let [[current _] (alts!! [channel] :default nil)]
|
(update-in terminated [key] assoc :current nil :started? false)
|
||||||
(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
|
key))
|
||||||
(actions/skip-type current screen entities)
|
(assoc-in entities [key :started?] true)))
|
||||||
(get-in entities [:actions :last-skip-type]))}))))
|
(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]
|
(defn update-from-hotspots [screen entities]
|
||||||
@@ -1104,12 +1113,18 @@ void main ()
|
|||||||
:origin-y 0
|
:origin-y 0
|
||||||
:x -20
|
:x -20
|
||||||
:y -20)
|
:y -20)
|
||||||
:actions {:object nil
|
:fg-actions {:object nil
|
||||||
:channel (chan)
|
:channel (chan)
|
||||||
:current nil
|
:current nil
|
||||||
:script-running? false
|
:script-running? false
|
||||||
:started? 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
|
:volume {:object nil
|
||||||
:value 0.0}
|
:value 0.0}
|
||||||
:music-override {:object nil
|
:music-override {:object nil
|
||||||
@@ -1171,8 +1186,10 @@ void main ()
|
|||||||
(let [entities (fade-in-first-time-if-necessary screen entities)
|
(let [entities (fade-in-first-time-if-necessary screen entities)
|
||||||
entities (utils/apply-tweens screen entities (:tweens entities))
|
entities (utils/apply-tweens screen entities (:tweens entities))
|
||||||
entities (update-cursor screen entities)
|
entities (update-cursor screen entities)
|
||||||
entities (start-script-if-necessary screen entities)
|
entities (start-script-if-necessary screen entities :fg-actions)
|
||||||
entities (update-from-script screen entities)
|
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-room screen entities)
|
||||||
entities (update-from-hotspots screen entities)
|
entities (update-from-hotspots screen entities)
|
||||||
entities (assoc-in entities [:room :entities :ego :last-frame] (get-in entities [:room :entities :ego :object]))
|
entities (assoc-in entities [:room :entities :ego :last-frame] (get-in entities [:room :entities :ego :object]))
|
||||||
@@ -1292,7 +1309,7 @@ void main ()
|
|||||||
:on-show-inventory (fn [screen [entities]]
|
:on-show-inventory (fn [screen [entities]]
|
||||||
(click-inventory screen entities))
|
(click-inventory screen entities))
|
||||||
:on-save (fn [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.))
|
(let [date (.format (java.text.SimpleDateFormat. "MM/dd/YY") (java.util.Date.))
|
||||||
save-name (str (-> entities :room :name) " - " date)]
|
save-name (str (-> entities :room :name) " - " date)]
|
||||||
(utils/save entities
|
(utils/save entities
|
||||||
@@ -1363,7 +1380,7 @@ void main ()
|
|||||||
)
|
)
|
||||||
(defn hud-interactable? []
|
(defn hud-interactable? []
|
||||||
(let [[scene-entities] (-> scene :entities deref)]
|
(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?])
|
(get-in scene-entities [:state :active?])
|
||||||
(= 0.0 (get-in scene-entities [:fade :opacity])))))
|
(= 0.0 (get-in scene-entities [:fade :opacity])))))
|
||||||
|
|
||||||
|
|||||||
@@ -353,10 +353,10 @@
|
|||||||
(< y1 y (+ y1 height))))
|
(< y1 y (+ y1 height))))
|
||||||
|
|
||||||
(defn is-unstoppable-script-running [screen entities]
|
(defn is-unstoppable-script-running [screen entities]
|
||||||
(let [current-action (get-in entities [:actions :current])
|
(let [current-action (get-in entities [:fg-actions :current])
|
||||||
is-script-running (get-in entities [:actions :script-running?])]
|
is-script-running (get-in entities [:fg-actions :script-running?])]
|
||||||
(and is-script-running
|
(and is-script-running
|
||||||
(= :none (get-in entities [:actions :last-skip-type])))))
|
(= :none (get-in entities [:fg-actions :last-skip-type])))))
|
||||||
|
|
||||||
(defn update-override [{:keys [^FitViewport viewport] :as screen} entities]
|
(defn update-override [{:keys [^FitViewport viewport] :as screen} entities]
|
||||||
(let [raw-pos (get-in entities [:cursor :last-pos])
|
(let [raw-pos (get-in entities [:cursor :last-pos])
|
||||||
|
|||||||
Reference in New Issue
Block a user