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