<commit_before>(ns chocolatier.engine.entities
  ;; NOTE to use protocols from another ns, import them explicitely by
  ;; name and not their methods
  ;; Use them in this ns by refering to the name
  (:use [chocolatier.utils.logging :only [debug info warn error]])  
  (:require [chocolatier.engine.components :refer [Entity
                                                   Renderable
                                                   Controllable]]))


(defrecord Bunny [id sprite x y]
  Entity
  (tick [this]
    (let [sprite (:sprite this)
          old-rotation (aget sprite "rotation")]
      (aset sprite "rotation" (+ 0.01 old-rotation))))
  
  Renderable
  (render [this stage]
    (.addChild stage (:sprite this)))

  Controllable
  (react-to-user-input [this state time]
    (let [sprite (:sprite this)
          control-keys #{:W :A :S :D}
          input @(:input state)
          move-rate 1
          move #(condp = %
                      :W (set! (.-position.y sprite)
                               (- (.-position.y sprite) move-rate))
                      :A (set! (.-position.x sprite)
                               (- (.-position.x sprite) move-rate))
                      :S (set! (.-position.y sprite)
                               (+ (.-position.y sprite) move-rate))
                      :D (set! (.-position.x sprite)
                               (+ (.-position.x sprite) move-rate))
                      :else nil)]
      (doseq [[k v] input]
        (when (= v "on")
          (move k))))))<commit_msg>Add direction arrow pad support to controls<commit_after>(ns chocolatier.engine.entities
  ;; NOTE to use protocols from another ns, import them explicitely by
  ;; name and not their methods
  ;; Use them in this ns by refering to the name
  (:use [chocolatier.utils.logging :only [debug info warn error]])  
  (:require [chocolatier.engine.components :refer [Entity
                                                   Renderable
                                                   Controllable]]))


(defrecord Bunny [id sprite x y]
  Entity
  (tick [this] nil)
  
  Renderable
  (render [this stage]
    (.addChild stage (:sprite this)))

  Controllable
  (react-to-user-input [this state time]
    (let [sprite (:sprite this)
          input @(:input state)
          move-rate 1
          move #(condp = %
                      :W (set! (.-position.y sprite)
                               (- (.-position.y sprite) move-rate))
                      :A (set! (.-position.x sprite)
                               (- (.-position.x sprite) move-rate))
                      :S (set! (.-position.y sprite)
                               (+ (.-position.y sprite) move-rate))
                      :D (set! (.-position.x sprite)
                               (+ (.-position.x sprite) move-rate))
                      :& (set! (.-position.y sprite)
                               (- (.-position.y sprite) move-rate))
                      :% (set! (.-position.x sprite)
                               (- (.-position.x sprite) move-rate))
                      ;; Parenths are reserved so wrap it in keyword call
                      (keyword "(") (set! (.-position.y sprite)
                                            (+ (.-position.y sprite) move-rate))
                      :' (set! (.-position.x sprite)
                               (+ (.-position.x sprite) move-rate))
                      ;; Otherwise do nothing
                      nil)]
      (doseq [[k v] input]
        (when (= v "on")
          (move k))))))
{'fraction_non_alphanumeric': 0.12314165497896214, 'fraction_numerical': 0.001402524544179523, 'mean_word_length': 1.2455919395465995, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 21, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1337157', 'n_tokens_mistral': 987, 'n_tokens_neox': 913, 'n_words': 286}