(ns sekai.core.components
  (:require [sekai.core.pixi :as pixi]
            [sekai.core.entity :as entity]))

(defn- manip-tag [fun tag] (fn [eid] (fun eid tag)))
(defn- add-tag [tag] (manip-tag entity/register-tag! tag))
(defn- remove-tag [tag] (manip-tag entity/deregister-tag! tag))

(defmulti attach (fn [component _] (:name component)))
(defmulti detach (fn [component _] (:name component)))

(defn position [x y]
  {:name :position
   :data [x y]
   :hook (add-tag :spatial)})
(defmethod attach :position [{:keys [data]} eid]
  (print data eid))

(defn tags [& tags]
  {:name :tags
   :data (set tags)
   :hook nil})

(defn sprite [url]
  {:name :sprite
   :data (pixi/make-sprite! url)
   :hook (add-tag :renderable)})
