part 2 background scripts.

This commit is contained in:
Bryce Covert
2015-11-19 18:10:10 -08:00
parent ff04d07a0f
commit 624688524b
2 changed files with 31 additions and 15 deletions

View File

@@ -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)))))
(def ^{:dynamic true} *fg-bg-key* :fg-actions)
(defmacro run-action [entities & forms]
`(let [c# (chan)]
(do
(put! (get-in (deref ~entities) [:fg-actions :channel])
(put! (get-in (deref ~entities) [*fg-bg-key* :channel])
(reify IAction
(get-channel [_] c#)
~@forms))
@@ -62,26 +65,37 @@
(reset! ~entities result#))))))
(defn change-script-state [entities state]
(run-action entities
(begin [this screen entities]
(update-in entities [:fg-actions] assoc :script-running? state :last-skip-type (if state :end nil)))
(let [fg-bg-key *fg-bg-key*]
(run-action entities
(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]
true)
(done? [this screen entities]
true)
(terminate [this screen entities]
entities)
(skip-type [this screen entities]
:none-but-arrow)))
(terminate [this screen entities]
entities)
(skip-type [this screen entities]
: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]
`(fn [starting-entities#]
(put! (get-in starting-entities# [:fg-actions :script-chan])
(fn [starting-entities#]
(let [~entities (atom starting-entities#)]
(thread (do
(thread (binding [*fg-bg-key* :fg-actions]
~@forms
(change-script-state ~entities false)
(utils/save @~entities :autosave "Autosave"))))))))
@@ -91,7 +105,7 @@
(put! (get-in starting-entities# [:fg-actions :script-chan])
(fn [starting-entities#]
(let [~entities (atom starting-entities#)]
(thread (do
(thread (binding [*fg-bg-key* :fg-actions]
~@forms
(change-script-state ~entities false))))))))