 (ns voke.pixi
-  (:require [cljsjs.pixi]
-            [voke.schemas :refer [Entity Shape System]])
-  (:require-macros [schema.core :as sm]))
+  (:require [cljs.spec :as s]
+            [cljsjs.pixi]))
 
 (defn make-renderer
   [width height node]


(defn render! [entities]
  (handle-unknown-entities! (filter
                              #(not (contains? @graphics-data-by-entity-id (:id %)))
                              entities))
  ; TODO update entity visibility
  ; TODO something something camera

      (aset "y" (- y (/ h 2))))
    graphics-data))

(defn entity->graphics-data!
  [entity]
  (rectangle (-> entity :component/shape :shape/center :geometry/x)
             (-> entity :component/shape :shape/center :geometry/y)
             (-> entity :component/shape :shape/width)
             (-> entity :component/shape :shape/height)
             (-> entity :component/render :render/fill)))

(s/fdef entity->graphics-data!
  :args (s/cat :entity :entity/entity))

(defn handle-unknown-entities! [entities]
  ; TODO - only actually operate on the entity if it's visible
  (doseq [entity entities]
    (swap! graphics-data-by-entity-id
           assoc
           (:entity/id entity)
           (entity->graphics-data! entity))))

(defn update-entity-position!
  [entity-id new-center]
  (let [graphics-data (@graphics-data-by-entity-id entity-id)]
    (when graphics-data
      (let [shape (aget graphics-data "shape")]
        (aset shape "x" (- (new-center :geometry/x) (/ (aget shape "width") 2)))
        (aset shape "y" (- (new-center :geometry/y) (/ (aget shape "height") 2)))))))

(s/fdef update-entity-position!
  :args (s/cat :entity-id :entity/id
               :new-center :geometry/vector2))

(defn remove-entity!
  [entity-id]
