 
           (let [direction (msg :direction)
                 update-entity-args (case (msg :type)
-                                     :move-key-down [[:input :intended-move-direction] conj direction]
-                                     :move-key-up [[:input :intended-move-direction] disj direction]
-                                     :fire-key-down [[:input :intended-fire-direction]
+                                     :move-key-down [[:component/input :input/intended-move-direction] conj direction]
+                                     :move-key-up [[:component/input :input/intended-move-direction] disj direction]
+                                     :fire-key-down [[:component/input :input/intended-fire-direction]
                                                      (fn [fire-directions]
                                                        (if (in? fire-directions direction)
                                                          fire-directions
                                                          (conj fire-directions direction)))]
-                                     :fire-key-up [[:input :intended-fire-direction]
+                                     :fire-key-up [[:component/input :input/intended-fire-direction]
                                                    (fn [fire-directions]
                                                      (filterv #(not= direction %) fire-directions))])]
 

          directions
          [#{:up :down} #{:left :right}]))

(sm/defn human-controlled-entity-movement-directions
  [entity :- Entity]
  (-> entity
      (safe-get-in [:input :intended-move-direction])
      remove-conflicting-directions))

(sm/defn intended-directions->angle :- Direction
  [intended-directions :- [IntendedDirection]]
  (let [intended-direction-values (map direction-value-mappings intended-directions)]
    (Math/atan2 (apply + (map Math/sin intended-direction-values))
                (apply + (map Math/cos intended-direction-values)))))

(sm/defn update-move-direction :- Entity
  [entity :- Entity]
  (let [intended-directions (human-controlled-entity-movement-directions entity)]
    (if (seq intended-directions)
      (assoc-in entity
                [:motion :direction]
                (intended-directions->angle intended-directions))
      (assoc-in entity
                [:motion :direction]
                nil))))

(sm/defn update-fire-direction :- Entity
  [entity :- Entity]
  (let [intended-direction (last (get-in entity [:input :intended-fire-direction]))]
    (if intended-direction
      (assoc-in entity
                [:weapon :fire-direction]
                (intended-directions->angle [intended-direction]))
      (assoc-in entity [:weapon :fire-direction] nil))))

;;; Public


(ns voke.input
  (:require [cljs.spec :as s]
            [clojure.set :refer [intersection difference subset?]]
            [clojure.string :refer [starts-with?]]
            [cljs.core.async :refer [chan <! put!]]
            [goog.events :as events]
            [plumbing.core :refer [safe-get-in]]
            [voke.state :refer [update-entity!]]
            [voke.util :refer [in?]])
  (:import [goog.events KeyCodes])
  (:require-macros [cljs.core.async.macros :refer [go-loop]]))

(def move-key-mappings {KeyCodes.W     :up
                        KeyCodes.A     :left
