<commit_before>(ns escape-game.core
  (:require [escape-game.utils :refer :all]
            [escape-game.actions :refer :all]
            [play-clj.core :refer :all]
            [play-clj.g2d :refer :all] ))


;; forward declarations
(declare escape-game-game main-screen win-screen rooms)


;; asset manager
(defonce manager (asset-manager))


;; some generic functions
(def debug? true)
(defn debug
  "I print debugging information if I should."
  [& r]
  (when debug? (apply println r)))


;; helpers
(defn switch-to-room
  [room target]
  (debug "MOVING FROM" room "TO" target)
  (screen! main-screen :switch-to-room :target target)
  nil)

(defn map->entity
  "I take a map and return an entity merged with the map."
  [m]
  (merge (texture (:image m)) m))

(defn room->entities
  "I make a vector? of entities from an entry in the rooms map."
  [r]
  (debug "CREATING ROOM FOR" r "...")
  (let [room (get rooms r)]
    (map #(do (debug "LOADING THINGIE" (:name %) "WITH VAL" %)
              (map->entity %))
         room)))


;; since all entities need a name, image, x, y, width and height....
;; note that the macro doesn't expand to an actual entity but to a map
(defmacro defentity
  [name image x y width height & m]
  `(assoc {}
          :name ~name
          :image ~image
          :x ~x :y ~y
          :width ~width :height ~height
          ~@m))


;; a simple macro to make arrow definitions more concise
(defmacro arrow [direction target]
  `(defentity
    ({:left "left" :right "right"} ~direction)
    ({:left "images/arrowLeft.png" :right "images/arrowRight.png"} ~direction)
    ({:left 50 :right 600} ~direction) 200 64 64
    :action (fn
              [ent# screen# entities#]
              (switch-to-room (:current-room screen#) ~target))))

<commit_msg>Added when-selected macro<commit_after>(ns escape-game.core
  (:require [escape-game.utils :refer :all]
            [escape-game.actions :refer :all]
            [play-clj.core :refer :all]
            [play-clj.g2d :refer :all] ))


;; forward declarations
(declare escape-game-game main-screen win-screen rooms)


;; asset manager
(defonce manager (asset-manager))


;; some generic functions
(def debug? true)
(defn debug
  "I print debugging information if I should."
  [& r]
  (when debug? (apply println r)))


;; helpers
(defn switch-to-room
  [room target]
  (debug "MOVING FROM" room "TO" target)
  (screen! main-screen :switch-to-room :target target)
  nil)

(defn map->entity
  "I take a map and return an entity merged with the map."
  [m]
  (merge (texture (:image m)) m))

(defn room->entities
  "I make a vector? of entities from an entry in the rooms map."
  [r]
  (debug "CREATING ROOM FOR" r "...")
  (let [room (get rooms r)]
    (map #(do (debug "LOADING THINGIE" (:name %) "WITH VAL" %)
              (map->entity %))
         room)))


;; since all entities need a name, image, x, y, width and height....
;; note that the macro doesn't expand to an actual entity but to a map
(defmacro defentity
  [name image x y width height & m]
  `(assoc {}
          :name ~name
          :image ~image
          :x ~x :y ~y
          :width ~width :height ~height
          ~@m))


;; a simple macro to make arrow definitions more concise
(defmacro arrow [direction target]
  `(defentity
    ({:left "left" :right "right"} ~direction)
    ({:left "images/arrowLeft.png" :right "images/arrowRight.png"} ~direction)
    ({:left 50 :right 600} ~direction) 200 64 64
    :action (fn
              [ent# screen# entities#]
              (switch-to-room (:current-room screen#) ~target))))

;; these macros capture the symbols ent, screen and entities so they
;; can be used in the body
(defmacro when-selected
  [item & body]
  `(fn ~['ent 'screen 'entities]
     (if (selected? ~'screen ~item)
       (do ~@body)
       ~'ent)))


{'fraction_non_alphanumeric': 0.13896885632033498, 'fraction_numerical': 0.006804501439413766, 'mean_word_length': 2.7766798418972334, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3210427', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1227, 'n_words': 456}