Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/clj/orcpub/db/schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@
(map
bool-prop-no-history
[::weapon5e/special?
::weapon5e/loading?
::weapon5e/melee?
::weapon5e/ranged?
::weapon5e/heavy?
Expand Down
32 changes: 19 additions & 13 deletions src/cljc/orcpub/components.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,26 @@
{:value key}
name])

;; Form-2 component: resets <select> to placeholder after each on-change fires.
(defn selection-adder [values on-change]
[:select.builder-option.builder-option-dropdown
{:value ""
:on-change on-change}
[:option.builder-dropdown-item
{:value ""
:disabled true}
"<select to add>"]
(doall
(map
(fn [{:keys [key name]}]
^{:key key}
[selection-item key name false])
values))])
(let [selected-value (atom "")]
(fn [values on-change]
[:select.builder-option.builder-option-dropdown
{:value @selected-value
:on-change (fn [e]
(let [v (-> e .-target .-value)]
(on-change e)
(reset! selected-value "")))}
[:option.builder-dropdown-item
{:value ""
:disabled true}
"<select to add>"]
(doall
(map
(fn [{:keys [key name]}]
^{:key key}
[selection-item key name false])
values))])))

(defn selection [values on-change selected-value]
[:select
Expand Down
53 changes: 52 additions & 1 deletion src/cljc/orcpub/dnd/e5/magic_items.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
::weapons5e/range
::weapons5e/versatile
::weapons5e/special?
::weapons5e/loading?
::weapons5e/melee?
::weapons5e/ranged?
::weapons5e/heavy?
Expand Down Expand Up @@ -2950,7 +2951,9 @@ The boots regain 2 hours of flying capability for every 12 hours they aren鈥檛 i
weapons5e/ammunition))

(defn add-key [item]
(assoc item :key (common/name-to-kw (name-key item))))
(assoc item
:key (common/name-to-kw (name-key item))
:name (name-key item)))

(def weapon-subtypes
#{:axe :sword :staff})
Expand Down Expand Up @@ -3149,3 +3152,51 @@ The boots regain 2 hours of flying capability for every 12 hours they aren鈥檛 i

(defn equipped-armor-details [armor]
(equipped-items-details armor all-armor-map))

;; Strip base-weapon detail keys that only apply to custom (:other) weapons.
(defn remove-custom-weapon-fields [item]
(dissoc item
::weapons5e/finesse?
::weapons5e/versatile?
::weapons5e/reach?
::weapons5e/two-handed?
::weapons5e/thrown?
::weapons5e/heavy?
::weapons5e/light?
::weapons5e/ammunition?
::weapons5e/special?
::weapons5e/loading?
::weapons5e/damage-die-count
::weapons5e/damage-die
::weapons5e/versatile
::weapons5e/melee?
::weapons5e/ranged?
::weapons5e/type
::weapons5e/range
::weapons5e/damage-type))

;; Apply a subtype toggle to an item. Initialises sane defaults when
;; switching to :other (Custom) so the view doesn't need to dispatch
;; defaults during render.
(defn apply-subtype-toggle [item type]
(case type
:other (-> item
remove-custom-weapon-fields
(assoc ::subtypes #{:other})
(assoc ::weapons5e/damage-die-count 1)
(assoc ::weapons5e/damage-die 4)
(assoc ::weapons5e/type :simple)
(assoc ::weapons5e/damage-type :bludgeoning)
(assoc ::weapons5e/melee? true)
(assoc ::weapons5e/ranged? false))
:all (-> item
remove-custom-weapon-fields
(assoc ::subtypes #{:all}))
(-> item
remove-custom-weapon-fields
(update ::subtypes
(fn [s]
(let [clean (disj (or s #{}) :other :all)]
(if (get clean type)
(disj clean type)
(conj clean type))))))))
6 changes: 6 additions & 0 deletions src/cljc/orcpub/dnd/e5/weapons.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
:key :crossbow-light
::two-handed? true
::ammunition? true
::loading? true
::link "https://en.wikipedia.org/wiki/Crossbow"}
{::ranged? true,
:key :dart,
Expand Down Expand Up @@ -332,6 +333,7 @@
::ranged? true,
::range {::min 25, ::max 100},
::ammunition? true
::loading? true
:key :blowgun}
{:name "Crossbow, hand",
::damage-type :piercing,
Expand All @@ -341,6 +343,7 @@
::ranged? true,
::range {::min 30, ::max 120},
::ammunition? true
::loading? true
::light? true
:key :crossbow-hand}
{:name "Crossbow, heavy",
Expand All @@ -353,6 +356,7 @@
::range {::min 100, ::max 400},
:key :crossbow-heavy
::ammunition? true
::loading? true
::two-handed? true}
{:name "Longbow",
::damage-type :piercing,
Expand Down Expand Up @@ -383,6 +387,7 @@
::heavy? true,
::range {::min 30, ::max 90},
:key :firearm-hand
::loading? true
::two-handed? false}
{:name "Firearm, Burst (DMV)",
::damage-type :piercing,
Expand All @@ -403,6 +408,7 @@
::heavy? true,
::range {::min 60, ::max 120},
:key :firearm-long
::loading? true
::two-handed? true}])

(def ammunition
Expand Down
9 changes: 5 additions & 4 deletions src/cljc/orcpub/pdf_spec.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@
(def coin-keys [:cp :sp :ep :gp :pp])

(defn equipment-fields [built-char]
(let [equipment (es/entity-val built-char :equipment)
(let [equipment-map (merge mi5e/all-equipment-map @(subscribe [::mi5e/all-magic-items-map]))
equipment (es/entity-val built-char :equipment)
armor (es/entity-val built-char :armor)
magic-armor (es/entity-val built-char :magic-armor)
magic-items (es/entity-val built-char :magic-items)
Expand Down Expand Up @@ -188,8 +189,8 @@
(map
(fn [[kw {count ::char-equip5e/quantity}]]
(if (> count 1)
(str (disp5e/equipment-name mi5e/all-equipment-map kw) " x" count )
(str (disp5e/equipment-name mi5e/all-equipment-map kw))
(str (disp5e/equipment-name equipment-map kw) " x" count )
(str (disp5e/equipment-name equipment-map kw))
)
)
(filter
Expand All @@ -199,7 +200,7 @@
"\n"
(map
(fn [[kw {count ::char-equip5e/quantity}]]
(str (disp5e/equipment-name mi5e/all-equipment-map kw) " (" count ")"))
(str (disp5e/equipment-name equipment-map kw) " (" count ")"))
(merge
(apply dissoc treasure coin-keys)
unequipped-items)))})))
Expand Down
51 changes: 21 additions & 30 deletions src/cljs/orcpub/dnd/e5/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,14 @@
:item-save-success
(fn [{:keys [db]} [_ response]]
(let [strict-item (:body response)
item (mi/to-internal-item strict-item)]
{:dispatch-n [[:show-message "Your item has been saved."]
item (mi/to-internal-item strict-item)
item-id (:db/id strict-item)
existing-items (::mi/custom-items db)
updated-items (if (some #(= item-id (:db/id %)) existing-items)
(mapv #(if (= item-id (:db/id %)) strict-item %) existing-items)
(conj (vec existing-items) strict-item))]
{:db (assoc db ::mi/custom-items updated-items)
:dispatch-n [[:show-message "Your item has been saved."]
[::mi/set-item item]]})))

(reg-event-fx
Expand Down Expand Up @@ -3072,6 +3078,18 @@
(fn [item _]
(update item ::weapons/ammunition? not)))

(reg-event-db
::mi/toggle-item-special?
item-interceptors
(fn [item _]
(update item ::weapons/special? not)))

(reg-event-db
::mi/toggle-item-loading?
item-interceptors
(fn [item _]
(update item ::weapons/loading? not)))

(reg-event-db
::mi/toggle-item-versatile?
item-interceptors
Expand Down Expand Up @@ -3747,38 +3765,11 @@
ability-kw
value)))

(defn remove-custom-weapon-fields [item]
(dissoc item
::weapons/finesse?
::weapons/versatile?
::weapons/reach?
::weapons/two-handed?
::weapons/thrown?
::weapons/heavy?
::weapons/light?
::weapons/ammunition?
::weapons/damage-die-count
::weapons/damage-die
::weapons/versatile
::weapons/melee?
::weapons/ranged?
::weapons/type
::weapons/range
::weapons/damage-type))

(reg-event-db
::mi/toggle-subtype
item-interceptors
(fn [item [_ type]]
(remove-custom-weapon-fields
(case type
:other (assoc item ::mi/subtypes #{:other})
:all (assoc item ::mi/subtypes #{:all})
(update item
::mi/subtypes
#(as-> % $
(disj $ :other :all)
(toggle-set type $)))))))
(mi/apply-subtype-toggle item type)))

(reg-event-fx
::char5e/open-character
Expand Down
12 changes: 12 additions & 0 deletions src/cljs/orcpub/dnd/e5/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,18 @@
(fn [item _]
(get item ::weapon5e/ammunition?)))

(reg-sub
::mi5e/item-special?
:<- [::mi5e/builder-item]
(fn [item _]
(get item ::weapon5e/special?)))

(reg-sub
::mi5e/item-loading?
:<- [::mi5e/builder-item]
(fn [item _]
(get item ::weapon5e/loading?)))

(reg-sub
::mi5e/item-versatile?
:<- [::mi5e/builder-item]
Expand Down
15 changes: 7 additions & 8 deletions src/cljs/orcpub/dnd/e5/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3844,13 +3844,6 @@
)
)))])]]
(when other?
;;;batch-set multiple default values
(doseq [evt [[::mi/set-item-damage-die-count 1]
[::mi/set-item-damage-die 4]
[::mi/set-item-weapon-type :simple]
[::mi/set-item-melee-ranged :melee]]
]
(dispatch evt))
[:div.main-text-color.m-b-10.m-t-10
[:span.f-s-18.f-w-b "Base Weapon Details"]
[:div.flex.flex-wrap.m-t-10
Expand All @@ -3877,7 +3870,13 @@
[labeled-checkbox "Light?" @(subscribe [::mi/item-light?])]]
[:div.m-l-10
{:on-click (make-event-handler ::mi/toggle-item-ammunition?)}
[labeled-checkbox "Ammunition?" @(subscribe [::mi/item-ammunition?])]]]
[labeled-checkbox "Ammunition?" @(subscribe [::mi/item-ammunition?])]]
[:div.m-l-10
{:on-click (make-event-handler ::mi/toggle-item-special?)}
[labeled-checkbox "Special?" @(subscribe [::mi/item-special?])]]
[:div.m-l-10
{:on-click (make-event-handler ::mi/toggle-item-loading?)}
[labeled-checkbox "Loading?" @(subscribe [::mi/item-loading?])]]]
[:div.flex.flex-wrap
[:div.m-t-10
[labeled-dropdown
Expand Down
Loading
Loading