diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/votann/core.clj | 4 | ||||
| -rw-r--r-- | src/votann/event_handler.clj | 46 | ||||
| -rw-r--r-- | src/votann/tab_widget.clj | 6 |
3 files changed, 35 insertions, 21 deletions
diff --git a/src/votann/core.clj b/src/votann/core.clj index 7958151..d24b87e 100644 --- a/src/votann/core.clj +++ b/src/votann/core.clj @@ -1,7 +1,7 @@ (ns votann.core (:gen-class) (:require [votann.util :refer [get-resource-path]] - [votann.event-handler :refer [map-event-handler *list-units]] + [votann.event-handler :refer [map-event-handler *state]] [votann.tab_widget :refer [tab-widget]] [cljfx.api :as fx])) @@ -29,4 +29,4 @@ (defn -main [& args] - (fx/mount-renderer *list-units renderer)) + (fx/mount-renderer *state renderer)) diff --git a/src/votann/event_handler.clj b/src/votann/event_handler.clj index 6805d53..8558762 100644 --- a/src/votann/event_handler.clj +++ b/src/votann/event_handler.clj @@ -1,36 +1,51 @@ (ns votann.event-handler + (:require [votann.codex :refer [kin-models]]) (:import [javafx.scene.input KeyCode KeyEvent])) -(def *list-units (atom {:points 0 :units []})) +(def *state (atom {:list + {:points 0 + :units []} + :battle-simulator + {:data [] + :total-damage {} + :data-type "Total" + :count "0" + :weapon-type "Ranged" + :model (:name (first kin-models)) + :target (:name (first kin-models)) + :rolls "1" + :target-count "1" + :tokens "0 " + :disabled false}})) (defn enter-event [function e] (if (= KeyCode/ENTER (.getCode ^KeyEvent (:fx/event e))) (function e))) (defn undo-points [_] - (if-not (empty? (get-in @*list-units [:units])) - (let [points (:points (last (:units @*list-units)))] - (swap! *list-units assoc :points (max 0 (- (:points @*list-units) points))) - (swap! *list-units update-in [:units] pop)))) + (if-not (empty? (get-in @*state [:list :units])) + (let [points (:points (last (get-in @*state [:list :units])))] + (swap! *state assoc-in [:list :points] (max 0 (- (get-in @*state [:list :points]) points))) + (swap! *state update-in [:list :units] pop)))) (defn restart-list [_] - (if-not (empty? (get-in @*list-units [:units])) + (if-not (empty? (get-in @*state [:list :units])) (do - (swap! *list-units assoc :points 0) - (swap! *list-units assoc-in [:units] [])))) + (swap! *state assoc-in [:list :points] 0) + (swap! *state assoc-in [:list :units] [])))) (defn add-unit [e] - (swap! *list-units assoc :points (+ (:points @*list-units) (:points (:event/target e)))) - (swap! *list-units update-in [:units] conj (:event/target e))) + (swap! *state assoc-in [:list :points] (+ (get-in @*state [:list :points]) (:points (:event/target e)))) + (swap! *state update-in [:list :units] conj (:event/target e))) (defn remove-unit [e] (do - (swap! *list-units assoc :points (max 0 (- (:points @*list-units) (:points (:event/target e))))) - (swap! *list-units update :units #(vec (concat (subvec % 0 (:index (:event/target e))) (subvec % (inc (:index (:event/target e))))))))) + (swap! *state assoc-in [:list :points] (max 0 (- (get-in @*state [:list :points]) (:points (:event/target e))))) + (swap! *state update-in [:list :units] #(vec (concat (subvec % 0 (:index (:event/target e))) (subvec % (inc (:index (:event/target e))))))))) (defn export-list [_] - (if-not (empty? (get-in @*list-units [:units])) - (spit (str (.toString (java.time.Instant/now)) ".list") @*list-units))) + (if-not (empty? (get-in @*state [:list :units])) + (spit (str (.toString (java.time.Instant/now)) ".list") (:list @*state)))) (defn map-event-handler [e] (cond (= :event/undo-unit-click (:event/type e)) @@ -61,5 +76,4 @@ (export-list e) (= :event/export-list-enter (:event/type e)) - (enter-event export-list e) - )) + (enter-event export-list e))) diff --git a/src/votann/tab_widget.clj b/src/votann/tab_widget.clj index 297d47c..85bb770 100644 --- a/src/votann/tab_widget.clj +++ b/src/votann/tab_widget.clj @@ -4,6 +4,7 @@ [votann.unit-widget :refer [unit-view-widget]] [votann.enhancements-widget :refer [enhancements-view-widget]] [votann.codex-view :refer [codex-page]] + [votann.battle-simulator-widget :refer [place-holder]] [cljfx.api :as fx] [cljfx.ext.web-view :as fx.ext.web-view])) @@ -37,8 +38,7 @@ [{:fx/type :tab :text "Battle Simulator" :closable false - :content {:fx/type :label - :text "coming soon (TM)"}}]) + :content place-holder}]) (defn tab-widget [data] - (vec (apply concat [(list-view-tab data) codex-view-tab battle-simulator-view-tab]))) + (vec (apply concat [(list-view-tab (:list data)) codex-view-tab battle-simulator-view-tab]))) |