replace input state machine with much simpler one autogenerated from stm minilanguage

This commit is contained in:
Jeremy Penner 2013-04-05 21:17:15 -04:00
parent 907b45a8ef
commit de29d67036

View file

@ -5,31 +5,14 @@
(:require [hottub.stm :as stm] (:require [hottub.stm :as stm]
[hottub.gs :as gs])) [hottub.gs :as gs]))
(defn is-active [input v] (defn is-active [v input]
(contains? (:mousebuttons input) :left)) (contains? (:mousebuttons input) :left))
(defn is-input-event [event] (stm/defstm :click
(= (:type event) :input)) [(::stm/enter {:returns-value false} [stm]
(let [input-now (:input (first (gs/q :name :input)))
(defn advance [stm input state-next activehigh] stm (stm/post-event stm (assoc input-now :type :input))]
(let [active (is-active input (stm/value stm))] stm))
(if (or (and activehigh active) (and (not activehigh) (not active))) (:input #(not (is-active %1 %2)))]
(stm/goto stm state-next)))) [(:input is-active)]
[(:input #(not (is-active %1 %2)))])
(defmethod stm/enter-state [:click :start] [stm]
(let [input-now (:input (first (gs/q :name :input)))]
(stm/post-event stm (assoc input-now :type :input))))
(defmethod stm/on-event [:click :start] [stm event]
(if (is-input-event event)
(advance stm event :wait-for-press false)))
(defmethod stm/on-event [:click :wait-for-press] [stm event]
(if (is-input-event event)
(advance stm event :wait-for-release true)))
(defmethod stm/on-event [:click :wait-for-release] [stm event]
(if (is-input-event event)
(advance stm event :end false)))