Skip to content
Draft
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
11 changes: 10 additions & 1 deletion src/cljs/orcpub/character_builder.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,17 @@
(js/console.warn "NO PREREQ_FN" (::t/name option) prereq)))
(::t/prereqs option))))

(defn ->keyword
"Converts a value to a keyword, handling both string and keyword inputs.
Strings like \":weapon\" are parsed correctly to :weapon.
Keywords like :weapon are returned as-is."
[v]
(if (keyword? v)
v
(reader/read-string v)))

(defn set-class-fn [i options-map]
(fn [e] (let [new-key (keyword (.. e -target -value))]
(fn [e] (let [new-key (->keyword (.. e -target -value))]
(dispatch [:set-class new-key i options-map]))))

(def set-class (memoize set-class-fn))
Expand Down
23 changes: 16 additions & 7 deletions src/cljs/orcpub/dnd/e5/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2959,6 +2959,15 @@

;;;; Item Builder

(defn ->keyword
"Converts a value to a keyword, handling both string and keyword inputs.
Strings like \":weapon\" are parsed correctly to :weapon.
Keywords like :weapon are returned as-is."
[v]
(if (keyword? v)
v
(reader/read-string v)))

(reg-event-db
::mi/set-item-description
item-interceptors
Expand All @@ -2970,26 +2979,26 @@
item-interceptors
(fn [item [_ item-type-str]]
(-> item
(assoc ::mi/type (keyword item-type-str))
(assoc ::mi/type (->keyword item-type-str))
(dissoc ::mi/subtypes))))

(reg-event-db
::mi/set-item-weapon-type
item-interceptors
(fn [item [_ item-type-str]]
(assoc item ::weapons/type (keyword item-type-str))))
(assoc item ::weapons/type (->keyword item-type-str))))

(reg-event-db
::mi/set-item-damage-type
item-interceptors
(fn [item [_ item-type-str]]
(assoc item ::weapons/damage-type (keyword item-type-str))))
(assoc item ::weapons/damage-type (->keyword item-type-str))))

(reg-event-db
::mi/set-item-melee-ranged
item-interceptors
(fn [item [_ item-type-str]]
(let [kw (keyword item-type-str)]
(let [kw (->keyword item-type-str)]
(assoc item
::weapons/melee? (= kw :melee)
::weapons/ranged? (= kw :ranged)))))
Expand Down Expand Up @@ -3089,7 +3098,7 @@
::mi/set-item-rarity
item-interceptors
(fn [item [_ item-type-str]]
(assoc item ::mi/rarity (keyword item-type-str))))
(assoc item ::mi/rarity (->keyword item-type-str))))

(reg-event-db
::mi/set-item-damage-bonus
Expand Down Expand Up @@ -3694,7 +3703,7 @@
:ability
ability-kw
:type]
(keyword type))))
(->keyword type))))

(defn set-mod-value [item mods-path mod-key value]
(if value
Expand Down Expand Up @@ -3726,7 +3735,7 @@
[::mi/internal-modifiers
speed-type-kw
:type]
(keyword mod-type))))
(->keyword mod-type))))

(reg-event-db
::mi/set-speed-mod-value
Expand Down