most things are working.

This commit is contained in:
Bryce Covert
2016-07-29 19:05:41 -07:00
parent 53d21c1f65
commit bab004ab87

View File

@@ -55,6 +55,8 @@
(declare hud)
(declare get-selected-inventory-item)
(def v-shader "attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;
@@ -245,14 +247,15 @@ void main ()
(or (:id interacting-entity) (:id interaction) nil)))
((or (when (and interacting-entity (not (:cursor interaction)))
(do (screen! hud :on-start-script)
((:get-script interacting-entity) (get-in entities [:cursor :current]) [x y])))
((:get-script interacting-entity) (or (get-selected-inventory-item) (get-in entities [:cursor :current])) [x y])))
(when interaction
(do (screen! hud :on-start-script)
((:get-script interaction) (or (when (:cursor interaction) :main)
(get-selected-inventory-item)
(get-in entities [:cursor :current]))
[x y])))
((:get-script default-interaction) (get-in entities [:cursor :current]) [x y])) entities))
((:get-script default-interaction) (or (get-selected-inventory-item) (get-in entities [:cursor :current])) [x y])) entities))
(assoc-in entities [:cursor :down-target] nil)))
@@ -876,7 +879,7 @@ void main ()
(defn update-cursor [screen {{:keys [current override last active was-active]} :cursor :as entities}]
(if (= 0.0 (get-in entities [:fade :opacity]))
(let [new-current (or override current)]
(let [new-current (or override (get-selected-inventory-item) current)]
(when-not (and (= new-current
last)
(= active was-active))
@@ -1357,7 +1360,7 @@ void main ()
(screen! hud :on-reactivate :cursor (get-in entities [:cursor :current]))
(-> entities
(assoc-in [:state :active?] true)
(assoc-in [:cursor :override] nil)))
(assoc-in [:cursor :current] :main)))
:on-end-safe (fn [screen [entities]]
((actions/get-script entities
@@ -1424,6 +1427,12 @@ void main ()
(tween/tween [target grow-or-shrink :opacity] screen [target :opacity] opacity-from opacity-to 0.15 :ease tween/ease-in-out-quadratic)))
entities)))
(defn get-selected-inventory-item []
(doto
(let [[{{:keys [state state-data]} :inv-fsm}] (-> hud :entities deref)]
(and (= state :selected)
state-data))))
(defscreen demo
:on-show
(fn [screen entities]
@@ -1509,7 +1518,7 @@ void main ()
(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])))))
(- (:total-time screen) (get-in entities [:inventory :anim-start])))))
(reify ITransition
(start-transition [this screen entities]
@@ -1533,7 +1542,7 @@ void main ()
(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])))))
(- (:total-time screen) (get-in entities [:inventory :anim-start])))))
(reify ITransition
(start-transition [this screen entities]
@@ -1551,7 +1560,6 @@ void main ()
(accept-state entities state state-data
[(reify ITransition
(start-transition [this screen entities]
(screen! scene :on-click-inventory)
(update-in entities [:inventory] (fn [i] (actions/start-animation screen i :closing))))
(transition-done? [this screen entities] true))
(appear-transition state-data :hide :in)
@@ -1601,7 +1609,7 @@ void main ()
(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])))))
(- (:total-time screen) (get-in entities [:inventory :anim-start])))))
(reify ITransition
(start-transition [this screen entities]
@@ -1611,19 +1619,40 @@ void main ()
(transition-done? [this screen entities]
true))]))
(defmethod transition-hud [:none :aquiring]
(defmethod transition-hud [:none :acquire]
[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 :open))))
(transition-done? [this screen entities]
(animation! (get-in entities [:inventory :anim])
:is-animation-finished
(- (:total-time screen) (get-in entities [:inventory :anim-start])))))
(appear-transition state-data :show :none)
(reify ITransition
(start-transition [this screen entities]
(screen! scene :on-click-inventory)
(update-in entities [:inventory] (fn [i] (actions/start-animation screen i :closing))))
(transition-done? [this screen entities] true))
(appear-transition state-data :hide :in)]))
(defmethod transition-hud [:acquire :none]
[screen entities state state-data]
(accept-state entities state state-data [(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 [:selected :acquire]
[screen entities state state-data]
(accept-state entities state state-data))
(defmethod transition-hud [:aquiring :none]
[screen entities state state-data]
(accept-state entities state state-data))
(defmethod transition-hud [:selected :aquiring]
[screen entities state state-data]
(accept-state entities state state-data))
(defmethod transition-hud [:aquiring :selected]
(defmethod transition-hud [:aquiring :acquire]
[screen entities state state-data]
(accept-state entities state state-data))
@@ -1676,11 +1705,13 @@ void main ()
:baseline 9000
:opacity 0.8)
:inventory (assoc (utils/get-texture "inventory.png") :x 278 :y 0 :baseline 9000
:open (utils/make-anim-seq "open-inventory" [42 56] 0.055 (flatten [(range 6) 6 7 8 7 ]))
:open (doto (utils/make-anim-seq "open-inventory" [42 56] 0.055 (flatten [(range 6) 6 7 8 7 ]))
(animation! :set-play-mode (play-mode :normal)))
:anim (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])
:closing (utils/make-anim-seq "open-inventory" [42 56] 0.055 [7 7 7 7 7 7 7 9 10 11 12 0])
:closing (doto (utils/make-anim-seq "open-inventory" [42 56] 0.055 [7 7 7 7 7 7 7 9 10 11 12 0])
(animation! :set-play-mode (play-mode :normal)))
:anim-start 0
:mouse-in? (zone/box 278 0 320 42)
:opacity 0.8)
@@ -1735,12 +1766,14 @@ void main ()
:on-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]))))))
(doto
(-> 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])))))
(#(println (get-in % [:inv-fsm :pending-states])))))
:on-remove-item
(fn [{:keys [item] :as screen} [ entities]]