Skip to content

Commit

Permalink
Support applying HP changes from the touchable UI
Browse files Browse the repository at this point in the history
  • Loading branch information
dhleong committed Dec 13, 2020
1 parent 5547b8f commit d4b6cd8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
19 changes: 16 additions & 3 deletions src/cljs/wish/sheets/dnd5e/overlays/hp.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
[wish.views.widgets.spinning-modifier
:refer [spinning-modifier]]))

(defn- apply-hp-delta! [delta max-hp]
(>evt [::events/update-hp delta max-hp])
(>evt [:toggle-overlay nil]))

(defn- condition-widget
[[id level] _on-delete]
(let [c (get data/conditions id)]
Expand Down Expand Up @@ -120,8 +124,7 @@
{:on-submit (fn-click
(let [{:keys [heal damage]} @state]
(log "Update HP: heal +" heal " -" damage)
(>evt [::events/update-hp (- heal damage) max-hp])
(>evt [:toggle-overlay nil])))}
(apply-hp-delta! (- heal damage) max-hp)))}
[:div.sections

[:div.quick-adjust
Expand Down Expand Up @@ -224,7 +227,17 @@
:per-rotation (condp > max-hp
100 20
40)
:path [:heal]]]
:path [:heal]]

(when (let [delta (:heal @state)]
(and delta (not= 0 delta)))
[:div.sections
[:input.apply {:type 'button
:value "Apply!"
:on-click (fn-click
(apply-hp-delta! (:heal @state) max-hp))
}] ])
]
])

; ======= public interface ================================
Expand Down
5 changes: 4 additions & 1 deletion src/cljs/wish/sheets/dnd5e/overlays/style.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@
[:.section-header {:margin-bottom "0px"}]

[:.touchable (merge flex/vertical
flex/align-center)]
flex/align-center)
[:input.apply (merge
styles/button
{:margin-top "1em"})]]

[:.new-hp (merge styles/text-center
{:padding "12px"
Expand Down
8 changes: 6 additions & 2 deletions src/cljs/wish/views/widgets/spinning_modifier.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,18 @@
:or {delta->color (constantly nil)}}]
(letfn [(<v []
(get-in @ratom path 0))
(>v [v]
(assoc-in @ratom path v))]
(v< [v]
(swap! ratom assoc-in path v))]
(r/with-let [state (atom nil)
rotation (r/atom 0)]
(let [delta (int (* per-rotation (/ @rotation 360)))
current (min (+ initial delta)
maximum)
color (delta->color delta)]

(when-not (= (<v) delta)
(v< delta))

[:div {:class (spinning-modifier-class)
:on-touch-move (partial on-touch-move state rotation)
:on-touch-end #(swap! state dissoc :last-touch)}
Expand Down

0 comments on commit d4b6cd8

Please sign in to comment.