more progress!

This commit is contained in:
Bryce Covert
2016-07-29 13:13:40 -07:00
parent dd0eb3c9c5
commit 53d21c1f65
2 changed files with 42 additions and 179 deletions

View File

@@ -543,8 +543,7 @@
(begin [this screen entities]
(screen! @(resolve 'advent.screens.scene/hud) :on-remove-item :item ((:all-items entities) item))
(-> entities
(update-in [:state :inventory] #(remove (partial = item) %))
(assoc-in [:cursor :current] :main)))
(update-in [:state :inventory] #(remove (partial = item) %))))
(continue [this screen entities] entities)
@@ -586,8 +585,7 @@
(screen! @(resolve 'advent.screens.scene/hud) :on-give-item :item ((:all-items entities) item))
(-> entities
(update-in [:state :inventory] #(conj % item))
(update-in [:state :obtained-items] #(conj % item))
(assoc-in [:cursor :current] ((:all-items entities) item))))
(update-in [:state :obtained-items] #(conj % item))))
(continue [this screen entities] entities)

View File

@@ -1459,6 +1459,7 @@ void main ()
(transition-done? [this screen entities]))
(defn accept-state [entities state state-data transitions]
(println "entering state" state)
(-> entities
(assoc-in [:inv-fsm :state] state)
(assoc-in [:inv-fsm :state-data] state-data)
@@ -1468,19 +1469,19 @@ void main ()
(reify ITransition
(start-transition [this screen entities]
(let [fade-tween (if (= :hide hide-or-show)
(tween/tween :appear-item screen [:selected-item :opacity] 1.0 0.0 0.5 :ease tween/ease-in-out-quadratic)
(tween/tween :appear-item screen [:selected-item :opacity] 0.0 1.0 0.5 :ease tween/ease-in-out-quadratic))
(tween/tween :appear-item screen [:selected-item :opacity] 1.0 0.0 0.5 :ease tween/ease-linear)
(tween/tween :appear-item screen [:selected-item :opacity] 0.0 1.0 0.5 :ease tween/ease-linear))
move-tween (condp = in-or-out
:far-out
(tween/tween :appear-item-y screen [:selected-item :y] 35 40 0.5 :ease tween/ease-in-out-quadratic)
(tween/tween :appear-item-y screen [:selected-item :y] 35 40 0.5 :ease tween/ease-linear)
:out
(tween/tween :appear-item-y screen [:selected-item :y] 30 35 0.5 :ease tween/ease-in-out-quadratic)
(tween/tween :appear-item-y screen [:selected-item :y] 30 35 0.5 :ease tween/ease-linear)
:in
(tween/tween :appear-item-y screen [:selected-item :y] 35 30 0.5 :ease tween/ease-in-out-quadratic)
(tween/tween :appear-item-y screen [:selected-item :y] 35 30 0.5 :ease tween/ease-linear)
:none
(tween/tween :appear-item-y screen [:selected-item :y] 35 35 0.5 :ease tween/ease-in-out-quadratic))]
(tween/tween :appear-item-y screen [:selected-item :y] 35 35 0.5 :ease tween/ease-linear))]
(-> entities
(assoc :selected-item
(assoc (texture (aget (get-in entities [:all-items]) 0 (.indexOf utils/+all-cursors+ (:cursor item))))
@@ -1551,7 +1552,7 @@ void main ()
[(reify ITransition
(start-transition [this screen entities]
(screen! scene :on-click-inventory)
(update-in [:inventory] (fn [i] (actions/start-animation screen i :closing))))
(update-in entities [:inventory] (fn [i] (actions/start-animation screen i :closing))))
(transition-done? [this screen entities] true))
(appear-transition state-data :hide :in)
@@ -1591,6 +1592,25 @@ void main ()
(accept-state entities state state-data
[(appear-transition state-data :show :out)]))
(defmethod transition-hud [:remove :none]
[screen entities state state-data]
(accept-state entities state state-data
[(reify ITransition
(start-transition [this screen entities]
(update-in entities [:inventory] (fn [i] (actions/start-animation screen i :closing))))
(transition-done? [this screen entities]
(animation! (get-in entities [:inventory :anim])
:is-animation-finished
(- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start])))))
(reify ITransition
(start-transition [this screen entities]
(-> entities
(update-in [:inventory] (fn [i] (actions/start-animation screen i :default)))
(dissoc :selected-item)))
(transition-done? [this screen entities]
true))]))
(defmethod transition-hud [:none :aquiring]
[screen entities state state-data]
(accept-state entities state state-data))
@@ -1626,173 +1646,11 @@ void main ()
next-state
(-> (transition-hud screen entities next-state next-state-data)
(assoc-in [:inv-fsm :pending-states] pending-states))
(assoc-in [:inv-fsm :pending-states] (doto (vec pending-states) println)))
:else
nil))
#_(defmethod transition-hud [:none :opening-inventory]
[screen entities _]
(-> entities
(update-in [:inventory] #(actions/start-animation screen % :open))
(assoc :state :opening-inventory)))
#_(defmethod transition-hud [:opening-inventory :opened-inventory]
[screen entities _]
(screen! scene :on-click-inventory)
(-> entities
(update-in [:inventory] #(actions/start-animation screen % :opened))
(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 [:remove-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
:item cursor))
(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 [:none :choosing-item]
[{:keys [cursor] :as screen} entities _]
(-> entities
(update-in [:inventory] #(actions/start-animation screen % :open))
(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
:item cursor))
(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 [:none :give-item]
[{:keys [item] :as screen} entities _]
(-> entities
(update-in [:inventory] #(actions/start-animation screen % :opened))
(assoc :selected-item
(assoc (texture (aget (get-in entities [:all-items]) 0 (.indexOf utils/+all-cursors+ (:cursor item))))
:x 300 :y 40 :baseline 9000 :opacity 0.0
:item item))
(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] 40 35 0.5 :ease tween/ease-in-out-quadratic))
(assoc :state :give-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 [:chose-item :remove-item]
[{:keys [cursor] :as screen} entities _]
(-> 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 40 0.5 :ease tween/ease-in-out-quadratic))
(update-in [:inventory] (fn [i] (actions/start-animation screen i :closing)))
(assoc :state :remove-item)))
#_(defmethod transition-hud [:give-item :chose-item]
[screen entities _]
(-> entities
(update-in [:inventory] #(actions/start-animation screen % :opened))
(assoc :state :chose-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]
(:state entities)))
#_(defmethod process-state :default [screen entities] entities)
#_(defmethod process-state :opening-inventory
[screen entities]
(when
(animation! (get-in entities [:inventory :open])
:is-animation-finished
(- (+ (:delta-time screen) (:total-time screen)) (get-in entities [:inventory :anim-start])))
(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)))
#_(defmethod process-state :remove-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)))
#_(defmethod process-state :give-item
[screen entities]
(when-not (get-in entities [:tweens :appear-item])
(transition-hud screen entities :chose-item)))
(defscreen hud
:on-show
(fn [screen entities]
@@ -1876,20 +1734,27 @@ void main ()
(.update viewport width height true))
:on-give-item
(fn [screen [ entities]]
#_(transition-hud screen entities :give-item))
(fn [{:keys [item] :as screen} [ entities]]
(-> entities
(update-in [:inv-fsm :pending-states] conj [:acquire item])
(update-in [:inv-fsm] (fn [{:keys [state state-data] :as fsm}]
(if (and (= state :selected) (= item state-data))
(update-in fsm [:pending-states] conj [:none state-data])
(update-in fsm [:pending-states] conj [state state-data]))))))
:on-remove-item
(fn [{:keys [item] :as screen} [ entities]]
(-> entities
(update-in [:inv-fsm :pending-states] conj [:remove item])
(update-in [:inv-fsm] (fn [{:keys [state state-data] :as fsm}]
(update-in fsm [:pending-states] conj [state state-data])))))
(if (and (= state :selected) (= item state-data))
(update-in fsm [:pending-states] conj [:none state-data])
(update-in fsm [:pending-states] conj [state state-data]))))))
:on-return-item
(fn [screen [ entities]]
(if (hud-interactable?)
(transition-hud screen entities :none :in)))
(transition-hud screen entities :none (get-in entities [:inv-fsm :state-data]))))
:on-start-script
@@ -1949,7 +1814,7 @@ void main ()
((:mouse-in? (:inventory entities)) x y)
(if (:selected-item entities)
(transition-hud screen entities :none :in)
(transition-hud screen entities :none (get-in entities [:inv-fsm :state-data]))
(transition-hud screen entities :open nil))
(utils/intersects? (:close entities) [x y])