# HG changeset patch # User Robert McIntyre # Date 1319460110 25200 # Node ID bbffa41a12a9e9da6b3bda73f051cfb70caad574 # Parent 775d97247dd07049311c8eb461477183f72e240d moved apply-map to util.org from world.org, fixed some grammar problems, made examples more concise diff -r 775d97247dd0 -r bbffa41a12a9 org/util.org --- a/org/util.org Mon Oct 24 05:25:01 2011 -0700 +++ b/org/util.org Mon Oct 24 05:41:50 2011 -0700 @@ -217,6 +217,16 @@ (add-element game element (.getRootNode game)))) +(defn apply-map + "Like apply, but works for maps and functions that expect an + implicit map and nothing else as in (fn [& {}]). + ------- Example ------- + (defn demo [& {:keys [www] :or {www \"oh yeah\"} :as env}] + (println www)) + (apply-map demo {:www \"hello!\"}) + -->\"hello\"" + [fn m] + (apply fn (reduce #(into %1 %2) [] m))) #+end_src diff -r 775d97247dd0 -r bbffa41a12a9 org/world.org --- a/org/world.org Mon Oct 24 05:25:01 2011 -0700 +++ b/org/world.org Mon Oct 24 05:41:50 2011 -0700 @@ -193,52 +193,32 @@ : fields with their names. This helps with C wrappers where they have : just defined a bunch of integer constants instead of enums +#+begin_src clojure :exports both :results verbatim +(take 5 (vals (pokemon.lpsolve/constant-map KeyInput))) +#+end_src + +#+results: +: ("KEY_ESCAPE" "KEY_1" "KEY_2" "KEY_3" "KEY_4") + =(all-keys)= converts the constant names like =KEY_J= to the more clojure-like =key-j=, and returns a map from these keys to jMonkeyEngine =KeyTrigger= objects, which jMonkeyEngine3 uses as it's abstraction over the physical keys. =all-keys= also adds the three mouse button controls to the map. - #+begin_src clojure :exports both :results output (require 'clojure.contrib.pprint) (clojure.contrib.pprint/pprint - (take 10 (keys (cortex.world/all-keys)))) + (take 6 (cortex.world/all-keys))) #+end_src #+results: -#+begin_example -("key-n" - "key-apps" - "key-pgup" - "key-f8" - "key-o" - "key-at" - "key-f9" - "key-0" - "key-p" - "key-subtract") -#+end_example - -#+begin_src clojure :exports both :results output -(clojure.contrib.pprint/pprint - (take 10 (vals (cortex.world/all-keys)))) -#+end_src - -#+results: -#+begin_example -(# - # - # - # - # - # - # - # - # - #) -#+end_example - +: (["key-n" #] +: ["key-apps" #] +: ["key-pgup" #] +: ["key-f8" #] +: ["key-o" #] +: ["key-at" #]) ** World Creation @@ -351,27 +331,15 @@ ;; focus. (.setPauseOnLostFocus false) (.setSettings *app-settings*)))) - -(defn apply-map - "Like apply, but works for maps and functions that expect an - implicit map and nothing else as in (fn [& {}]). - ------- Example ------- - (defn demo [& {:keys [www] :or {www \"oh yeah\"} :as env}] - (println www)) - (apply-map demo {:www \"hello!\"}) - -->\"hello\"" - [fn m] - (apply fn (reduce #(into %1 %2) [] m))) - #+end_src =(world)= is the most important function here. It presents a more -functional interface to the Application life-cycle, and all it's -objects except =root-node= are plain clojure data structures. It's now -possible to extend functionally by composing multiple functions -together, and to add more keyboard-driven actions by combining clojure -maps. +functional interface to the Application life-cycle, and all its +arguments except =root-node= are plain immutable clojure data +structures. This makes it easier to extend functionally by composing +multiple functions together, and to add more keyboard-driven actions +by combining clojure maps.