a hacky way to make talking automatically stop after a certain amount of time.

This commit is contained in:
=
2014-09-11 13:23:23 -07:00
parent 8ebd46a935
commit 9528a04a58
2 changed files with 42 additions and 19 deletions

View File

@@ -4,6 +4,7 @@
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]
[clojure.pprint]
[clojure.string :as s]
[advent.pathfind]
[advent.actions :as actions]
[advent.screens.dialogue :as dialogue])
@@ -56,16 +57,31 @@
[(stop target-id)]))]
actions))
(defn get-text-duration [text]
(* (count (s/split text #" ")) 0.75))
(defn talk [target-id text]
(fn [screen entities]
(let [target-y (get-in entities [target-id :y])
scale-fn (get-in entities [:background :scale-fn])
scale (scale-fn target-y)
height (* scale 36)]
(run! dialogue/talking-screen :on-talk :text text
:x (get-in entities [target-id :x]) :y (+ (get-in entities [target-id :y]) height)
:target-id target-id
:scale scale)
(-> entities
(update-in [target-id :actions] rest)
(assoc-in [target-id :anim] (get-in entities [target-id :talk]))))))
;; instead of tracking initial-time in an atom to determine when
;; this is done, this should probably be moved into a start and done?
;; function for an action
(let [initial-time (atom nil)]
(fn [screen entities]
(swap! initial-time #(or % (:total-time screen)))
(let [target-y (get-in entities [target-id :y])
scale-fn (get-in entities [:background :scale-fn])
scale (scale-fn target-y)
height (* scale 36)
done? (> (- (:total-time screen)
@initial-time)
(get-text-duration text))]
(if done?
(do
(run! dialogue/talking-screen :stop-talk :target-id target-id)
(update-in entities [target-id :actions] rest))
(do
(run! dialogue/talking-screen :on-talk :text text
:x (get-in entities [target-id :x]) :y (+ (get-in entities [target-id :y]) height)
:target-id target-id
:scale scale)
(assoc-in entities [target-id :anim] (get-in entities [target-id :talk]))))))))