progress on interactions with cursors

This commit is contained in:
Bryce Covert
2016-08-11 21:22:56 -07:00
parent a3536d7b0d
commit 626eb12f98
7 changed files with 133 additions and 89 deletions

View File

@@ -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)