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.utils :refer :all]
|
||||||
[play-clj.g2d :refer :all]
|
[play-clj.g2d :refer :all]
|
||||||
[clojure.pprint]
|
[clojure.pprint]
|
||||||
|
[clojure.string :as s]
|
||||||
[advent.pathfind]
|
[advent.pathfind]
|
||||||
[advent.actions :as actions]
|
[advent.actions :as actions]
|
||||||
[advent.screens.dialogue :as dialogue])
|
[advent.screens.dialogue :as dialogue])
|
||||||
@@ -56,16 +57,31 @@
|
|||||||
[(stop target-id)]))]
|
[(stop target-id)]))]
|
||||||
actions))
|
actions))
|
||||||
|
|
||||||
|
(defn get-text-duration [text]
|
||||||
|
(* (count (s/split text #" ")) 0.75))
|
||||||
|
|
||||||
(defn talk [target-id text]
|
(defn talk [target-id text]
|
||||||
|
;; 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]
|
(fn [screen entities]
|
||||||
|
(swap! initial-time #(or % (:total-time screen)))
|
||||||
|
|
||||||
(let [target-y (get-in entities [target-id :y])
|
(let [target-y (get-in entities [target-id :y])
|
||||||
scale-fn (get-in entities [:background :scale-fn])
|
scale-fn (get-in entities [:background :scale-fn])
|
||||||
scale (scale-fn target-y)
|
scale (scale-fn target-y)
|
||||||
height (* scale 36)]
|
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
|
(run! dialogue/talking-screen :on-talk :text text
|
||||||
:x (get-in entities [target-id :x]) :y (+ (get-in entities [target-id :y]) height)
|
:x (get-in entities [target-id :x]) :y (+ (get-in entities [target-id :y]) height)
|
||||||
:target-id target-id
|
:target-id target-id
|
||||||
:scale scale)
|
:scale scale)
|
||||||
(-> entities
|
(assoc-in entities [target-id :anim] (get-in entities [target-id :talk]))))))))
|
||||||
(update-in [target-id :actions] rest)
|
|
||||||
(assoc-in [target-id :anim] (get-in entities [target-id :talk]))))))
|
|
||||||
|
|||||||
@@ -32,11 +32,14 @@
|
|||||||
(case cursor
|
(case cursor
|
||||||
:walk (assoc-in entities [:ego :actions] (actions/from-path screen entities :ego [x y]))
|
:walk (assoc-in entities [:ego :actions] (actions/from-path screen entities :ego [x y]))
|
||||||
:look (assoc-in entities [:ego :actions] [(actions/stop :ego)
|
: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)
|
: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)
|
: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])))))
|
(def +next-cursor+ (into {} (map vector [:walk :touch :look :talk] (drop 1 (cycle [:walk :touch :look :talk])))))
|
||||||
@@ -165,11 +168,13 @@
|
|||||||
:look
|
:look
|
||||||
(assoc-in entities [:ego :actions]
|
(assoc-in entities [:ego :actions]
|
||||||
[(actions/stop :ego)
|
[(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
|
:touch
|
||||||
(assoc-in entities [:ego :actions] (concat
|
(assoc-in entities [:ego :actions] (concat
|
||||||
(actions/from-path screen entities :ego [262 88])
|
(actions/from-path screen entities :ego [262 88])
|
||||||
[(actions/talk :ego (str "Anyone home?"))]))
|
[(actions/talk :ego (str "Anyone home?"))
|
||||||
|
(actions/stop :ego)]))
|
||||||
nil)))
|
nil)))
|
||||||
(reify
|
(reify
|
||||||
IMouseIn
|
IMouseIn
|
||||||
@@ -180,11 +185,13 @@
|
|||||||
(case cursor
|
(case cursor
|
||||||
:look
|
:look
|
||||||
(assoc-in entities [:ego :actions] [(actions/stop :ego)
|
(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
|
:touch
|
||||||
(assoc-in entities [:ego :actions] (concat
|
(assoc-in entities [:ego :actions] (concat
|
||||||
(actions/from-path screen entities :ego [290 66])
|
(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)))]
|
nil)))]
|
||||||
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00)
|
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00)
|
||||||
:layers [(assoc background :x 0 :y 0 :baseline 0)
|
:layers [(assoc background :x 0 :y 0 :baseline 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user