This repository has been archived by the owner. It is now read-only.
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (28 sloc) 1.07 KB
;; From Mire, a multiplayer text adventure written in Clojure:
(ns mire.rooms)
declare rooms load-room
(defn load-rooms [dir]
"Given a dir, return a map with an entry corresponding to each file
in it. Files should be maps containing room data."
(reduce load-room {} (.listFiles ( dir))))
(defn load-room [rooms file]
(let [room (read-string (slurp (.getAbsolutePath file)))]
(conj rooms
{(keyword (.getName file))
{:name (keyword (.getName file))
:desc (:desc room)
:exits (ref (:exits room))
:items (ref (or (:items room) #{}))
:inhabitants (ref #{})}})))
(defn set-rooms
"Set mire.rooms/rooms to a map of rooms corresponding to each file
in dir. This function should be used only once at mire startup, so
having a def inside the function body should be OK. Defaults to
looking in data/rooms/."
(def rooms (load-rooms dir)))
([] (set-rooms "data/rooms/")))
(defn room-contains?
[room thing]
(@(:items room) (keyword thing)))