you must click the same target to have a script kick off.
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
|
||||
(defn make-entity [id entity]
|
||||
(merge entity
|
||||
{:mouse-in? (fn [entities x y]
|
||||
{:id id
|
||||
: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))
|
||||
|
||||
@@ -241,38 +241,48 @@ void main()
|
||||
:else
|
||||
entities)))
|
||||
|
||||
(defn get-interaction [entities x y]
|
||||
(first (filter #((:mouse-in? %) entities x y)
|
||||
(get-in entities [:room :interactions]))) )
|
||||
|
||||
(defn get-interacting-entity [entities x y]
|
||||
(let [interactable-entities (if (= (doto (get-in entities [:cursor :current]) println) :main)
|
||||
(vals (dissoc (get-in entities [:room :entities]) :ego))
|
||||
(vals (get-in entities [:room :entities])))
|
||||
interacting-entity (first (sort-by (comp - :baseline)
|
||||
(filter #(and (:mouse-in? %)
|
||||
(:get-script %)
|
||||
((:mouse-in? %) entities x y))
|
||||
interactable-entities)))]
|
||||
interacting-entity))
|
||||
|
||||
(defn left-click [screen entities]
|
||||
(let [[x y] (utils/unproject screen)]
|
||||
(println "clicked " x y)
|
||||
(let [interaction (first (filter #((:mouse-in? %) entities x y)
|
||||
(get-in entities [:room :interactions])))
|
||||
interactable-entities (if (= (doto (get-in entities [:cursor :current]) println) :main)
|
||||
(vals (dissoc (get-in entities [:room :entities]) :ego))
|
||||
(vals (get-in entities [:room :entities])))
|
||||
interacting-entity (first (sort-by (comp - :baseline)
|
||||
(filter #(and (:mouse-in? %)
|
||||
(:get-script %)
|
||||
((:mouse-in? %) entities x y))
|
||||
interactable-entities)))
|
||||
current-action (get-in entities [:actions :current])
|
||||
|
||||
;; TODO - hacky way of resetting queue
|
||||
|
||||
entities (if current-action
|
||||
(skip-action screen entities)
|
||||
entities)]
|
||||
|
||||
(if (get-in entities [:actions :script-running?])
|
||||
entities
|
||||
((or (when interacting-entity
|
||||
((:get-script interacting-entity) (get-in entities [:cursor :current]) [x y]))
|
||||
(when interaction
|
||||
((:get-script interaction) (or (when (:cursor interaction) :main)
|
||||
(get-in entities [:cursor :current]))
|
||||
[x y]))
|
||||
|
||||
((:get-script default-interaction) (get-in entities [:cursor :current]) [x y])) entities))
|
||||
entities)))
|
||||
(let [[x y] (utils/unproject screen)
|
||||
_ (println "clicked " x y)
|
||||
interaction (get-interaction entities x y)
|
||||
interacting-entity (get-interacting-entity entities x y)
|
||||
current-action (get-in entities [:actions :current])
|
||||
|
||||
;; TODO - hacky way of resetting queue
|
||||
|
||||
entities (if (and current-action
|
||||
(= (get-in entities [:cursor :down-target])
|
||||
(or (:id interacting-entity) (:id interaction) nil)))
|
||||
(skip-action screen entities)
|
||||
entities)]
|
||||
|
||||
(when (and (not (get-in entities [:actions :script-running?]))
|
||||
(= (get-in entities [:cursor :down-target])
|
||||
(or (:id interacting-entity) (:id interaction) nil)))
|
||||
((or (when interacting-entity
|
||||
((:get-script interacting-entity) (get-in entities [:cursor :current]) [x y]))
|
||||
(when interaction
|
||||
((:get-script interaction) (or (when (:cursor interaction) :main)
|
||||
(get-in entities [:cursor :current]))
|
||||
[x y]))
|
||||
|
||||
((:get-script default-interaction) (get-in entities [:cursor :current]) [x y])) entities))
|
||||
(assoc-in entities [:cursor :down-target] nil)))
|
||||
|
||||
(defn drink-blergh [entities]
|
||||
(actions/walk-straight-to entities :ego [205 45])
|
||||
@@ -920,7 +930,8 @@ void main()
|
||||
:current :main
|
||||
:last nil
|
||||
:override :hourglass
|
||||
:last-pos [0 0]}
|
||||
:last-pos [0 0]
|
||||
:down-target nil}
|
||||
|
||||
:all-items (assoc items/items :object nil)
|
||||
:started? {:value false
|
||||
@@ -1036,6 +1047,21 @@ void main()
|
||||
:on-touch-dragged
|
||||
mouse-moved
|
||||
|
||||
:on-touch-down
|
||||
(fn [{:keys [input-x input-y viewport] :as screen} [entities]]
|
||||
(when (utils/contains-point? (.getScreenX viewport) (.getScreenY viewport)
|
||||
(.getScreenWidth viewport) (.getScreenHeight viewport)
|
||||
input-x input-y)
|
||||
(when (and (= (button-code :left)
|
||||
(:button screen))
|
||||
(get-in entities [:state :active?])
|
||||
(not (get-in entities [:state :hud-active?]))
|
||||
(= 0.0 (get-in entities [:fade :opacity])))
|
||||
(let [[x y] (utils/unproject screen)
|
||||
interaction (get-interaction entities x y)
|
||||
interacting-entity (get-interacting-entity entities x y)]
|
||||
(assoc-in entities [:cursor :down-target] (or (:id interacting-entity ) (:id interaction) nil))))))
|
||||
|
||||
:on-touch-up (fn [{:keys [input-x input-y viewport] :as screen} [entities]]
|
||||
(when (utils/contains-point? (.getScreenX viewport) (.getScreenY viewport)
|
||||
(.getScreenWidth viewport) (.getScreenHeight viewport)
|
||||
|
||||
Reference in New Issue
Block a user