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]
[hottub.gs :as gs]))
(defn is-active [input v]
(defn is-active [v input]
(contains? (:mousebuttons input) :left))
(defn is-input-event [event]
(= (:type event) :input))
(defn advance [stm input state-next activehigh]
(let [active (is-active input (stm/value stm))]
(if (or (and activehigh active) (and (not activehigh) (not active)))
(stm/goto stm state-next))))
(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)))
(stm/defstm :click
[(::stm/enter {:returns-value false} [stm]
(let [input-now (:input (first (gs/q :name :input)))
stm (stm/post-event stm (assoc input-now :type :input))]
stm))
(:input #(not (is-active %1 %2)))]
[(:input is-active)]
[(:input #(not (is-active %1 %2)))])