hey friends
i'm working on a card game, and i have files with the card effect definitions. i want to fundamentally change how the effect definitions are structured by code-walking and making the changes and then saving the file at the end, but i'm struggling to figure out how to traverse the nodes rewrite-clj gives back
for example, here's a simple card definition:
(defcard "15 Minutes"
{:abilities [{:cost [:click 1]
:msg "shuffle 15 Minutes into R&D"
:label "Shuffle 15 Minutes into R&D"
:effect (effect (move :corp card :deck nil)
(shuffle! :corp :deck)
(update-all-agenda-points))}]
:flags {:has-abilities-when-stolen true}})
i parse the file with (def agendas (z/of-file "src/clj/game/cards/agendas.clj"))
, and then call (z/find-next-value agendas z/next 'defcard)
to move to the defcard
node.
is there a better way of saying (-> (z/find-next-value agendas z/next 'defcard) z/next z/next (z/find-value z/next :abilities) z/right)
to process the map inside the :abilities
vector?
Hi @nbtheduke. I guess you could skip the first find, that is if you don’t need it for some other reason.
(-> agendas
(z/find-next-value z/next :abilities)
z/right)
Would bring you to your :abilities
vector.thank you!
what if i wanted to look at every map literal in the whole file?
@nbtheduke You could iterate through every form in the file using z/next
and check every time if it's a map or not
interesting, okay
@nbtheduke This is also what I do in carve where I remove nodes by looking at the location given a list of locations: https://github.com/borkdude/carve/blob/8e9a29b9b985a89ce0aa0b7f4117e072a07bed44/src/carve/impl.clj#L88