item interactions.

This commit is contained in:
2014-10-01 20:42:26 -07:00
parent d235017423
commit 6c0acd1ae6

View File

@@ -27,14 +27,17 @@
(cursor-override [this])) (cursor-override [this]))
(defprotocol IInteractable (defprotocol IInteractable
(get-script [this location])) (get-script [this cursor location]))
(def default-interaction (def default-interaction
(reify (reify
IInteractable IInteractable
(get-script [_ [x y]] (get-script [_ cursor [x y]]
(actions/get-script entities (if (= :main cursor)
(actions/walk-to entities :ego [x y] true))))) (actions/get-script entities
(actions/walk-to entities :ego [x y] true))
(actions/get-script entities
(actions/talk entities :ego "I don't know what to do with that."))))))
(defn find-override [screen entities [x y]] (defn find-override [screen entities [x y]]
@@ -68,8 +71,8 @@
(if current-action (if current-action
entities entities
((or (when interaction ((or (when interaction
(get-script interaction [x y])) (get-script interaction (get-in entities [:cursor :current]) [x y]))
(get-script default-interaction [x y])) entities)) (get-script default-interaction (get-in entities [:cursor :current]) [x y])) entities))
entities)))) entities))))
(defn flip [anim] (defn flip [anim]
@@ -145,8 +148,10 @@
(mouse-in? [_ location] (mouse-in? [_ location]
(apply (apply zone/box (:box spec)) location)) (apply (apply zone/box (:box spec)) location))
IInteractable IInteractable
(get-script [_ location] (get-script [_ cursor location]
(:script spec)) (if (= :main cursor)
(:script spec)
(get-in spec [:scripts cursor])))
ICursorOverridable ICursorOverridable
(cursor-override [this] (:cursor spec))) (cursor-override [this] (:cursor spec)))
)] )]
@@ -315,7 +320,9 @@
(if ((get-in @entities [:state :inventory]) :wool) (if ((get-in @entities [:state :inventory]) :wool)
(actions/talk entities :ego "The sheep has given me enough wool.") (actions/talk entities :ego "The sheep has given me enough wool.")
(do (actions/give entities :wool) (do (actions/give entities :wool)
(actions/talk entities :ego "I guess his wool is shedding."))))} (actions/talk entities :ego "I guess her wool is shedding."))))
:scripts {:wool (actions/get-script entities
(actions/talk entities :ego "She doesn't need it back."))}}
:right-dir {:box [300 131 320 224] :right-dir {:box [300 131 320 224]
:script (actions/get-script :script (actions/get-script
entities entities