Skip to content

Commit 9945548

Browse files
committed
Some minor code cleanup in simalq.un-iq.
1 parent 6d1447f commit 9945548

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

simalq/un_iq.hy

+39-39
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,11 @@
5959

6060
(defmacro adapt [old-cls #* body]
6161
"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))
6867

6968
(defn mac-roman-str [n]
7069
"A Mac Roman-encoded string of length `n` with Mac-style newlines."
@@ -169,10 +168,10 @@
169168
:if (not (.endswith member "/"))
170169
(.removeprefix member "infinity_quests_2/") (.read z member))))
171170

172-
(defn read-quest [name inp]
171+
(defn read-quest [name data]
173172
"Parse `bytes` into a `Quest`."
174173

175-
(setv data (.parse quest-fmt inp))
174+
(setv data (.parse quest-fmt data))
176175
(Quest
177176
:name name
178177
:title data.title
@@ -193,41 +192,42 @@
193192
(Pos m (- (get xy 0) 1) (- m.height (get xy 1)))
194193
None))
195194
: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))
198197

199198
:do (for [x (range l.width) y (range l.height)]
200199
; Fill in `m`.
201200
(setv iq-ix (get l.map (+ (* x l.height) (- l.height y 1))))
202201
; We have to reverse y-coordinates to get y = 0 as the
203202
; 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
231231
:n (+ i 1)
232232
:title l.title
233233
:player-start (mk-pos l.player-start)
@@ -244,10 +244,10 @@
244244
;; * Denazification
245245
;; --------------------------------------------------------------
246246

247-
(defn denazify [quest-name level-n level]
247+
(defn denazify [quest-name level]
248248
"Remove swastika-based designs in the given IQ level. The level is
249249
modified in place and then returned."
250-
(case [quest-name level-n]
250+
(case [quest-name level.n]
251251

252252
["New Nightmare" 1] (do
253253
; Replace the large central swastika.

0 commit comments

Comments
 (0)