(ns sekai.core.init
  (:require ["pixi.js" :as PIXI]
            [sekai.core.gamestate :refer [game-state]]
            [sekai.core.pixi :as pixi]))

(defn render []
  (let [state @game-state
        bnuuy (get-in state [:entities :bnuuy])
        sprite (:sprite bnuuy)
        position (:position bnuuy)]
    (set! (.-x sprite) (:x position))
    (set! (.-y sprite) (:y position))
    (set! (.-rotation sprite) (:angle bnuuy))
    ))

(defn init []
  (println "Hello World")
  (let [game (pixi/make-canvas! 256 256)
        bnuuy (-> PIXI .-Sprite (.from "https://pixijs.com/assets/bunny.png"))]

    (.appendChild js/document.body (.-view game))
    (set! (.-className (.-view game)) "game-view")

    (-> game .-stage (.addChild bnuuy))
    (-> bnuuy .-anchor (.set 0.5))

;    (-> game .-ticker (.add (fn [delta] (gameloop delta))))

    (println game)))
