Skip to content

Commit

Permalink
Merge pull request #519 from Jessomadic/Original-Character-Sheet-Text…
Browse files Browse the repository at this point in the history
…-Fix-#517

PDF Ghosting (duplicate fields) Issue #517 and Add option to Print DC/Mod #521
  • Loading branch information
datdamnzotz committed Mar 28, 2021
2 parents 85278db + 90e3dbe commit 632f9a1
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 20 deletions.
Binary file modified resources/fillable-char-sheetstyle-1-2-spells.pdf
Binary file not shown.
File renamed without changes
11 changes: 6 additions & 5 deletions src/clj/orcpub/pdf.clj
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@
(+ margin-x total-width)
y)))
(.setStrokingColor cs 0 0 0)))

(defn spell-school-level [{:keys [level school]} class-nm]
(if (zero? level)
(str class-nm " - "(s/capitalize school) " cantrip")
(str class-nm " Cantrip " (s/capitalize school))
(str class-nm " Level " level " " (str (s/capitalize school)))))

(defn draw-spell-field [cs document title value x y]
Expand Down Expand Up @@ -282,7 +283,7 @@
remaining-height (- 11.0 total-height)
margin-y (/ remaining-height 2)
fonts (load-fonts document)]
(with-open [img-stream (io/input-stream (io/resource "public/image/orcpub-card-logo.png"))
(with-open [img-stream (io/input-stream (io/resource "public/image/card-logo.png"))
over-img-stream (io/input-stream (io/resource "public/image/clockwise-rotation.png"))]
(let [img (LosslessFactory/createFromImage document (ImageIO/read img-stream))
over-img (LosslessFactory/createFromImage document (ImageIO/read over-img-stream))]
Expand Down Expand Up @@ -326,7 +327,7 @@
(- box-width 0.3)
(- box-height 0.2))))))))))

(defn print-spells [cs document box-width box-height spells page-number]
(defn print-spells [cs document box-width box-height spells page-number print-spell-card-dc-mod?]
(let [num-boxes-x (int (/ 8.5 box-width))
num-boxes-y (int (/ 11.0 box-height))
total-width (* num-boxes-x box-width)
Expand All @@ -336,7 +337,7 @@
remaining-height (- 11.0 total-height)
margin-y (/ remaining-height 2)
fonts (load-fonts document)]
(with-open [card-logo-img-stream (io/input-stream (io/resource "public/image/orcpub-card-logo.png"))
(with-open [card-logo-img-stream (io/input-stream (io/resource "public/image/card-logo.png"))
over-img-stream (io/input-stream (io/resource "public/image/clockwise-rotation.png"))]
(let [card-logo-img (LosslessFactory/createFromImage document (ImageIO/read card-logo-img-stream))
over-img (LosslessFactory/createFromImage document (ImageIO/read over-img-stream))]
Expand Down Expand Up @@ -417,7 +418,7 @@
0.2)
(draw-text-to-box cs
(if (not= class-nm "Homebrew")
(str (spell-school-level spell class-nm) " " dc-str (str " Spell Mod " (common/bonus-str attack-bonus)))
(str (spell-school-level spell class-nm) (when print-spell-card-dc-mod? (str " " dc-str (str " Spell Mod " (common/bonus-str attack-bonus)))))
(spell-school-level spell class-nm))
(:italic fonts)
8
Expand Down
11 changes: 6 additions & 5 deletions src/clj/orcpub/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@
:weapon-name-2 8
:weapon-name-3 8}))

(defn add-spell-cards! [doc spells-known spell-save-dcs spell-attack-mods custom-spells] (try
(defn add-spell-cards! [doc spells-known spell-save-dcs spell-attack-mods custom-spells print-spell-card-dc-mod?] (try
(let [custom-spells-map (common/map-by-key custom-spells)
spells-map (merge spells/spell-map custom-spells-map)
flat-spells (-> spells-known vals flatten)
Expand All @@ -421,7 +421,7 @@
class)
key])
flat-spells)
parts (vec (partition-all 9 sorted-spells))]
parts (vec (partition-all 9 flat-spells))]
(doseq [i (range (count parts))
:let [part (parts i)]]
(let [page (PDPage.)]
Expand All @@ -444,7 +444,8 @@
2.5
3.5
spells
i))
i
print-spell-card-dc-mod?))
back-page (PDPage.)]
(with-open [back-page-cs (PDPageContentStream. doc back-page)]
(.addPage doc back-page)
Expand All @@ -453,7 +454,7 @@

(defn character-pdf-2 [req]
(let [fields (-> req :form-params :body edn/read-string)
{:keys [image-url image-url-failed faction-image-url faction-image-url-failed spells-known custom-spells spell-save-dcs spell-attack-mods print-spell-cards? print-character-sheet-style?]} fields
{:keys [image-url image-url-failed faction-image-url faction-image-url-failed spells-known custom-spells spell-save-dcs spell-attack-mods print-spell-cards? print-character-sheet-style? print-spell-card-dc-mod?]} fields

sheet6 (str "fillable-char-sheetstyle-" print-character-sheet-style? "-6-spells.pdf")
sheet5 (str "fillable-char-sheetstyle-" print-character-sheet-style? "-5-spells.pdf")
Expand All @@ -476,7 +477,7 @@
(with-open [doc (PDDocument/load input)]
(pdf/write-fields! doc fields (not chrome?) font-sizes)
(if (and print-spell-cards? (seq spells-known))
(add-spell-cards! doc spells-known spell-save-dcs spell-attack-mods custom-spells))
(add-spell-cards! doc spells-known spell-save-dcs spell-attack-mods custom-spells print-spell-card-dc-mod?))
(if (and image-url
(re-matches #"^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]" image-url)
(not image-url-failed))
Expand Down
19 changes: 13 additions & 6 deletions src/cljc/orcpub/pdf_spec.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
print-prepared-spells?
prepares-spells
prepared-spells-by-class]

(let [flat-spells (char5e/flat-spells spells-known)
spells-map @(subscribe [::spells/spells-map])
plugin-spells-map @(subscribe [::spells/plugin-spells-map])
Expand Down Expand Up @@ -379,14 +380,17 @@
spell-pages)))))

(defn spellcasting-fields [built-char print-prepared-spells?]
(let [spells-known (char5e/spells-known built-char)
spell-attack-modifier-fn (char5e/spell-attack-modifier-fn built-char)
(let [spell-attack-modifier-fn (char5e/spell-attack-modifier-fn built-char)
spell-save-dc-fn (char5e/spell-save-dc-fn built-char)
spell-slots (char5e/spell-slots built-char)
prepares-spells (char5e/prepares-spells built-char)
prepared-spells-by-class (char5e/prepared-spells-by-class built-char)]
prepared-spells-by-class (char5e/prepared-spells-by-class built-char)
sorted-spells-known (into {}
(map (fn [[id datum]]
[id (into (sorted-map) datum)]))
(char5e/spells-known built-char))]

(spell-page-fields spells-known
(spell-page-fields sorted-spells-known
spell-slots
spell-save-dc-fn
spell-attack-modifier-fn
Expand Down Expand Up @@ -498,7 +502,8 @@
print-spell-cards?
print-prepared-spells?
print-large-abilities?
print-character-sheet-style?] :as options}]
print-character-sheet-style?
print-spell-card-dc-mod?] :as options}]
(let [race (char5e/race built-char)
subrace (char5e/subrace built-char)
abilities (abilities-spec
Expand Down Expand Up @@ -572,7 +577,9 @@
:faction-name (char5e/faction-name built-char)
:print-character-sheet? print-character-sheet?
:print-spell-cards? print-spell-cards?
:print-character-sheet-style? print-character-sheet-style?}
:print-character-sheet-style? print-character-sheet-style?
:print-spell-card-dc-mod? print-spell-card-dc-mod?
}
(attacks-and-spellcasting-fields built-char)
(skill-fields built-char)
abilities
Expand Down
10 changes: 10 additions & 0 deletions src/cljs/orcpub/dnd/e5/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3791,6 +3791,16 @@
(fn [db _]
(update db ::char5e/exclude-spell-cards-print? not)))

(reg-event-db
::char5e/toggle-spell-cards-by-level
(fn [db _]
(update db ::char5e/exclude-spell-cards-by-level? not)))

(reg-event-db
::char5e/toggle-spell-cards-by-dc-mod
(fn [db _]
(update db ::char5e/exclude-spell-cards-by-dc-mod? not)))

(reg-event-db
::char5e/toggle-large-abilities-print
(fn [db _]
Expand Down
6 changes: 6 additions & 0 deletions src/cljs/orcpub/dnd/e5/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,12 @@
(fn [db _]
(-> db ::char5e/exclude-spell-cards-print? not)))

(reg-sub
::char5e/print-spell-card-dc-mod?
(fn [db _]
(-> db ::char5e/exclude-spell-cards-by-dc-mod? not)))


(reg-sub
::char5e/print-character-sheet?
(fn [db _]
Expand Down
21 changes: 17 additions & 4 deletions src/cljs/orcpub/dnd/e5/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3476,14 +3476,16 @@
print-spell-cards?
print-prepared-spells?
print-large-abilities?
print-character-sheet-style?]
print-character-sheet-style?
print-spell-card-dc-mod?]
#(let [export-fn (export-pdf built-char
id
{:print-character-sheet? print-character-sheet?
:print-spell-cards? print-spell-cards?
:print-prepared-spells? print-prepared-spells?
:print-large-abilities? print-large-abilities?
:print-character-sheet-style? print-character-sheet-style?})]
:print-character-sheet-style? print-character-sheet-style?
:print-spell-card-dc-mod? print-spell-card-dc-mod?})]
(export-fn)
(dispatch [::char/hide-options])))

Expand All @@ -3508,6 +3510,7 @@
print-prepared-spells? @(subscribe [::char/print-prepared-spells?])
print-large-abilities? @(subscribe [::char/print-large-abilities?])
print-character-sheet-style? @(subscribe [::char/print-character-sheet-style?])
print-spell-card-dc-mod? @(subscribe [::char/print-spell-card-dc-mod?])
has-spells? (seq (char/spells-known built-char))
print-button-enabled (if (or (= print-character-sheet-style? nil)
(= (str print-character-sheet-style?) "NaN"))
Expand Down Expand Up @@ -3539,6 +3542,14 @@
[labeled-checkbox
"Print Spell Cards"
print-spell-cards?]]]])
(if print-spell-cards?
[:div.m-b-2
[:div.flex
[:div
{:on-click (make-event-handler ::char/toggle-spell-cards-by-dc-mod)}
[labeled-checkbox
"Print Spell DC and MOD"
print-spell-card-dc-mod?]]]])
(if has-spells?
[:div.m-b-10
[:div.m-b-10
Expand All @@ -3565,7 +3576,8 @@
print-spell-cards?
print-prepared-spells?
print-large-abilities?
print-character-sheet-style?)}
print-character-sheet-style?
print-spell-card-dc-mod?)}
"Print"]]]))

(defn make-print-handler [id built-char]
Expand Down Expand Up @@ -7522,7 +7534,8 @@
{:print-character-sheet? true
:print-spell-cards? true
:print-prepared-spells? false
:print-character-sheet-style? 1})}
:print-character-sheet-style? 1
:print-spell-card-dc-mod? true})}
"print"]
(if (= username owner)
[:button.form-button.m-l-5
Expand Down

0 comments on commit 632f9a1

Please sign in to comment.