(ns advent.screens.rooms.cat-tree
  (:require [advent.screens.rooms :as rooms]
            [advent.actions :as actions]
            [advent.utils :as utils]
            [clojure.zip :as zip]
            [play-clj.core :refer :all]
            [play-clj.ui :refer :all]
            [play-clj.utils :refer :all]
            [play-clj.g2d :refer :all]))

(defn make [screen]
  (let [cat-stand-sheet (texture! (texture "cat-tree/cat-stand.png") :split 22 10)
        cat-stand (animation 0.15 (for [i (flatten [(repeat 10 0) 1 1 (repeat 10 0) 2 3 4 3 0  0 2 3 4 3 (repeat 10 0) 1 1 (repeat 10 0) 5 5 6 6 7 (repeat 10 [7 8]) 6 5 0])]
                                   (aget cat-stand-sheet 0 i)))]
    (rooms/make :interactions
                {:down-dir {:box [150 0 270 20]
                            :script (actions/get-script entities
                                                        (actions/walk-to entities :ego [203 1])
                                                        (actions/transition-background entities :outside-house [137 204])
                                                        (actions/walk-to entities :ego [195 140]))
                            :cursor :down}}
                :layers [(assoc (texture "cat-tree/background.png") :x 0 :y 0 :baseline 0)
                         (assoc (texture "cat-tree/tree-and-rock.png") :x 0 :y 0 :baseline 161)
                         (assoc (texture "cat-tree/sillhoute.png") :x 0 :y 0 :baseline 240)]
                :entities { :cat (actions/start-animation screen
                                                          (assoc (animation->texture screen cat-stand)
                                                            :x 184 :y 173 :baseline 240
                                                            :script (actions/get-script entities
                                                                                        (actions/talk entities :ego "Here kitty, kitty, kitty.")
                                                                                        (actions/talk entities :ego "Kitty's not so interested in me.")))
                                                          cat-stand)}
                :collision "cat-tree/collision.png"
                :scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.20))))
