generated from PEZ/rn-rf-shadow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbases_table.cljs
57 lines (49 loc) · 1.92 KB
/
bases_table.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(ns gurps.pages.character.widgets.bases-table
(:require [gurps.widgets.base :refer [view]]
[gurps.pages.character.widgets.base-text :refer [base-text]]
[gurps.pages.character.utils.damage-table :refer [damage-table]]
;; NOTE: referenced because of events registered there we depend on, this is kinda jank, need to refactor so we dont need to do this
[gurps.pages.character.widgets.encumbrance-table]
["twrnc" :refer [style] :rename {style tw}]
[re-frame.core :as rf]))
(defn bases-table
[]
[:> view {:style (tw "flex flex-col w-full gap-2")}
[:> view {:style (tw "flex flex-row flex-grow gap-2 justify-between")}
[base-text {:attr :basic-lift}]
[base-text {:attr :damage-thrust, :style (tw "justify-center")}]
[base-text {:attr :damage-swing, :style (tw "justify-end")}]]
[:> view {:style (tw "flex flex-row flex-grow gap-2 justify-between")}
[base-text {:attr :basic-speed, :upgradable? true}]
[base-text {:attr :basic-move, :upgradable? true, :style (tw "justify-end")}]]])
(def attrs [:basic-move
:basic-speed])
(doseq [attr attrs]
(rf/reg-sub
(keyword :attribute-costs attr)
(fn [db _]
(get-in db [:attribute-costs attr] 0))))
(rf/reg-event-fx
:attribute-costs/update
(fn [{:keys [db]} [_ k v]]
(let [old-v (get-in db [:attribute-costs k] 0)]
{:db (assoc-in db [:attribute-costs k] v)
:fx [[:dispatch [:profile.update/unspent-points (- v old-v)]]]
:effects.async-storage/set {:k (keyword :attribute-costs k)
:value v}})))
(rf/reg-sub
:attributes/basic-speed
:<- [:attributes/ht]
:<- [:attributes/dex]
(fn [[ht dx]]
(/ (+ ht dx) 4)))
(rf/reg-sub
:attributes/damage-thrust
:<- [:attributes/str]
(fn [str]
(get-in damage-table [str :thr])))
(rf/reg-sub
:attributes/damage-swing
:<- [:attributes/str]
(fn [str]
(get-in damage-table [str :sw])))