Skip to content

Commit 7612285

Browse files
committed
Factored out a helper class TargetedScenery.
1 parent 018c44b commit 7612285

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

simalq/tile/scenery.hy

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@
142142
passwallable T
143143
wand-destructible T))
144144
145+
(defclass TargetedScenery [Scenery]
146+
147+
(setv
148+
field-defaults (dict
149+
:target None)
150+
fields #("target"))
151+
152+
(defmeth [classmethod] read-tile-extras [mk-pos v1 v2]
153+
(dict :target (mk-pos #(v1 v2))))
154+
155+
(defmeth suffix-dict []
156+
(dict :target @target)))
157+
145158
;; --------------------------------------------------------------
146159
;; * Basic scenery
147160
;; --------------------------------------------------------------
@@ -285,19 +298,11 @@
285298

286299
:flavor "This massive slab of steel will certainly not be opened with a sad little bargain-basement skeleton key. Your best bet is looking for a remote switch of some kind.")
287300

288-
(deftile "+|" "a metal-door control" Scenery
301+
(deftile "+|" "a metal-door control" TargetedScenery
289302
:iq-ix 168
290-
:field-defaults (dict
291-
:target None)
292-
:fields #("target")
293303

294304
:blocks-move T
295305

296-
:read-tile-extras (classmethod (fn [cls mk-pos v1 v2]
297-
(dict :target (mk-pos #(v1 v2)))))
298-
:suffix-dict (meth []
299-
(dict :target @target))
300-
301306
:hook-player-bump (meth [origin]
302307
(doc f"If there's a metal door at {@target}, it's destroyed. Otherwise, everything on the square is destroyed and a metal door is created there.")
303308
(for [t (list (at @target)) :if (= t.stem "metal door")]
@@ -640,19 +645,10 @@
640645
;; ** Gates
641646
;; --------------------------------------------------------------
642647

643-
(defclass Gate [Scenery]
644-
(setv field-defaults (dict
645-
:target None))
646-
(setv fields #("target"))
647-
648+
(defclass Gate [TargetedScenery]
648649
(setv blocks-monster T)
649650
(setv one-shot? F)
650651

651-
(defn [classmethod] read-tile-extras [cls mk-pos v1 v2]
652-
(dict :target (mk-pos #(v1 v2))))
653-
654-
(defmeth suffix-dict []
655-
(dict :dest @target))
656652
(defmeth hook-player-walked-into []
657653
(doc (+
658654
f"Teleports you to {@target}. Anything already there is unaffected."

tests/test_scenery.hy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@
443443
(defn t [] (Pos G.map 5 6))
444444

445445
(mk-tile [1 0] [stem :target (t)])
446-
(assert-full-name [1 0] f"a {stem} (dest <Pos 5,6>)")
446+
(assert-full-name [1 0] f"a {stem} (target <Pos 5,6>)")
447447
(set-square (t) "orc" "pile of gold" "exit")
448448
(assert (and (= G.turn-n 0) (= G.player.pos (Pos G.map 0 0))))
449449
; Walking into the gate warps us to the target square, but

0 commit comments

Comments
 (0)