33 lines
1.8 KiB
Clojure
33 lines
1.8 KiB
Clojure
(ns advent.screens.rooms
|
|
(:require [advent.zone :as zone]))
|
|
|
|
(defn make-entity [id entity]
|
|
(merge entity
|
|
{:mouse-in? (fn [entities x y]
|
|
(let [{entity-x :x entity-y :y width :width height :height region :object} (get-in entities [:room :entities id])
|
|
width (or width (.getRegionWidth region))
|
|
height (or height (.getRegionHeight region))]
|
|
((zone/box entity-x entity-y (+ entity-x width) (+ entity-y height)) x y)))}
|
|
(when (:script entity)
|
|
{:get-script (fn [cursor [x y]]
|
|
(if (= :main cursor)
|
|
(:script entity)
|
|
(when-let [scripts (:scripts entity)]
|
|
(scripts (:value cursor)))))})))
|
|
(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)]
|
|
(scripts (:value cursor)))))}))
|
|
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})))
|
|
|
|
|