|
59 | 59 |
|
60 | 60 | (defmacro adapt [old-cls #* body]
|
61 | 61 | "Syntactic sugar for `construct.Adapter`."
|
62 |
| - (setv C (hy.gensym)) |
63 |
| - `(do |
64 |
| - (defclass ~C [construct.Adapter] |
65 |
| - (defn _decode [self obj context path] |
66 |
| - ~@body)) |
67 |
| - (~C ~old-cls))) |
| 62 | + `( |
| 63 | + (type "adapter" #(construct.Adapter) (dict |
| 64 | + :_decode (fn [self obj context path] |
| 65 | + ~@body))) |
| 66 | + ~old-cls)) |
68 | 67 |
|
69 | 68 | (defn mac-roman-str [n]
|
70 | 69 | "A Mac Roman-encoded string of length `n` with Mac-style newlines."
|
|
169 | 168 | :if (not (.endswith member "/"))
|
170 | 169 | (.removeprefix member "infinity_quests_2/") (.read z member))))
|
171 | 170 |
|
172 |
| -(defn read-quest [name inp] |
| 171 | +(defn read-quest [name data] |
173 | 172 | "Parse `bytes` into a `Quest`."
|
174 | 173 |
|
175 |
| - (setv data (.parse quest-fmt inp)) |
| 174 | + (setv data (.parse quest-fmt data)) |
176 | 175 | (Quest
|
177 | 176 | :name name
|
178 | 177 | :title data.title
|
|
193 | 192 | (Pos m (- (get xy 0) 1) (- m.height (get xy 1)))
|
194 | 193 | None))
|
195 | 194 | :setv tile-extras (dfor
|
196 |
| - c l.tile-extras |
197 |
| - (mk-pos c.pos) (tuple c.data)) |
| 195 | + pair l.tile-extras |
| 196 | + (mk-pos pair.pos) (tuple pair.data)) |
198 | 197 |
|
199 | 198 | :do (for [x (range l.width) y (range l.height)]
|
200 | 199 | ; Fill in `m`.
|
201 | 200 | (setv iq-ix (get l.map (+ (* x l.height) (- l.height y 1))))
|
202 | 201 | ; We have to reverse y-coordinates to get y = 0 as the
|
203 | 202 | ; bottom row.
|
204 |
| - (unless (= iq-ix FLOOR) |
205 |
| - (setv p (Pos m x y)) |
206 |
| - (setv result (get Tile.types-by-iq-ix iq-ix)) |
207 |
| - (defn te [cls] |
208 |
| - (if (in p tile-extras) |
209 |
| - (.read-tile-extras cls mk-pos |
210 |
| - #* (get tile-extras p)) |
211 |
| - {})) |
212 |
| - (.extend (get m.data x y) (cond |
213 |
| - (is (type result) type) |
214 |
| - ; The usual case: the `iq-ix` specifies the type, and no |
215 |
| - ; more. |
216 |
| - [(result :pos p #** (te result))] |
217 |
| - (is (type result) dict) |
218 |
| - ; This `iq-ix` specifies the type and a certain value of |
219 |
| - ; a field. |
220 |
| - [((get result "cls") :pos p |
221 |
| - #** {(get result "field") (get result "value")} |
222 |
| - #** (te (get result "cls")))] |
223 |
| - (callable (type result)) |
224 |
| - ; A special case where a callback makes the tiles |
225 |
| - ; itself. It can return any number of them. |
226 |
| - (result p #* (get tile-extras p)) |
227 |
| - T |
228 |
| - (raise (ValueError (+ "Bad `Tile.types-by-iq-ix` entry: " (repr result)))))))) |
229 |
| - |
230 |
| - (denazify name (+ i 1) (Level |
| 203 | + (when (= iq-ix FLOOR) |
| 204 | + (continue)) |
| 205 | + (setv p (Pos m x y)) |
| 206 | + (setv result (get Tile.types-by-iq-ix iq-ix)) |
| 207 | + (defn te [cls] |
| 208 | + (if (in p tile-extras) |
| 209 | + (.read-tile-extras cls mk-pos |
| 210 | + #* (get tile-extras p)) |
| 211 | + {})) |
| 212 | + (.extend (get m.data x y) (cond |
| 213 | + (is (type result) type) |
| 214 | + ; The usual case: the `iq-ix` specifies the type, and no |
| 215 | + ; more. |
| 216 | + [(result :pos p #** (te result))] |
| 217 | + (is (type result) dict) |
| 218 | + ; This `iq-ix` specifies the type and a certain value of |
| 219 | + ; a field. |
| 220 | + [((get result "cls") :pos p |
| 221 | + #** {(get result "field") (get result "value")} |
| 222 | + #** (te (get result "cls")))] |
| 223 | + (callable (type result)) |
| 224 | + ; A special case where a callback makes the tiles |
| 225 | + ; itself. It can return any number of them. |
| 226 | + (result p #* (get tile-extras p)) |
| 227 | + T |
| 228 | + (raise (ValueError (+ "Bad `Tile.types-by-iq-ix` entry: " (repr result))))))) |
| 229 | + |
| 230 | + (denazify name (Level |
231 | 231 | :n (+ i 1)
|
232 | 232 | :title l.title
|
233 | 233 | :player-start (mk-pos l.player-start)
|
|
244 | 244 | ;; * Denazification
|
245 | 245 | ;; --------------------------------------------------------------
|
246 | 246 |
|
247 |
| -(defn denazify [quest-name level-n level] |
| 247 | +(defn denazify [quest-name level] |
248 | 248 | "Remove swastika-based designs in the given IQ level. The level is
|
249 | 249 | modified in place and then returned."
|
250 |
| - (case [quest-name level-n] |
| 250 | + (case [quest-name level.n] |
251 | 251 |
|
252 | 252 | ["New Nightmare" 1] (do
|
253 | 253 | ; Replace the large central swastika.
|
|
0 commit comments