From e032790aec01f9893dfd094feb30f0555a307a32 Mon Sep 17 00:00:00 2001 From: 0xNul <57599792+0xNul@users.noreply.github.com> Date: Sun, 23 Jul 2023 12:06:37 -0700 Subject: added target distance for weapon type that use them --- src/votann/battle_simulator_widget.clj | 13 ++++++++++--- src/votann/event_handler.clj | 19 ++++++++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/votann/battle_simulator_widget.clj b/src/votann/battle_simulator_widget.clj index 256f9a3..de86b4a 100644 --- a/src/votann/battle_simulator_widget.clj +++ b/src/votann/battle_simulator_widget.clj @@ -30,7 +30,7 @@ (= "Total" type) {:fx/type :xy-chart-data :x-value (util/total damage) :y-value weapon})))) -(defn battle-simulator-widget [{:keys [data total-damage data-type count weapon-type rolls target-count tokens disabled]}] +(defn battle-simulator-widget [{:keys [data total-damage data-type count weapon-type rolls target-count target-distance tokens disabled]}] {:fx/type :v-box :style "-fx-background-color: #e1e0e1;" :children [{:fx/type :h-box @@ -74,8 +74,15 @@ {:fx/type :text-field :on-key-typed {:event/type :event/choice-select-target-size} :max-width 82 - :text target-count} - ]} + :text target-count}]} + {:fx/type :v-box + :children [ + {:fx/type :label + :text "Distance \""} + {:fx/type :text-field + :on-key-typed {:event/type :event/choice-select-target-distance} + :max-width 82 + :text target-distance}]} {:fx/type :v-box :children [ {:fx/type :label diff --git a/src/votann/event_handler.clj b/src/votann/event_handler.clj index 6a9a735..794fd22 100644 --- a/src/votann/event_handler.clj +++ b/src/votann/event_handler.clj @@ -17,6 +17,7 @@ :target (:name (first kin-models)) :rolls "1" :target-count "1" + :target-distance "2" :tokens "0 " :disabled false}})) @@ -107,7 +108,11 @@ ;;battle-simulator events (= :event/choice-select-weapon (:event/type e)) - (swap! *state assoc-in [:battle-simulator :weapon-type] (.getValue (.getTarget (:fx/event e)))) + (do + (swap! *state assoc-in [:battle-simulator :weapon-type] (.getValue (.getTarget (:fx/event e)))) + (if (= "Ranged" (get-in @*state [:battle-simulator :weapon-type])) + (swap! *state assoc-in [:battle-simulator :target-distance] "2") + (swap! *state assoc-in [:battle-simulator :target-distance] "1"))) (= :event/choice-select-model (:event/type e)) (do @@ -162,6 +167,18 @@ (.setText (.getTarget (:fx/event e)) "") (swap! *state assoc-in [:battle-simulator :disabled] true))) + (= :event/choice-select-target-distance (:event/type e)) + (try + (let [count (Integer/parseInt (.getText (.getTarget (:fx/event e))))] + (if (< count 1) + (do + (swap! *state assoc-in [:battle-simulator :target-distance] "") + (.setText (.getTarget (:fx/event e)) "")) + (swap! *state assoc-in [:battle-simulator :target-distance] (str count)))) + (catch java.lang.NumberFormatException | java.lang.NullPointerException e + (swap! *state assoc-in [:battle-simulator :target-distance] "") + (.setText (.getTarget (:fx/event e)) ""))) + (= :event/choice-select-tokens (:event/type e)) (swap! *state assoc-in [:battle-simulator :tokens] (.getValue (.getTarget (:fx/event e)))) -- cgit v1.2.3