Permalink
Browse files

Merge branch '11-idioms' into 12-packaging

  • Loading branch information...
technomancy committed Apr 17, 2009
2 parents 00053a4 + a278d27 commit 858f5fb16405c7e8838a915c2154a80382a052af
Showing with 28 additions and 20 deletions.
  1. +13 −4 src/mire/rooms.clj
  2. +2 −2 src/mire/server.clj
  3. +1 −2 src/mire/test/commands.clj
  4. +10 −10 src/mire/test/rooms.clj
  5. +2 −2 src/mire/util.clj
View
@@ -1,6 +1,6 @@
(ns mire.rooms)
-(def rooms)
+(declare rooms)
(defn load-room [rooms file]
(let [room (read-string (slurp (.getAbsolutePath file)))]
@@ -12,10 +12,19 @@
:items (ref (or (:items room) #{}))
:inhabitants (ref #{})}})))
-(defn load-rooms
+(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 (java.io.File. dir))))
+
+(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/."
([dir]
- (def rooms (reduce load-room {}
- (.listFiles (java.io.File. dir))))))
+ (def rooms (load-rooms dir)))
+ ([] (set-rooms "data/rooms/")))
(defn room-contains?
[room thing]
View
@@ -38,8 +38,8 @@
(defn -main
([rooms-dir port]
- (load-rooms rooms-dir)
+ (set-rooms rooms-dir)
(defonce server (create-server (Integer. port) mire-handle-client))
(println "Launching Mire server on port" port))
([rooms-dir] (-main rooms-dir 3333))
- ([] (-main "data/rooms")))
+ ([] (-main "data/rooms")))
@@ -2,11 +2,10 @@
(:use [mire commands player rooms] :reload-all)
(:use [clojure.contrib test-is seq-utils duck-streams]))
-(def rooms-dir "data/rooms/")
+(set-rooms "data/rooms/")
(defmacro def-command-test [name & body]
`(deftest ~name
- (load-rooms rooms-dir)
(binding [*current-room* (ref (:start rooms))
*inventory* (ref #{})
*player-name* "Tester"]
View
@@ -2,18 +2,18 @@
(:use [mire player rooms] :reload-all)
(:use [clojure.contrib test-is seq-utils]))
-(deftest test-load-rooms
- (load-rooms "data/rooms/")
- (doseq [name [:start :closet :hallway :promenade]]
- (is (contains? rooms name)))
- (is (re-find #"promenade" (:desc (:promenade rooms))))
- (is (= :hallway (:west @(:exits (:promenade rooms)))))
- (is (includes? @(:items (:promenade rooms)) :bunny))
- (is (empty? @(:inhabitants (:promenade rooms)))))
+(deftest test-set-rooms
+ (let [rooms (load-rooms "data/rooms/")]
+ (doseq [name [:start :closet :hallway :promenade]]
+ (is (contains? rooms name)))
+ (is (re-find #"promenade" (:desc (:promenade rooms))))
+ (is (= :hallway (:west @(:exits (:promenade rooms)))))
+ (is (includes? @(:items (:promenade rooms)) :bunny))
+ (is (empty? @(:inhabitants (:promenade rooms))))))
(deftest test-room-contains?
- (load-rooms "data/rooms/")
- (let [closet (:closet rooms)]
+ (let [rooms (load-rooms "data/rooms/")
+ closet (:closet rooms)]
(is (not (empty? (filter #(= % :keys) @(:items closet)))))
(is (room-contains? closet "keys"))
(is (not (room-contains? closet "monkey")))))
View
@@ -3,5 +3,5 @@
(defn move-between-refs
"Move one instance of obj between from and to. Must be called in a transaction."
[obj from to]
- (commute from disj obj)
- (commute to conj obj))
+ (alter from disj obj)
+ (alter to conj obj))

0 comments on commit 858f5fb

Please sign in to comment.