<commit_before>(in-ns 'play-clj.core)

; drawing

(defmulti sprite-batch #(-> % :renderer class) :default nil)

(defmethod sprite-batch nil
  [screen]
  (SpriteBatch.))

(defmethod sprite-batch BatchTiledMapRenderer
  [{:keys [^BatchTiledMapRenderer renderer]}]
  (.getSpriteBatch renderer))

(defmethod sprite-batch Stage
  [{:keys [^Stage renderer]}]
  (.getSpriteBatch renderer))

(defn draw! [{:keys [renderer] :as screen} entities]
  (assert renderer)
  (let [^SpriteBatch batch (sprite-batch screen)]
    (.begin batch)
    (doseq [e entities]
      (cond
        (map? e)
        (let [{:keys [^TextureRegion image x y width height]} e]
          (.draw batch image (float x) (float y) (float width) (float height)))
        (isa? (type e) Actor)
        (.draw ^Actor e batch 1)))
    (.end batch))
  entities)

; textures

(defn image
  [val]
  (if (string? val)
    (-> ^String val Texture. TextureRegion.)
    (TextureRegion. ^TextureRegion val)))

(defn split-image
  ([val size]
    (split-image val size size))
  ([val width height]
    (-> val ^TextureRegion image (.split width height))))

(defn flip-image
  [val x? y?]
  (doto ^TextureRegion (image val) (.flip x? y?)))

(defmacro animation
  [duration images & args]
  `(Animation. ~duration
               (utils/gdx-into-array ~images)
               (utils/gdx-static-field :graphics :g2d :Animation
                                       ~(or (first args) :normal))))<commit_msg>Add image-width and image-height<commit_after>(in-ns 'play-clj.core)

; drawing

(defmulti sprite-batch #(-> % :renderer class) :default nil)

(defmethod sprite-batch nil
  [screen]
  (SpriteBatch.))

(defmethod sprite-batch BatchTiledMapRenderer
  [{:keys [^BatchTiledMapRenderer renderer]}]
  (.getSpriteBatch renderer))

(defmethod sprite-batch Stage
  [{:keys [^Stage renderer]}]
  (.getSpriteBatch renderer))

(defn draw! [{:keys [renderer] :as screen} entities]
  (assert renderer)
  (let [^SpriteBatch batch (sprite-batch screen)]
    (.begin batch)
    (doseq [e entities]
      (cond
        (map? e)
        (let [{:keys [^TextureRegion image x y width height]} e]
          (.draw batch image (float x) (float y) (float width) (float height)))
        (isa? (type e) Actor)
        (.draw ^Actor e batch 1)))
    (.end batch))
  entities)

; textures

(defn image
  [val]
  (if (string? val)
    (-> ^String val Texture. TextureRegion.)
    (TextureRegion. ^TextureRegion val)))

(defn image-width
  ([^TextureRegion img]
    (.getRegionWidth img))
  ([^TextureRegion img val]
    (.setRegionWidth img val)))

(defn image-height
  ([^TextureRegion img]
    (.getRegionHeight img))
  ([^TextureRegion img val]
    (.setRegionHeight img val)))

(defn split-image
  ([val size]
    (split-image val size size))
  ([val width height]
    (-> val ^TextureRegion image (.split width height))))

(defn flip-image
  [val x? y?]
  (doto ^TextureRegion (image val) (.flip x? y?)))

(defmacro animation
  [duration images & args]
  `(Animation. ~duration
               (utils/gdx-into-array ~images)
               (utils/gdx-static-field :graphics :g2d :Animation
                                       ~(or (first args) :normal))))
{'fraction_non_alphanumeric': 0.14626490897677338, 'fraction_numerical': 0.0012554927809165098, 'mean_word_length': 2.9443069306930694, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6506113', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1037, 'n_words': 314}