 (println "test mk-entity"
          (mk-entity {} :player1 [:a :b]))
 
+(defn get-component-fns
+  [state component-id]
+  (get-in state [:components component-id :fns]))
+
 (defn get-component-state
   [state component-id entity-id]
-  (get-in state [:components component-id :state entity-id]))
+  (or (get-in state [:components component-id :state entity-id])
+      {}))
 
 (defn mk-component-state
   "Returns a hashmap that can be merged into the state hashmap

    (apply merge-with deep-merge vals)
    (last vals)))

(println "test deep-merge" (deep-merge {:a 1} {:b {:c 2}}))

(defn entities-with-component
  "Takes a hashmap and returns all keys whose values contain component-id"

   merged into the game state."
  [component-id f]
  (fn [state entity-id]
    (let [r (mk-component-state
             component-id
             entity-id
             (f (get-component-state state component-id entity-id)
                entity-id))]
      (println "component-fn result" r)
      r)))

(println "test mk-component-fn"
         ((mk-component-fn :test (fn [& args] (identity {:foo "bar"})))
