a hacky way to make talking automatically stop after a certain amount of time.
This commit is contained in:
@@ -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]))))))))
|
||||
|
||||
@@ -32,11 +32,14 @@
|
||||
(case cursor
|
||||
:walk (assoc-in entities [:ego :actions] (actions/from-path screen entities :ego [x y]))
|
||||
:look (assoc-in entities [:ego :actions] [(actions/stop :ego)
|
||||
(actions/talk :ego "Looks pretty uninteresting to me.")])
|
||||
(actions/talk :ego "Looks pretty uninteresting to me.")
|
||||
(actions/stop :ego)])
|
||||
:touch (assoc-in entities [:ego :actions] [(actions/stop :ego)
|
||||
(actions/talk :ego "Can't do anything with it.")])
|
||||
(actions/talk :ego "Can't do anything with it.")
|
||||
(actions/stop :ego)])
|
||||
:talk (assoc-in entities [:ego :actions] [(actions/stop :ego)
|
||||
(actions/talk :ego "It's not much of a conversationalist.")])))))
|
||||
(actions/talk :ego "It's not much of a conversationalist.")
|
||||
(actions/stop :ego)])))))
|
||||
|
||||
|
||||
(def +next-cursor+ (into {} (map vector [:walk :touch :look :talk] (drop 1 (cycle [:walk :touch :look :talk])))))
|
||||
@@ -165,11 +168,13 @@
|
||||
:look
|
||||
(assoc-in entities [:ego :actions]
|
||||
[(actions/stop :ego)
|
||||
(actions/talk :ego (str "The last time I went through that door, Fangald turned me into a frog."))])
|
||||
(actions/talk :ego (str "The last time I went through that door, Fangald turned me into a frog."))
|
||||
(actions/stop :ego)])
|
||||
:touch
|
||||
(assoc-in entities [:ego :actions] (concat
|
||||
(actions/from-path screen entities :ego [262 88])
|
||||
[(actions/talk :ego (str "Anyone home?"))]))
|
||||
[(actions/talk :ego (str "Anyone home?"))
|
||||
(actions/stop :ego)]))
|
||||
nil)))
|
||||
(reify
|
||||
IMouseIn
|
||||
@@ -180,11 +185,13 @@
|
||||
(case cursor
|
||||
:look
|
||||
(assoc-in entities [:ego :actions] [(actions/stop :ego)
|
||||
(actions/talk :ego (str "It's the coolest sword I've ever seen!"))])
|
||||
(actions/talk :ego (str "It's the coolest sword I've ever seen!"))
|
||||
(actions/stop :ego)])
|
||||
:touch
|
||||
(assoc-in entities [:ego :actions] (concat
|
||||
(actions/from-path screen entities :ego [290 66])
|
||||
[(actions/talk :ego (str "Maybe I can pull it out."))]))
|
||||
[(actions/talk :ego (str "Maybe I can pull it out."))
|
||||
(actions/stop :ego)]))
|
||||
nil)))]
|
||||
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00)
|
||||
:layers [(assoc background :x 0 :y 0 :baseline 0)
|
||||
|
||||
Reference in New Issue
Block a user