part 2 background scripts.
This commit is contained in:
@@ -47,10 +47,13 @@
|
|||||||
(seq (set/intersection (set (get-in entities [:state :inventory])) (set items)))
|
(seq (set/intersection (set (get-in entities [:state :inventory])) (set items)))
|
||||||
(seq (set/intersection (set (get-in @entities [:state :inventory])) (set items)))))
|
(seq (set/intersection (set (get-in @entities [:state :inventory])) (set items)))))
|
||||||
|
|
||||||
|
(def ^{:dynamic true} *fg-bg-key* :fg-actions)
|
||||||
|
|
||||||
|
|
||||||
(defmacro run-action [entities & forms]
|
(defmacro run-action [entities & forms]
|
||||||
`(let [c# (chan)]
|
`(let [c# (chan)]
|
||||||
(do
|
(do
|
||||||
(put! (get-in (deref ~entities) [:fg-actions :channel])
|
(put! (get-in (deref ~entities) [*fg-bg-key* :channel])
|
||||||
(reify IAction
|
(reify IAction
|
||||||
(get-channel [_] c#)
|
(get-channel [_] c#)
|
||||||
~@forms))
|
~@forms))
|
||||||
@@ -62,26 +65,37 @@
|
|||||||
(reset! ~entities result#))))))
|
(reset! ~entities result#))))))
|
||||||
|
|
||||||
(defn change-script-state [entities state]
|
(defn change-script-state [entities state]
|
||||||
(run-action entities
|
(let [fg-bg-key *fg-bg-key*]
|
||||||
(begin [this screen entities]
|
(run-action entities
|
||||||
(update-in entities [:fg-actions] assoc :script-running? state :last-skip-type (if state :end nil)))
|
(begin [this screen entities]
|
||||||
|
(update-in entities [fg-bg-key] assoc :script-running? state :last-skip-type (if state :end nil)))
|
||||||
|
|
||||||
(continue [this screen entities] entities)
|
(continue [this screen entities] entities)
|
||||||
|
|
||||||
(done? [this screen entities]
|
(done? [this screen entities]
|
||||||
true)
|
true)
|
||||||
|
|
||||||
(terminate [this screen entities]
|
(terminate [this screen entities]
|
||||||
entities)
|
entities)
|
||||||
(skip-type [this screen entities]
|
(skip-type [this screen entities]
|
||||||
:none-but-arrow)))
|
:none-but-arrow))))
|
||||||
|
|
||||||
|
(defmacro get-bg-script [entities & forms]
|
||||||
|
`(fn [starting-entities#]
|
||||||
|
(put! (get-in starting-entities# [:bg-actions :script-chan])
|
||||||
|
(fn [starting-entities#]
|
||||||
|
(let [~entities (atom starting-entities#)]
|
||||||
|
(thread (binding [*fg-bg-key* :bg-actions]
|
||||||
|
~@forms
|
||||||
|
(change-script-state ~entities false)
|
||||||
|
)))))))
|
||||||
|
|
||||||
(defmacro get-script [entities & forms]
|
(defmacro get-script [entities & forms]
|
||||||
`(fn [starting-entities#]
|
`(fn [starting-entities#]
|
||||||
(put! (get-in starting-entities# [:fg-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 (binding [*fg-bg-key* :fg-actions]
|
||||||
~@forms
|
~@forms
|
||||||
(change-script-state ~entities false)
|
(change-script-state ~entities false)
|
||||||
(utils/save @~entities :autosave "Autosave"))))))))
|
(utils/save @~entities :autosave "Autosave"))))))))
|
||||||
@@ -91,7 +105,7 @@
|
|||||||
(put! (get-in starting-entities# [:fg-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 (binding [*fg-bg-key* :fg-actions]
|
||||||
~@forms
|
~@forms
|
||||||
(change-script-state ~entities false))))))))
|
(change-script-state ~entities false))))))))
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,12 @@
|
|||||||
[play-clj.g2d :refer :all]))
|
[play-clj.g2d :refer :all]))
|
||||||
|
|
||||||
(defn brian [screen entities]
|
(defn brian [screen entities]
|
||||||
|
|
||||||
(when (and (not (get-in entities [:fg-actions :script-running?]))
|
(when (and (not (get-in entities [:fg-actions :script-running?]))
|
||||||
|
(not (get-in entities [:bg-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-bg-script entities
|
||||||
((rand-nth [#(actions/do-dialogue entities :game-player "2 to the power of pi."
|
((rand-nth [#(actions/do-dialogue entities :game-player "2 to the power of pi."
|
||||||
:game-player "No, that's not right.")
|
:game-player "No, that's not right.")
|
||||||
#(actions/do-dialogue entities :game-player "Eureka!"
|
#(actions/do-dialogue entities :game-player "Eureka!"
|
||||||
@@ -362,7 +364,7 @@
|
|||||||
]
|
]
|
||||||
(rooms/make :music {:day :town-1 :night :night :sunrise :night}
|
(rooms/make :music {:day :town-1 :night :night :sunrise :night}
|
||||||
:name "Inside castle"
|
:name "Inside castle"
|
||||||
:timers {:brian [10.0 20.0 brian]}
|
:timers {:brian [10.0 2.0 brian]}
|
||||||
:interactions
|
:interactions
|
||||||
{:right-door {:box [286 140 306 160]
|
{:right-door {:box [286 140 306 160]
|
||||||
:cursor :right
|
:cursor :right
|
||||||
|
|||||||
Reference in New Issue
Block a user