finite state machine for great justice.
This commit is contained in:
@@ -26,7 +26,7 @@
|
|||||||
:profiles {
|
:profiles {
|
||||||
:dev {
|
:dev {
|
||||||
:source-paths ["src" "src-common" "src-dev"]
|
:source-paths ["src" "src-common" "src-dev"]
|
||||||
:jvm-opts ["-Duse-repl=true" "-Dno-steam=true"]
|
:jvm-opts ["-Duse-repl=true" "-Dno-steam=true" "-Dclojure.compiler.direct-linking=true"]
|
||||||
:dependencies [[com.badlogicgames.gdx/gdx-tools "1.5.3"]
|
:dependencies [[com.badlogicgames.gdx/gdx-tools "1.5.3"]
|
||||||
[org.clojure/tools.nrepl "0.2.7"]
|
[org.clojure/tools.nrepl "0.2.7"]
|
||||||
[play-clj-nrepl "0.1.0" :exclusions [play-clj]]
|
[play-clj-nrepl "0.1.0" :exclusions [play-clj]]
|
||||||
|
|||||||
@@ -1343,7 +1343,8 @@ void main ()
|
|||||||
input-x input-y)
|
input-x input-y)
|
||||||
(if (= (button-code :right)
|
(if (= (button-code :right)
|
||||||
(:button screen))
|
(:button screen))
|
||||||
(assoc-in entities [:cursor :current] :main)
|
(do
|
||||||
|
(screen! hud :on-return-item))
|
||||||
(when (and (get-in entities [:state :active?])
|
(when (and (get-in entities [:state :active?])
|
||||||
(not (get-in entities [:state :hud-active?]))
|
(not (get-in entities [:state :hud-active?]))
|
||||||
(= 0.0 (get-in entities [:fade :opacity])))
|
(= 0.0 (get-in entities [:fade :opacity])))
|
||||||
@@ -1369,7 +1370,7 @@ void main ()
|
|||||||
(screen! hud :on-chose-item :item item)
|
(screen! hud :on-chose-item :item item)
|
||||||
(assoc-in entities [:cursor :current] item))
|
(assoc-in entities [:cursor :current] item))
|
||||||
|
|
||||||
:on-show-inventory (fn [screen [entities]]
|
:on-click-inventory (fn [screen [entities]]
|
||||||
(click-inventory screen entities))
|
(click-inventory screen entities))
|
||||||
:on-save (fn [screen [entities]]
|
:on-save (fn [screen [entities]]
|
||||||
(when-not (get-in entities [:fg-actions :script-running?])
|
(when-not (get-in entities [:fg-actions :script-running?])
|
||||||
@@ -1453,17 +1454,65 @@ void main ()
|
|||||||
(defmethod transition-hud [:none :opening-inventory]
|
(defmethod transition-hud [:none :opening-inventory]
|
||||||
[screen entities _]
|
[screen entities _]
|
||||||
(-> entities
|
(-> entities
|
||||||
(update-in [:inventory] #(actions/start-animation screen % :open))
|
(update-in [:inventory] #(actions/start-animation screen % :open))
|
||||||
(assoc :opening-inventory? true)
|
|
||||||
(assoc :state :opening-inventory)))
|
(assoc :state :opening-inventory)))
|
||||||
|
|
||||||
(defmethod transition-hud [:opening-inventory :opened-inventory]
|
(defmethod transition-hud [:opening-inventory :opened-inventory]
|
||||||
[screen entities _]
|
[screen entities _]
|
||||||
(screen! scene :on-show-inventory)
|
(screen! scene :on-click-inventory)
|
||||||
(-> entities
|
(-> entities
|
||||||
(update-in [:inventory] #(actions/start-animation screen % :opened))
|
(update-in [:inventory] #(actions/start-animation screen % :opened))
|
||||||
(assoc :state :opened-inventory)))
|
(assoc :state :opened-inventory)))
|
||||||
|
|
||||||
|
(defmethod transition-hud [:opened-inventory :closing-inventory]
|
||||||
|
[screen entities _]
|
||||||
|
(-> entities
|
||||||
|
(update-in [:inventory] #(actions/start-animation screen % :closing))
|
||||||
|
(assoc :state :closing-inventory)))
|
||||||
|
|
||||||
|
(defmethod transition-hud [:closing-inventory :none]
|
||||||
|
[screen entities _]
|
||||||
|
(-> entities
|
||||||
|
(update-in [:inventory] #(actions/start-animation screen % :default))
|
||||||
|
(assoc :state :none)))
|
||||||
|
|
||||||
|
(defmethod transition-hud [:returning-item :none]
|
||||||
|
[screen entities _]
|
||||||
|
(-> entities
|
||||||
|
(update-in [:inventory] #(actions/start-animation screen % :default))
|
||||||
|
(dissoc :selected-item)
|
||||||
|
(assoc :state :none)))
|
||||||
|
|
||||||
|
(defmethod transition-hud [:opened-inventory :choosing-item]
|
||||||
|
[{:keys [cursor] :as screen} entities _]
|
||||||
|
(-> entities
|
||||||
|
(assoc :selected-item
|
||||||
|
(assoc (texture (aget (get-in entities [:all-items]) 0 (.indexOf utils/+all-cursors+ (:cursor cursor))))
|
||||||
|
:x 300 :y 40 :baseline 9000 :opacity 0.0))
|
||||||
|
(assoc-in [:tweens :appear-item]
|
||||||
|
(tween/tween :appear-item screen [:selected-item :opacity] 0.0 1.0 0.5 :ease tween/ease-in-out-quadratic))
|
||||||
|
(assoc-in [:tweens :appear-item-y]
|
||||||
|
(tween/tween :appear-item-y screen [:selected-item :y] 30 35 0.5 :ease tween/ease-in-out-quadratic))
|
||||||
|
(assoc :state :choosing-item)))
|
||||||
|
|
||||||
|
(defmethod transition-hud [:chose-item :returning-item]
|
||||||
|
[{:keys [cursor] :as screen} entities _]
|
||||||
|
(screen! scene :on-click-inventory)
|
||||||
|
(-> entities
|
||||||
|
(assoc-in [:tweens :disappear-item]
|
||||||
|
(tween/tween :disappear-item screen [:selected-item :opacity] 1.0 0.0 0.5 :ease tween/ease-in-out-quadratic))
|
||||||
|
(assoc-in [:tweens :disappear-item-y]
|
||||||
|
(tween/tween :disappear-item-y screen [:selected-item :y] 35 30 0.5 :ease tween/ease-in-out-quadratic))
|
||||||
|
(update-in [:inventory] (fn [i] (actions/start-animation screen i :closing)))
|
||||||
|
(assoc :state :returning-item)))
|
||||||
|
|
||||||
|
|
||||||
|
(defmethod transition-hud [:choosing-item :chose-item]
|
||||||
|
[screen entities _]
|
||||||
|
(-> entities
|
||||||
|
(update-in [:inventory] #(actions/start-animation screen % :opened))
|
||||||
|
(assoc :state :chose-item)))
|
||||||
|
|
||||||
(defmulti process-state (fn [screen entities]
|
(defmulti process-state (fn [screen entities]
|
||||||
(:state entities)))
|
(:state entities)))
|
||||||
|
|
||||||
@@ -1477,6 +1526,28 @@ void main ()
|
|||||||
(- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start])))
|
(- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start])))
|
||||||
(transition-hud screen entities :opened-inventory)))
|
(transition-hud screen entities :opened-inventory)))
|
||||||
|
|
||||||
|
(defmethod process-state :closing-inventory
|
||||||
|
[screen entities]
|
||||||
|
(when
|
||||||
|
(animation! (get-in entities [:inventory :closing])
|
||||||
|
:is-animation-finished
|
||||||
|
(- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start])))
|
||||||
|
(transition-hud screen entities :none)))
|
||||||
|
|
||||||
|
(defmethod process-state :choosing-item
|
||||||
|
[screen entities]
|
||||||
|
(when-not (get-in entities [:tweens :appear-item])
|
||||||
|
(transition-hud screen entities :chose-item)))
|
||||||
|
|
||||||
|
(defmethod process-state :returning-item
|
||||||
|
[screen entities]
|
||||||
|
(when
|
||||||
|
(and (animation! (get-in entities [:inventory :closing])
|
||||||
|
:is-animation-finished
|
||||||
|
(- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start])))
|
||||||
|
(not (get-in entities [:tweens :disappear-item])))
|
||||||
|
(transition-hud screen entities :none)))
|
||||||
|
|
||||||
(defscreen hud
|
(defscreen hud
|
||||||
:on-show
|
:on-show
|
||||||
(fn [screen entities]
|
(fn [screen entities]
|
||||||
@@ -1501,7 +1572,7 @@ void main ()
|
|||||||
:anim (utils/make-anim "inventory.png" [42 56] 0.1 [0])
|
:anim (utils/make-anim "inventory.png" [42 56] 0.1 [0])
|
||||||
:default (utils/make-anim "inventory.png" [42 56] 0.1 [0])
|
:default (utils/make-anim "inventory.png" [42 56] 0.1 [0])
|
||||||
:opened (utils/make-anim-seq "open-inventory" [42 56] 0.1 [7])
|
:opened (utils/make-anim-seq "open-inventory" [42 56] 0.1 [7])
|
||||||
:closing (utils/make-anim-seq "open-inventory" [42 56] 0.055 [9 10 11 12 0])
|
:closing (utils/make-anim-seq "open-inventory" [42 56] 0.055 [7 7 7 7 7 7 7 9 10 11 12 0])
|
||||||
:anim-start 0
|
:anim-start 0
|
||||||
:mouse-in? (zone/box 278 0 320 42)
|
:mouse-in? (zone/box 278 0 320 42)
|
||||||
:opacity 0.8)
|
:opacity 0.8)
|
||||||
@@ -1520,31 +1591,22 @@ void main ()
|
|||||||
(as-> entities entities
|
(as-> entities entities
|
||||||
(update-in entities [:inventory] assoc :r 0.75 :g 0.75 :b 0.75)
|
(update-in entities [:inventory] assoc :r 0.75 :g 0.75 :b 0.75)
|
||||||
(grow-hud screen entities :inventory false)))
|
(grow-hud screen entities :inventory false)))
|
||||||
|
entities (if (:selected-item entities)
|
||||||
|
(if hud-interactable?
|
||||||
|
(as-> entities entities
|
||||||
|
(update-in entities [:selected-item] assoc :r 1.0 :g 1.0 :b 1.0 ))
|
||||||
|
(as-> entities entities
|
||||||
|
(update-in entities [:selected-item] assoc :r 0.75 :g 0.75 :b 0.75)
|
||||||
|
(grow-hud screen entities :selected-item false)))
|
||||||
|
entities)
|
||||||
entities (if (and hud-interactable? (not (:already-saved? entities)))
|
entities (if (and hud-interactable? (not (:already-saved? entities)))
|
||||||
(as-> entities entities
|
(as-> entities entities
|
||||||
(update-in entities [:save] assoc :r 1.0 :g 1.0 :b 1.0 ))
|
(update-in entities [:save] assoc :r 1.0 :g 1.0 :b 1.0 ))
|
||||||
(as-> entities entities
|
(as-> entities entities
|
||||||
(update-in entities [:save] assoc :r 0.75 :g 0.75 :b 0.75)
|
(update-in entities [:save] assoc :r 0.75 :g 0.75 :b 0.75)
|
||||||
(grow-hud screen entities :save false)))
|
(grow-hud screen entities :save false)))
|
||||||
entities (or (process-state screen entities) entities)
|
|
||||||
#_#_entities (if (and (= (get-in entities [:inventory :anim])
|
entities (or (process-state screen entities) entities)]
|
||||||
(get-in entities [:inventory :closing]))
|
|
||||||
(animation! (get-in entities [:inventory :closing])
|
|
||||||
:is-animation-finished
|
|
||||||
(- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start]))))
|
|
||||||
(-> entities
|
|
||||||
(update-in [:inventory] #(actions/start-animation screen % :default)))
|
|
||||||
entities)
|
|
||||||
#_#_entities (if (and (:opening-inventory? entities)
|
|
||||||
(animation! (get-in entities [:inventory :open])
|
|
||||||
:is-animation-finished
|
|
||||||
(- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start]))))
|
|
||||||
(do
|
|
||||||
(screen! scene :on-show-inventory)
|
|
||||||
(-> entities
|
|
||||||
(assoc :opening-inventory? false)
|
|
||||||
(assoc-in [:inventory :anim] (get-in entities [:inventory :opened]))))
|
|
||||||
entities)]
|
|
||||||
#_(label! (:fps entities) :set-text (str (game :fps)))
|
#_(label! (:fps entities) :set-text (str (game :fps)))
|
||||||
|
|
||||||
|
|
||||||
@@ -1555,7 +1617,7 @@ void main ()
|
|||||||
(if hud-interactable?
|
(if hud-interactable?
|
||||||
(:inventory entities)
|
(:inventory entities)
|
||||||
(assoc (:inventory entities) :opacity 0.5))
|
(assoc (:inventory entities) :opacity 0.5))
|
||||||
#_(:selected-item entities)
|
(:selected-item entities)
|
||||||
(:close entities)])
|
(:close entities)])
|
||||||
entities))
|
entities))
|
||||||
|
|
||||||
@@ -1563,6 +1625,13 @@ void main ()
|
|||||||
(fn [{:keys [^FitViewport viewport width height]} entities]
|
(fn [{:keys [^FitViewport viewport width height]} entities]
|
||||||
(.update viewport width height true))
|
(.update viewport width height true))
|
||||||
|
|
||||||
|
:on-return-item
|
||||||
|
(fn [screen [ entities]]
|
||||||
|
(if (hud-interactable?)
|
||||||
|
|
||||||
|
(transition-hud screen entities :returning-item)))
|
||||||
|
|
||||||
|
|
||||||
:on-start-script
|
:on-start-script
|
||||||
(fn [_ [entities]]
|
(fn [_ [entities]]
|
||||||
(assoc-in entities [:already-saved?] false))
|
(assoc-in entities [:already-saved?] false))
|
||||||
@@ -1570,19 +1639,11 @@ void main ()
|
|||||||
|
|
||||||
:on-reactivate
|
:on-reactivate
|
||||||
(fn [{:keys [cursor] :as screen} [entities]]
|
(fn [{:keys [cursor] :as screen} [entities]]
|
||||||
#_(let [selected-item? (and (:value cursor)
|
(let [selected-item? (and (:value cursor)
|
||||||
(:cursor cursor))]
|
(:cursor cursor))]
|
||||||
(if selected-item?
|
(if selected-item?
|
||||||
(do
|
(transition-hud screen entities :choosing-item)
|
||||||
(-> entities
|
(transition-hud screen entities :closing-inventory))))
|
||||||
(assoc :selected-item
|
|
||||||
(assoc (texture (aget (get-in entities [:all-items ]) 0 (.indexOf utils/+all-cursors+ (:cursor cursor))))
|
|
||||||
:x 300 :y 40 :baseline 9000 :opacity 0.0))
|
|
||||||
(assoc-in [:tweens :appear-item]
|
|
||||||
(tween/tween [:appear-item] screen [:selected-item :opacity] 0.0 1.0 0.5 :ease tween/ease-in-out-quadratic))
|
|
||||||
(assoc-in [:tweens :appear-item-y]
|
|
||||||
(tween/tween [:appear-item-y] screen [:selected-item :y] 30 35 0.5 :ease tween/ease-in-out-quadratic))))
|
|
||||||
(update-in entities [:inventory] #(actions/start-animation screen % :closing)))))
|
|
||||||
|
|
||||||
:on-mouse-moved
|
:on-mouse-moved
|
||||||
(fn [screen [entities]]
|
(fn [screen [entities]]
|
||||||
@@ -1592,7 +1653,11 @@ void main ()
|
|||||||
hovered-save? (utils/intersects? (:save entities) [x y])]
|
hovered-save? (utils/intersects? (:save entities) [x y])]
|
||||||
(screen! scene :hud-active? :hud-active? (or hovered-close? hovered-inventory? hovered-save?))
|
(screen! scene :hud-active? :hud-active? (or hovered-close? hovered-inventory? hovered-save?))
|
||||||
(cond (and hovered-inventory? (hud-interactable?))
|
(cond (and hovered-inventory? (hud-interactable?))
|
||||||
(grow-hud screen entities :inventory true)
|
(as-> entities entities
|
||||||
|
(grow-hud screen entities :inventory true)
|
||||||
|
(if (:selected-item entities)
|
||||||
|
(grow-hud screen entities :selected-item true)
|
||||||
|
entities))
|
||||||
|
|
||||||
hovered-close?
|
hovered-close?
|
||||||
(grow-hud screen entities :close true)
|
(grow-hud screen entities :close true)
|
||||||
@@ -1603,6 +1668,9 @@ void main ()
|
|||||||
:else
|
:else
|
||||||
(let [entities (update-in entities [:tweens] dissoc :inventory-grow-x :inventory-grow-y)
|
(let [entities (update-in entities [:tweens] dissoc :inventory-grow-x :inventory-grow-y)
|
||||||
entities (grow-hud screen entities :inventory false)
|
entities (grow-hud screen entities :inventory false)
|
||||||
|
entities (if (:selected-item entities)
|
||||||
|
(grow-hud screen entities :selected-item false)
|
||||||
|
entities)
|
||||||
entities (grow-hud screen entities :close false)
|
entities (grow-hud screen entities :close false)
|
||||||
entities (grow-hud screen entities :save false)]
|
entities (grow-hud screen entities :save false)]
|
||||||
entities
|
entities
|
||||||
@@ -1617,22 +1685,12 @@ void main ()
|
|||||||
(not (hud-interactable?))
|
(not (hud-interactable?))
|
||||||
nil
|
nil
|
||||||
|
|
||||||
|
|
||||||
((:mouse-in? (:inventory entities)) x y)
|
((:mouse-in? (:inventory entities)) x y)
|
||||||
(transition-hud screen entities :opening-inventory)
|
|
||||||
#_(if (:selected-item entities)
|
|
||||||
(do
|
|
||||||
(screen! scene :on-show-inventory)
|
|
||||||
(-> entities
|
|
||||||
(assoc-in [:tweens :disappear-item]
|
|
||||||
(tween/tween [:disappear-item] screen [:selected-item :opacity] 1.0 0.0 0.5 :ease tween/ease-in-out-quadratic))
|
|
||||||
(assoc-in [:tweens :disappear-item-y]
|
|
||||||
(tween/tween [:disappear-item-y] screen [:selected-item :y] 35 30 0.5 :ease tween/ease-in-out-quadratic
|
|
||||||
:finish #(update-in % [:inventory]
|
|
||||||
(fn [i] (actions/start-animation screen i :closing)))))))
|
|
||||||
(-> entities
|
|
||||||
(update-in [:inventory] #(actions/start-animation screen % :open))
|
|
||||||
(assoc :opening-inventory? true)))
|
|
||||||
|
|
||||||
|
(if (:selected-item entities)
|
||||||
|
(transition-hud screen entities :returning-item)
|
||||||
|
(transition-hud screen entities :opening-inventory))
|
||||||
|
|
||||||
(utils/intersects? (:close entities) [x y])
|
(utils/intersects? (:close entities) [x y])
|
||||||
(screen! scene :on-menu)
|
(screen! scene :on-menu)
|
||||||
|
|||||||
Reference in New Issue
Block a user