Fork me on GitHub
Noah Bogart15:10:25

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

Noah Bogart15:10:36

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)
   :flags {:has-abilities-when-stolen true}})

Noah Bogart15:10:27

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.

Noah Bogart16:10:45

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)
Would bring you to your :abilities vector.

Noah Bogart18:10:55

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

Noah Bogart19:10:26

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: