progress on interactions with cursors
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
[com.badlogic.gdx.scenes.scene2d Actor Stage]
|
||||
[java.lang Object]))
|
||||
|
||||
(defn make-entity [id entity]
|
||||
(defn make-entity [id {:keys [scripts script only-script] :as entity}]
|
||||
(merge entity
|
||||
{:id id
|
||||
:mouse-in? (fn [entities x y]
|
||||
@@ -22,24 +22,41 @@
|
||||
((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))
|
||||
(when (or script scripts only-script)
|
||||
{:get-script (fn [cursor [x y]]
|
||||
(if (= :main cursor)
|
||||
(:script entity)
|
||||
(when-let [scripts (:scripts entity)]
|
||||
(or (scripts (:value cursor)) (scripts :default)))))})))
|
||||
(cond only-script
|
||||
only-script
|
||||
|
||||
(= :main cursor)
|
||||
script
|
||||
|
||||
scripts
|
||||
(or (scripts (:value cursor)) (scripts :default))
|
||||
|
||||
:else
|
||||
nil)
|
||||
)})))
|
||||
(defn make [& {:keys [collision interactions entities] :as params}]
|
||||
(let [interactions-as-list (for [[id spec] interactions]
|
||||
(let [interactions-as-list (for [[id {:keys [script scripts only-script box] :as spec}] interactions]
|
||||
(merge spec
|
||||
(when (:box spec)
|
||||
(when box
|
||||
{: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}))
|
||||
((apply zone/box box) x y))})
|
||||
(when (or script scripts only-script)
|
||||
{:get-script (fn [cursor [x y]]
|
||||
(cond only-script
|
||||
only-script
|
||||
|
||||
(= :main cursor)
|
||||
script
|
||||
|
||||
scripts
|
||||
(or (scripts (:value cursor)) (scripts :default))
|
||||
|
||||
:else
|
||||
nil)
|
||||
)})
|
||||
{:id id}))
|
||||
entities (into {} (for [[id entity] entities]
|
||||
[id (make-entity id entity)]))]
|
||||
(merge params {:collision (advent.pathfind/map-from-resource collision)
|
||||
|
||||
Reference in New Issue
Block a user