                     :cx x
                     :cy y
                     :r (/ TILE-SIZE 2)}]])))))
+
+(defmulti action-view :type)
+(defmethod action-view "laser"
+  [{:keys [start stop]}]
+  (laser-shot start stop))
+(defmethod action-view "droid"
+  [action]
+  (html [:g]))
+(defmethod action-view "mortar"
+  [action]
+  (html [:g]))
+(defmethod action-view :default [_]
+  (html [:g]))
 
 (defn world-view [state owner]
   (reify

(ns skyport.core
  (:require-macros [cljs.core.async.macros :refer (go go-loop)])
  (:require [cljs.core.async :refer (<! >! put! chan close!)]
            [clojure.string :as str]
            [clojure.walk :refer [keywordize-keys]]
            [chord.client :as socket :refer (ws-ch)]

                    :position [12 0]}]
         :message "gamestate"}))

(defn coords-to-pixel [[j k]]
  [(+ X-OFFSET (* TILE-SIZE
                  (/ 3 2)
                  (+ 2 (- k j))))
   (+ Y-OFFSET (* (/ TILE-SIZE 2)
                  (js/Math.sqrt 3)
                  (+ k (- j 2))))])


(defmulti handle-action :type)

(defmethod handle-action "laser"
  [{:keys [from stop] :as action}]
  (let [start (->> @state
                  :players
                  (drop-while (comp (partial not= from)
                                    :name))
                  first
                  :position)]
    (swap! state assoc :action
           (assoc action
             :start (coords-to-pixel start)
             :stop (coords-to-pixel stop)))))

(defmethod handle-action "droid"
  [action]
  (swap! state assoc :action action))

(defmethod handle-action "mortar"
  [action]
  (swap! state assoc :action action))

(defmethod handle-action "move"
  [{:keys [direction from]}]
  (let [[x y] (case direction
                "up"         [-1 -1]
                "left-up"    [ 0 -1]
                "right-up"   [-1  0]
                "down"       [ 1  1]
                "left-down"  [ 1  0]
                "right-down" [ 0  1])]
    (swap! state update-in [:players]
           (partial mapv (fn [{:keys [name position] :as player}]
                           (if-not (= name from)
                             player
                             (assoc-in player [:position] (mapv + [x y] position))))))))

(defmethod handle-action :default [_]
  ;; Do nothing.
