Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds new character sheet - Alternate version #450

Merged
merged 19 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added resources/fillable-char-sheetstyle-2-6-spells.pdf
Binary file not shown.
24 changes: 16 additions & 8 deletions src/clj/orcpub/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,23 @@

(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?]} 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?]} 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")
sheet4 (str "fillable-char-sheetstyle-" print-character-sheet-style? "-4-spells.pdf")
sheet3 (str "fillable-char-sheetstyle-" print-character-sheet-style? "-3-spells.pdf")
sheet2 (str "fillable-char-sheetstyle-" print-character-sheet-style? "-2-spells.pdf")
sheet1 (str "fillable-char-sheetstyle-" print-character-sheet-style? "-1-spells.pdf")
sheet0 (str "fillable-char-sheetstyle-" print-character-sheet-style? "-0-spells.pdf")
input (.openStream (io/resource (cond
(find fields :spellcasting-class-6) "fillable-char-sheet-6-spells.pdf"
(find fields :spellcasting-class-5) "fillable-char-sheet-5-spells.pdf"
(find fields :spellcasting-class-4) "fillable-char-sheet-4-spells.pdf"
(find fields :spellcasting-class-3) "fillable-char-sheet-3-spells.pdf"
(find fields :spellcasting-class-2) "fillable-char-sheet-2-spells.pdf"
(find fields :spellcasting-class-1) "fillable-char-sheet-1-spells.pdf"
:else "fillable-char-sheet-0-spells.pdf")))
(find fields :spellcasting-class-6) sheet6
(find fields :spellcasting-class-5) sheet5
(find fields :spellcasting-class-4) sheet4
(find fields :spellcasting-class-3) sheet3
(find fields :spellcasting-class-2) sheet2
(find fields :spellcasting-class-1) sheet1
:else sheet0)))
output (ByteArrayOutputStream.)
user-agent (get-in req [:headers "user-agent"])
chrome? (re-matches #".*Chrome.*" user-agent)]
Expand Down
3 changes: 2 additions & 1 deletion src/clj/orcpub/styles/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,8 @@

[:.form-button.disabled
{:opacity 0.5
:cursor :not-allowed}]
:cursor :not-allowed
:pointer-events "none"}]

[:.form-button.disabled:hover
{:box-shadow :none}]
Expand Down
9 changes: 6 additions & 3 deletions src/cljc/orcpub/pdf_spec.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@
{:keys [print-character-sheet?
print-spell-cards?
print-prepared-spells?
print-large-abilities?] :as options}]
print-large-abilities?
print-character-sheet-style?] :as options}]
(let [race (char5e/race built-char)
subrace (char5e/subrace built-char)
abilities (abilities-spec
Expand Down Expand Up @@ -545,7 +546,8 @@
:hd total-hit-dice
:initiative (common/bonus-str (es/entity-val built-char :initiative))
:speed speed
:hp-max (es/entity-val built-char :max-hit-points)
:hp-max (es/entity-val built-char :-max-hitpoints)
datdamnzotz marked this conversation as resolved.
Show resolved Hide resolved
:hp-current (char5e/current-hit-points built-char)
:passive (es/entity-val built-char :passive-perception)
:other-profs (other-profs-field built-char)
:personality-traits (s/join "\n\n" [(char5e/personality-trait-1 built-char) (char5e/personality-trait-2 built-char)])
Expand All @@ -569,7 +571,8 @@
:faction-image-url-failed (char5e/faction-image-url-failed built-char)
:faction-name (char5e/faction-name built-char)
:print-character-sheet? print-character-sheet?
:print-spell-cards? print-spell-cards?}
:print-spell-cards? print-spell-cards?
:print-character-sheet-style? print-character-sheet-style?}
(attacks-and-spellcasting-fields built-char)
(skill-fields built-char)
abilities
Expand Down
5 changes: 5 additions & 0 deletions src/cljs/orcpub/dnd/e5/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3777,6 +3777,11 @@
(fn [db _]
(update db ::char5e/print-large-abilities? not)))

(reg-event-db
::char5e/set-print-character-sheet-style?
(fn [db [_ id]]
(assoc-in db [::char5e/print-character-sheet-style?] id)))

(reg-event-db
::char5e/toggle-known-spells-print
(fn [db _]
Expand Down
5 changes: 5 additions & 0 deletions src/cljs/orcpub/dnd/e5/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,11 @@
(fn [db _]
(get db ::char5e/print-large-abilities?)))

(reg-sub
::char5e/print-character-sheet-style?
(fn [db [_ id]]
(get db ::char5e/print-character-sheet-style?)))

(reg-sub
::char5e/delete-confirmation-shown?
(fn [db [_ id]]
Expand Down
56 changes: 45 additions & 11 deletions src/cljs/orcpub/dnd/e5/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
(if @blurred? (validation-messages messages))])))

(defn export-pdf [built-char id & [options]]
(prn (str options))
(fn [_]
(let [field (.getElementById js/document "fields-input")]
(aset field "value" (str (pdf-spec/make-spec built-char id options)))
Expand Down Expand Up @@ -3401,28 +3402,63 @@
print-character-sheet?
print-spell-cards?
print-prepared-spells?
print-large-abilities?]
print-large-abilities?
print-character-sheet-style?]
#(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-large-abilities? print-large-abilities?
:print-character-sheet-style? print-character-sheet-style?})]
(export-fn)
(dispatch [::char/hide-options])))

(def export-pdf-handler (memoize export-pdf-fn))

(def make-arg-event-handler
(memoize
(fn [event-kw & [arg-fn]]
#(dispatch [event-kw (if arg-fn (arg-fn %) %)]))))

(defn print-button-style [print-button-enabled]
(if print-button-enabled
{}
{:opacity 0.5
:cursor :not-allowed
:pointer-events "none"}))


(defn print-options [id built-char]
(let [print-character-sheet? @(subscribe [::char/print-character-sheet?])
print-spell-cards? @(subscribe [::char/print-spell-cards?])
print-prepared-spells? @(subscribe [::char/print-prepared-spells?])
print-large-abilities? @(subscribe [::char/print-large-abilities?])
has-spells? (seq (char/spells-known built-char))]
print-character-sheet-style? @(subscribe [::char/print-character-sheet-style?])
has-spells? (seq (char/spells-known built-char))
print-button-enabled (if (or (= print-character-sheet-style? nil)
(= (str print-character-sheet-style?) "NaN"))
false true)]
[:div.flex.justify-cont-end
[:div.p-20
[:div.f-s-24.f-w-b.m-b-10 "Print Options"]
[:div.m-b-2
[:div.flex.m-b-10
[:div.m-t-10
[labeled-dropdown
"Select Character sheet"
#_(case print-character-sheet-style?
;nil "Select Character sheet"
1 "Original 5e Character sheet"
2 "Original 5e Character sheet - optional variant"
3 "Icewind Dale"
"Select Character sheet")
{:items [{:title "Select" :value " "}
{:title "Original 5e Character sheet" :value 1}
{:title "Original 5e Character sheet - optional variant" :value 2}
{:title "Icewind Dale" :value 3}]
:value print-character-sheet-style?
:on-change (make-arg-event-handler ::char/set-print-character-sheet-style? js/parseInt)}]]]
[:div.flex
[:div
{:on-click (make-event-handler ::char/toggle-large-abilities-print)}
Expand Down Expand Up @@ -3456,12 +3492,14 @@
{:on-click (make-event-handler ::char/hide-options)}
"Cancel"]
[:button.form-button.p-10.m-l-5
{:on-click (export-pdf-handler built-char
{:style (print-button-style print-button-enabled)
:on-click (export-pdf-handler built-char
id
print-character-sheet?
print-spell-cards?
print-prepared-spells?
print-large-abilities?)}
print-large-abilities?
print-character-sheet-style?)}
"Print"]]]))

(defn make-print-handler [id built-char]
Expand Down Expand Up @@ -3681,11 +3719,6 @@
armor/armor-types)
armor/armor)))])]]]))

(def make-arg-event-handler
(memoize
(fn [event-kw & [arg-fn]]
#(dispatch [event-kw (if arg-fn (arg-fn %) %)]))))

(defn value-to-item [v]
{:title v
:value v})
Expand Down Expand Up @@ -7407,7 +7440,8 @@
id
{:print-character-sheet? true
:print-spell-cards? true
:print-prepared-spells? false})}
:print-prepared-spells? false
:print-character-sheet-style? 1})}
"print"]
(if (= username owner)
[:button.form-button.m-l-5
Expand Down