src/clojurecraft/events.clj @ 57cb38f18a17

Better bootstrap.sh script. It now checks for dependencies and supports
downloading via either wget or curl. It also prints a message on how to
download the file manually in case neither utility is found. Update URL
to use new download location.
author Eliot <fadookie@gmail.com>
date Sat, 10 Sep 2011 01:35:47 -0700
parents 4c1055d72377
children (none)
(ns clojurecraft.events
  (:use [clojurecraft.actions :only [handle-action-group]]))

; Event Handlers -------------------------------------------------------------------
(defn- fire-handler [bot event-type & args]
  (let [action-groups (map #(apply (deref %) (into [bot] args))
                           (event-type @(:event-handlers bot)))]
    (dorun (map handle-action-group (cycle [bot]) action-groups))))

(defn fire-chat [bot message]
  (fire-handler bot :chat message))

(defn fire-dead [bot]
  (fire-handler bot :dead))


(defn add-handler [bot event-type handler]
  (dosync
    (let [current-handlers (event-type @(:event-handlers bot))
          updated-handlers (conj current-handlers handler)]
      (alter (:event-handlers bot) assoc event-type updated-handlers))))

(defn clear-handlers [bot event-type]
  (dosync (alter (:event-handlers bot) dissoc event-type)))