From de29d670366ee29ee1e6964529b4c06a13db7301 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Fri, 5 Apr 2013 21:17:15 -0400 Subject: [PATCH] replace input state machine with much simpler one autogenerated from stm minilanguage --- src/hottub/stm/input.clj | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/hottub/stm/input.clj b/src/hottub/stm/input.clj index 9721f7c..b2f9885 100644 --- a/src/hottub/stm/input.clj +++ b/src/hottub/stm/input.clj @@ -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)))])