diff --git a/desktop/src-common/advent/screens/rooms/inside_antique.clj b/desktop/src-common/advent/screens/rooms/inside_antique.clj index 912c7a29..a560e620 100644 --- a/desktop/src-common/advent/screens/rooms/inside_antique.clj +++ b/desktop/src-common/advent/screens/rooms/inside_antique.clj @@ -172,7 +172,7 @@ (actions/walk-to entities :ego [242 49] :face :right) (actions/play-animation entities :ego :reach) (actions/add-entity entities :teddy (get-in @entities [:room :teddy])) - (actions/remove-item entities :portrait)) + (actions/remove-item entities :teddy)) (defn has-to-return-teddy? [entities] (and (actions/has-item? entities :teddy) diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index 8ee37537..4697a384 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -891,25 +891,34 @@ void main () -(defn get-animation-point [^Animation animation total-time] +(defn get-looped-animation-point [^Animation animation total-time] (loop [time total-time] (if (> (- time (animation! animation :get-animation-duration)) 0) (recur (- time (animation! animation :get-animation-duration))) time))) -(defn animate [entity screen] - (merge entity (animation->texture (update-in screen [:total-time] #(- % (:anim-start entity))) - (:anim entity)) - {:current-frame-index (animation! ^Animation (:anim entity) :get-key-frame-index (get-animation-point (:anim entity) (- (:total-time screen) (:anim-start entity)))) - :previous-frame-index (animation! ^Animation (:anim entity) :get-key-frame-index (get-animation-point (:anim entity) (- (:total-time screen) (:anim-start entity) (or (:delta-time screen) 0)))) - :origin-x (or (get-in entity [:anim-origins (:anim entity) 0]) - (:base-origin-x entity) - (:origin-x entity)) - :origin-y (or (get-in entity [:anim-origins (:anim entity) 1]) - (:base-origin-y entity) - (:origin-y entity))} - (or (get-in entity [:anim-merges (:anim entity)]) - (get-in entity [:anim-merges :default])))) +(defn animate [{:keys [anim anim-loop? anim-merges anim-start] :or {anim-loop? true} :as entity} {:keys [delta-time total-time] :or {delta-time 0} :as screen}] + (let [current-frame-index (animation! ^Animation anim :get-key-frame-index + (if anim-loop? + (get-looped-animation-point anim (- total-time anim-start)) + (- total-time anim-start))) + previous-frame-index (animation! ^Animation anim :get-key-frame-index + (if anim-loop? + (get-looped-animation-point anim (- total-time anim-start delta-time)) + (- total-time anim-start delta-time)))] + (merge entity (animation->texture (update-in screen [:total-time] #(- % anim-start)) + anim + anim-loop?) + {:current-frame-index current-frame-index + :previous-frame-index previous-frame-index + :origin-x (or (get-in entity [:anim-origins anim 0]) + (:base-origin-x entity) + (:origin-x entity)) + :origin-y (or (get-in entity [:anim-origins anim 1]) + (:base-origin-y entity) + (:origin-y entity))} + (or (get-in entity [:anim-merges anim]) + (get-in entity [:anim-merges :default]))))) (defn get-layers [entities] @@ -1318,10 +1327,10 @@ void main () (filter identity))] (utils/stop-music snd))) - :on-mouse-moved + #_#_:on-mouse-moved mouse-moved - :on-touch-dragged + #_#_:on-touch-dragged mouse-moved :on-touch-down @@ -1633,10 +1642,14 @@ void main () (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)])) + (appear-transition state-data :hide :in) + (reify ITransition + (start-transition [this screen entities] + (dissoc entities :selected-item)) + (transition-done? [this screen entities] + true))])) (defmethod transition-hud [:acquire :none] [screen entities state state-data] @@ -1650,11 +1663,15 @@ void main () (defmethod transition-hud [:selected :acquire] [screen entities state state-data] - (accept-state entities state state-data)) + (accept-state entities state state-data + [(appear-transition (get-in entities [:inv-fsm :state-data]) :hide :none) + (appear-transition state-data :show :none) + (appear-transition state-data :hide :in)])) -(defmethod transition-hud [:aquiring :acquire] +(defmethod transition-hud [:acquire :selected] [screen entities state state-data] - (accept-state entities state state-data)) + (accept-state entities state state-data + [(appear-transition state-data :show :out)])) (defn fsm-busy? [entities] (seq (get-in entities [:inv-fsm :transition-steps]))) @@ -1708,6 +1725,7 @@ void main () :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]) + :anim-loop? false :default (utils/make-anim "inventory.png" [42 56] 0.1 [0]) :opened (utils/make-anim-seq "open-inventory" [42 56] 0.1 [7]) :closing (doto (utils/make-anim-seq "open-inventory" [42 56] 0.055 [7 7 7 7 7 7 7 9 10 11 12 0]) @@ -1780,9 +1798,13 @@ void main () (-> entities (update-in [:inv-fsm :pending-states] conj [:remove item]) (update-in [:inv-fsm] (fn [{:keys [state state-data] :as fsm}] - (if (and (= state :selected) (= item state-data)) + (cond + (and (= state :selected) (= item state-data)) (update-in fsm [:pending-states] conj [:none state-data]) - (update-in fsm [:pending-states] conj [state state-data])))))) + (= state :selected) + (update-in fsm [:pending-states] conj [state state-data]) + :else + (update-in fsm [:pending-states] conj [:none state-data])))))) :on-return-item (fn [screen [ entities]] @@ -1803,13 +1825,21 @@ void main () (transition-hud screen entities :selected cursor) (transition-hud screen entities :none nil)))) - :on-mouse-moved + :on-touch-down + (fn [screen [entities]] + (let [[x y] (utils/unproject screen) + hovered-inventory? ((:mouse-in? (:inventory entities)) x y) + hovered-close? (utils/intersects? (:close entities) [x y]) + hovered-save? (utils/intersects? (:save entities) [x y])] + (screen! scene :hud-active? :hud-active? (or hovered-close? hovered-inventory? hovered-save?)))) + + #_#_:on-mouse-moved + (fn [screen [entities]] (let [[x y] (utils/unproject screen) hovered-inventory? ((:mouse-in? (:inventory entities)) x y) hovered-close? (utils/intersects? (:close entities) [x y]) hovered-save? (utils/intersects? (:save entities) [x y])] - (screen! scene :hud-active? :hud-active? (or hovered-close? hovered-inventory? hovered-save?)) (cond (and hovered-inventory? (hud-interactable?)) (as-> entities entities (grow-hud screen entities :inventory true) diff --git a/desktop/src-common/advent/utils.clj b/desktop/src-common/advent/utils.clj index 43b69dbc..12847143 100644 --- a/desktop/src-common/advent/utils.clj +++ b/desktop/src-common/advent/utils.clj @@ -361,7 +361,7 @@ (let [current-action (get-in entities [:fg-actions :current]) is-script-running (get-in entities [:fg-actions :script-running?])] (and is-script-running - (= :none (get-in entities [:fg-actions :last-skip-type]))))) + (not= :end (get-in entities [:fg-actions :last-skip-type]))))) (defn update-override [{:keys [^FitViewport viewport] :as screen} entities] (let [raw-pos (get-in entities [:cursor :last-pos])