Created
February 13, 2015 21:24
-
-
Save tuturto/1cbd211efa8aa8f45298 to your computer and use it in GitHub Desktop.
fooling with macros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require hy.contrib.anaphoric) | |
(require pyherc.macros) | |
(import [pyherc.data [new-level Portal add-portal get-locations-by-tag | |
wall-tile]] | |
[pyherc.generators.level.partitioners.old-grid [RandomConnector]]) | |
(defmacro run-generators [level &rest generators] | |
(list (map (fn [x] `(ap-each ~x (it level))) generators))) | |
(defn new-level-generator [model partitioners room-generators decorators | |
portal-adders item-adders creature-adders | |
rng level-context] | |
"create a new level generator function" | |
(fn [portal] | |
(let [[level (new-level model)] | |
[partitioner (.choice rng partitioners)] | |
[connector (RandomConnector rng)] | |
[sections (.connect-sections connector (partitioner level))]] | |
(ap-each sections ((.choice rng room-generators) it)) | |
;; (ap-each portal-adders (it level)) | |
;; (ap-each creature-adders (it level)) | |
;; (ap-each item-adders (it level)) | |
;; (ap-each decorators (it level)) | |
(run-generators level | |
portal-adders | |
creature-adders | |
item-adders | |
decorators) | |
(when portal (let [[rooms (list (get-locations-by-tag level "room"))]] | |
(when rooms (add-portal level | |
(.choice rng rooms) | |
(Portal #t(portal.other-end-icon nil) nil) | |
portal)))) | |
level))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment