Skip to content

Commit

Permalink
Fixes custom weapons/items not displaying on PDFs
Browse files Browse the repository at this point in the history
Subscribed `all-weapons-map` so custom data is up to date

* Added documentation and comments for future maintainers
  • Loading branch information
codeGlaze committed Mar 12, 2024
1 parent 9f41415 commit 7f64b5a
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/cljc/orcpub/pdf_spec.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,22 @@
(str (dice/dice-string die-count die mod)
(if damage-type (str " " (name damage-type)))))

(defn attacks-and-spellcasting-fields [built-char]
(let [all-weapons (mi5e/equipped-items-details (char5e/all-weapons-inventory built-char) mi5e/all-weapons-map)
(defn attacks-and-spellcasting-fields
"For each weapon, we are creating a new map with the name, the attack bonus, and the damage.
The attack bonus is calculated using the function 'char5e/best-weapon-attack-modifier' which
calculates the attack bonus for a specific weapon.
The damage is calculated using the function 'damage-str' which takes the damage die, damage die count,
the damage modifier, and the damage type, and combines them into a string of the form 'dice-string damage-type'.
If the weapon is versatile, we also create a second map, where the name is suffixed with ' (two-handed)'
and the attack bonus and damage is calculated for the versatile form of the weapon.
We then remove any nil maps, and mapcat concatenates all of the maps into a single list.
The remove function filters out weapons of type 'ammunition'."
[built-char]
(let [all-weapons ; map of all weapons in inventory
(mi5e/equipped-items-details ; function to filter for equipped weapons
(char5e/all-weapons-inventory built-char)
@(subscribe [::mi5e/all-weapons-map]) ; re-frame subscription for all weapons
)
weapon-fields (mapcat
(fn [{:keys [name ::weapon5e/damage-die ::weapon5e/damage-die-count ::weapon5e/damage-type] :as weapon}]
(let [versatile (:versatile weapon)
Expand All @@ -452,8 +466,7 @@
all-weapons))
first-3-weapons (take 3 weapon-fields)
rest-weapons (drop 3 weapon-fields)
number-of-attacks (char5e/number-of-attacks built-char)
]
number-of-attacks (char5e/number-of-attacks built-char)]

(apply merge
{:attacks-and-spellcasting (str "Number of Attacks: " number-of-attacks "\n"
Expand Down

0 comments on commit 7f64b5a

Please sign in to comment.