(ns advent.screens.rooms (:require [advent.zone :as zone]) (:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter] [com.badlogic.gdx.graphics.g2d TextureRegion] [com.badlogic.gdx.utils.viewport FitViewport] [com.badlogic.gdx.scenes.scene2d Actor Stage] [java.lang Object])) (defn make-entity [id entity] (merge entity {:mouse-in? (fn [entities x y] (let [{entity-x :x entity-y :y width :width scale-x :scale-x scale-y :scale-y origin-x :origin-x origin-y :origin-y height :height region :object} (get-in entities [:room :entities id]) width (or width (if (instance? TextureRegion region ) (.getRegionWidth region) 0)) height (or height (if (instance? TextureRegion region ) (.getRegionHeight region) 0)) entity-x (- entity-x (* (or origin-x 0) (or scale-x 1))) entity-y (- entity-y (* (or origin-y 0) (or scale-y 1)))] ((zone/box entity-x entity-y (+ entity-x (* width (or scale-x 1))) (+ entity-y (* height (or scale-y 1)))) x y)))} (when (or (:scripts entity) (:script entity)) {:get-script (fn [cursor [x y]] (if (= :main cursor) (:script entity) (when-let [scripts (:scripts entity)] (or (scripts (:value cursor)) (scripts :default)))))}))) (defn make [& {:keys [collision interactions entities] :as params}] (let [interactions-as-list (for [[id spec] interactions] (merge spec {:mouse-in? (fn [_ x y] ((apply zone/box (:box spec)) x y)) :get-script (fn [cursor [x y]] (if (= :main cursor) (:script spec) (when-let [scripts (:scripts spec)] (or (scripts (:value cursor)) (scripts :default))))) :id id})) entities (into {} (for [[id entity] entities] [id (make-entity id entity)]))] (merge params {:collision (advent.pathfind/map-from-resource collision) :interactions interactions-as-list :entities entities})))