comparison org/world.org @ 320:52de8a36edde

removed last vestiges of clojure.contrib
author Robert McIntyre <rlm@mit.edu>
date Thu, 01 Mar 2012 06:24:17 -0700
parents bb3f8a4af87f
children 939bcc5950b2
comparison
equal deleted inserted replaced
319:b84701e4f6ae 320:52de8a36edde
51 (ns cortex.world 51 (ns cortex.world
52 "World Creation, abstraction over jme3's input system, and REPL 52 "World Creation, abstraction over jme3's input system, and REPL
53 driven exception handling" 53 driven exception handling"
54 {:author "Robert McIntyre"} 54 {:author "Robert McIntyre"}
55 55
56 (:use (clojure.contrib (def :only (defn-memo))))
57 (:use [clojure.contrib [str-utils :only [re-gsub]]])
58
59 (:import com.aurellem.capture.IsoTimer) 56 (:import com.aurellem.capture.IsoTimer)
60 57
61 (:import com.jme3.math.Vector3f) 58 (:import com.jme3.math.Vector3f)
62 (:import com.jme3.scene.Node) 59 (:import com.jme3.scene.Node)
63 (:import com.jme3.system.AppSettings) 60 (:import com.jme3.system.AppSettings)
151 (integer? (.get field nil)))) 148 (integer? (.get field nil))))
152 149
153 (defn integer-constants [class] 150 (defn integer-constants [class]
154 (filter static-integer? (.getFields class))) 151 (filter static-integer? (.getFields class)))
155 152
156 (defn-memo constant-map 153 (defn constant-map
157 "Takes a class and creates a map of the static constant integer 154 "Takes a class and creates a map of the static constant integer
158 fields with their names. This helps with C wrappers where they have 155 fields with their names. This helps with C wrappers where they have
159 just defined a bunch of integer constants instead of enums" 156 just defined a bunch of integer constants instead of enums"
160 [class] 157 [class]
161 (let [integer-fields (integer-constants class)] 158 (let [integer-fields (integer-constants class)]
162 (into (sorted-map) 159 (into (sorted-map)
163 (zipmap (map #(.get % nil) integer-fields) 160 (zipmap (map #(.get % nil) integer-fields)
164 (map #(.getName %) integer-fields))))) 161 (map #(.getName %) integer-fields)))))
162 (alter-var-root #'constant-map memoize)
165 163
166 (defn all-keys 164 (defn all-keys
167 "Uses reflection to generate a map of string names to jme3 trigger 165 "Uses reflection to generate a map of string names to jme3 trigger
168 objects, which govern input from the keyboard and mouse" 166 objects, which govern input from the keyboard and mouse"
169 [] 167 []
170 (let [inputs (constant-map KeyInput)] 168 (let [inputs (constant-map KeyInput)]
171 (assoc 169 (assoc
172 (zipmap (map (fn [field] 170 (zipmap (map (fn [field]
173 (.toLowerCase (re-gsub #"_" "-" field))) (vals inputs)) 171 (.toLowerCase (.replaceAll field "_" "-"))) (vals inputs))
174 (map (fn [val] (KeyTrigger. val)) (keys inputs))) 172 (map (fn [val] (KeyTrigger. val)) (keys inputs)))
175 ;;explicitly add mouse controls 173 ;;explicitly add mouse controls
176 "mouse-left" (MouseButtonTrigger. 0) 174 "mouse-left" (MouseButtonTrigger. 0)
177 "mouse-middle" (MouseButtonTrigger. 2) 175 "mouse-middle" (MouseButtonTrigger. 2)
178 "mouse-right" (MouseButtonTrigger. 1)))) 176 "mouse-right" (MouseButtonTrigger. 1))))