From c56d44a584edcf17fa6ac48996e924079ddc75ec Mon Sep 17 00:00:00 2001 From: Lalit Vatsal Date: Wed, 17 Feb 2021 22:13:57 +0530 Subject: [PATCH] code formatting using cursive --- src/cljs/reframe_codenames/core.cljs | 10 +- src/cljs/reframe_codenames/db.cljs | 32 +++--- src/cljs/reframe_codenames/events.cljs | 122 +++++++++++----------- src/cljs/reframe_codenames/subs.cljs | 56 +++++------ src/cljs/reframe_codenames/utils.cljs | 8 +- src/cljs/reframe_codenames/views.cljs | 134 ++++++++++++------------- 6 files changed, 181 insertions(+), 181 deletions(-) diff --git a/src/cljs/reframe_codenames/core.cljs b/src/cljs/reframe_codenames/core.cljs index 350f889..3c530da 100644 --- a/src/cljs/reframe_codenames/core.cljs +++ b/src/cljs/reframe_codenames/core.cljs @@ -1,10 +1,10 @@ (ns reframe-codenames.core (:require - [reagent.dom :as rdom] - [re-frame.core :as re-frame] - [reframe-codenames.events :as events] - [reframe-codenames.views :as views] - [reframe-codenames.config :as config])) + [reagent.dom :as rdom] + [re-frame.core :as re-frame] + [reframe-codenames.events :as events] + [reframe-codenames.views :as views] + [reframe-codenames.config :as config])) (defn dev-setup [] diff --git a/src/cljs/reframe_codenames/db.cljs b/src/cljs/reframe_codenames/db.cljs index f3ed657..fe88554 100644 --- a/src/cljs/reframe_codenames/db.cljs +++ b/src/cljs/reframe_codenames/db.cljs @@ -408,28 +408,28 @@ (take n))) (defn- take-colored-words [] - (let [w (take-rand-n words 25 []) - red (take-rand-n w 9 []) - blue (take-rand-n w 8 red) - grey (take-rand-n w 7 (concat red blue)) + (let [w (take-rand-n words 25 []) + red (take-rand-n w 9 []) + blue (take-rand-n w 8 red) + grey (take-rand-n w 7 (concat red blue)) black (take-rand-n w 1 (concat red blue grey))] {:all w :red red :blue blue :grey grey :black black})) (defn- game-tiles [] (let [categorized-words (take-colored-words) - all-words (:all categorized-words) - red-words-set (set (:red categorized-words)) - blue-words-set (set (:blue categorized-words)) - black-words-set (set (:black categorized-words)) - index (atom -1)] + all-words (:all categorized-words) + red-words-set (set (:red categorized-words)) + blue-words-set (set (:blue categorized-words)) + black-words-set (set (:black categorized-words)) + index (atom -1)] (map - (fn [word] - (let [color (cond (contains? red-words-set word) :red - (contains? blue-words-set word) :blue - (contains? black-words-set word) :black - :else :grey)] - {:color color :word word :index (swap! index inc) :open? false})) - all-words))) + (fn [word] + (let [color (cond (contains? red-words-set word) :red + (contains? blue-words-set word) :blue + (contains? black-words-set word) :black + :else :grey)] + {:color color :word word :index (swap! index inc) :open? false})) + all-words))) (defn default-db [] {:name "re-frame" diff --git a/src/cljs/reframe_codenames/events.cljs b/src/cljs/reframe_codenames/events.cljs index bfa5acb..4443392 100644 --- a/src/cljs/reframe_codenames/events.cljs +++ b/src/cljs/reframe_codenames/events.cljs @@ -1,77 +1,77 @@ (ns reframe-codenames.events (:require - [re-frame.core :as re-frame] - [reframe-codenames.db :as db] - [reframe-codenames.utils :as utils] - [day8.re-frame.tracing :refer [fn-traced]])) + [re-frame.core :as re-frame] + [reframe-codenames.db :as db] + [reframe-codenames.utils :as utils] + [day8.re-frame.tracing :refer [fn-traced]])) (re-frame/reg-event-db - ::initialize-db - (fn-traced [_ _] - (db/default-db))) + ::initialize-db + (fn-traced [_ _] + (db/default-db))) (re-frame/reg-event-db - ::toggle-turn - (fn-traced [d _] - (let [new-turn (utils/opp-color (:turn d))] - (merge d - {:turn new-turn - :message (utils/get-messsage-for-type :turn-message new-turn) - :turn-over? false - :hint "" - :limit 0})))) + ::toggle-turn + (fn-traced [d _] + (let [new-turn (utils/opp-color (:turn d))] + (merge d + {:turn new-turn + :message (utils/get-message-for-type :turn-message new-turn) + :turn-over? false + :hint "" + :limit 0})))) (re-frame/reg-event-db - ::toggle-spy-master - (fn-traced [d _] - (let [{:keys [spy-master? hint limit turn]} d - valid-hint? (and - (> limit 0) - (not (clojure.string/blank? hint)))] - (cond - (or (not spy-master?) valid-hint?) (-> d - (assoc :spy-master? (not spy-master?)) - (assoc :message (utils/get-messsage-for-type :turn-message turn))) - :else (-> d - (assoc :message (utils/get-messsage-for-type :spy-master-exit-error))))))) + ::toggle-spy-master + (fn-traced [d _] + (let [{:keys [spy-master? hint limit turn]} d + valid-hint? (and + (> limit 0) + (not (clojure.string/blank? hint)))] + (cond + (or (not spy-master?) valid-hint?) (-> d + (assoc :spy-master? (not spy-master?)) + (assoc :message (utils/get-message-for-type :turn-message turn))) + :else (-> d + (assoc :message (utils/get-message-for-type :spy-master-exit-error))))))) (re-frame/reg-event-db - ::open-tile - (fn-traced [d [_ i j]] - (let [index (+ (* i 5) j) - turn (:turn d) - {{{tile-color :color} index} :board} d] - (as-> d v - (assoc-in v [:board index :open?] true) - (update v :limit dec) - (assoc v :turn-over? - (or - (= (utils/opp-color turn) tile-color) - (zero? (:limit v)))) - (if (:turn-over? v) - (merge v - {:message (utils/get-messsage-for-type :open-tile-turn-over) - :hint "" - :limit 0}) - v))))) + ::open-tile + (fn-traced [d [_ i j]] + (let [index (+ (* i 5) j) + turn (:turn d) + {{{tile-color :color} index} :board} d] + (as-> d v + (assoc-in v [:board index :open?] true) + (update v :limit dec) + (assoc v :turn-over? + (or + (= (utils/opp-color turn) tile-color) + (zero? (:limit v)))) + (if (:turn-over? v) + (merge v + {:message (utils/get-message-for-type :open-tile-turn-over) + :hint "" + :limit 0}) + v))))) (re-frame/reg-event-db - ::set-hint - (fn-traced [d [_ text]] - (-> d - (assoc :hint text)))) + ::set-hint + (fn-traced [d [_ text]] + (-> d + (assoc :hint text)))) (re-frame/reg-event-db - ::set-limit - (fn-traced [d [_ limit]] - (-> d - (assoc :limit (int limit))))) + ::set-limit + (fn-traced [d [_ limit]] + (-> d + (assoc :limit (int limit))))) (re-frame/reg-event-db - ::announce-winner - (fn-traced [d [_ winner]] - (-> d - (merge - {:game-over? true - :spy-master? true - :message (utils/get-messsage-for-type :winner-announcement winner)})))) + ::announce-winner + (fn-traced [d [_ winner]] + (-> d + (merge + {:game-over? true + :spy-master? true + :message (utils/get-message-for-type :winner-announcement winner)})))) diff --git a/src/cljs/reframe_codenames/subs.cljs b/src/cljs/reframe_codenames/subs.cljs index 9be780a..7676eff 100644 --- a/src/cljs/reframe_codenames/subs.cljs +++ b/src/cljs/reframe_codenames/subs.cljs @@ -1,50 +1,50 @@ (ns reframe-codenames.subs (:require - [re-frame.core :as re-frame])) + [re-frame.core :as re-frame])) ; TODO - improve all the subs taking other subscribe as signal functions (re-frame/reg-sub - ::name - (fn [db] - (:name db))) + ::name + (fn [db] + (:name db))) (re-frame/reg-sub - ::board - (fn [db] - (:board db))) + ::board + (fn [db] + (:board db))) (re-frame/reg-sub - ::spy-master? - (fn [db] - (:spy-master? db))) + ::spy-master? + (fn [db] + (:spy-master? db))) (re-frame/reg-sub - ::turn - (fn [db] - (:turn db))) + ::turn + (fn [db] + (:turn db))) (re-frame/reg-sub - ::turn-over? - (fn [db] - (:turn-over? db))) + ::turn-over? + (fn [db] + (:turn-over? db))) (re-frame/reg-sub - ::hint - (fn [db] - (:hint db))) + ::hint + (fn [db] + (:hint db))) (re-frame/reg-sub - ::limit - (fn [db] - (:limit db))) + ::limit + (fn [db] + (:limit db))) (re-frame/reg-sub - ::message - (fn [db] - (:message db))) + ::message + (fn [db] + (:message db))) (re-frame/reg-sub - ::game-over? - (fn [db] - (:game-over? db))) + ::game-over? + (fn [db] + (:game-over? db))) diff --git a/src/cljs/reframe_codenames/utils.cljs b/src/cljs/reframe_codenames/utils.cljs index 8945b56..d09a9b6 100644 --- a/src/cljs/reframe_codenames/utils.cljs +++ b/src/cljs/reframe_codenames/utils.cljs @@ -6,7 +6,7 @@ (defn capitalize [s] (clojure.string/capitalize (name s))) -(defn get-messsage-for-type +(defn get-message-for-type ([tpe] (case tpe :open-tile-turn-over {:status :info @@ -30,7 +30,7 @@ (defn left-tiles-count-by-color [board-tiles color] (->> board-tiles (filter - #(and - (not (:open? %)) - (= color (:color %)))) + #(and + (not (:open? %)) + (= color (:color %)))) (count))) \ No newline at end of file diff --git a/src/cljs/reframe_codenames/views.cljs b/src/cljs/reframe_codenames/views.cljs index 34fe4f6..b633814 100644 --- a/src/cljs/reframe_codenames/views.cljs +++ b/src/cljs/reframe_codenames/views.cljs @@ -1,34 +1,34 @@ (ns reframe-codenames.views (:require - [re-frame.core :as re-frame] - [reframe-codenames.subs :as subs] - [reframe-codenames.events :as events] - [reframe-codenames.utils :as utils]) + [re-frame.core :as re-frame] + [reframe-codenames.subs :as subs] + [reframe-codenames.events :as events] + [reframe-codenames.utils :as utils]) (:require - ["react-bootstrap" - :refer - [Card - Button - ButtonGroup - Row - Col - Badge - Container - Accordion - FormControl - InputGroup - Alert]] - ["react-bootstrap/Card" :refer [Body Header Footer]] - ["react-bootstrap/Accordion" - :refer [Toggle Collapse] - :rename {Toggle AccToggle - Collapse AccCollapse}] - ["react-bootstrap/InputGroup" - :refer [Text Prepend Append] - :rename {Text IGText - Prepend IGPrepend - Append IGAppend}] - ["react-social-icons" :refer [SocialIcon]])) + ["react-bootstrap" + :refer + [Card + Button + ButtonGroup + Row + Col + Badge + Container + Accordion + FormControl + InputGroup + Alert]] + ["react-bootstrap/Card" :refer [Body Header Footer]] + ["react-bootstrap/Accordion" + :refer [Toggle Collapse] + :rename {Toggle AccToggle + Collapse AccCollapse}] + ["react-bootstrap/InputGroup" + :refer [Text Prepend Append] + :rename {Text IGText + Prepend IGPrepend + Append IGAppend}] + ["react-social-icons" :refer [SocialIcon]])) ; TODO - simplify booleans everywhere! @@ -51,8 +51,8 @@ [:> Body (map-indexed - (fn [index rule] [:p {:style {:text-align :left}} (str (inc index) ". " rule)]) - rules)]]]]) + (fn [index rule] [:p {:style {:text-align :left}} (str (inc index) ". " rule)]) + rules)]]]]) (defn grid-row [row-index items turn spy-master? disable?] [:> @@ -63,40 +63,40 @@ :margin 5 :padding 5} (map-indexed - (fn [col-index item] - (let [{:keys [open? color]} item] + (fn [col-index item] + (let [{:keys [open? color]} item] + [:> + Col + {:key (str "grid-cell-" (+ (* row-index 5) col-index)) + :style {:width "20vw" + :padding 0 + :margin 2}} [:> - Col - {:key (str "grid-cell-" (+ (* row-index 5) col-index)) - :style {:width "20vw" - :padding 0 - :margin 2}} - [:> - Button - {:key (str "grid-cell-" (+ (* row-index 5) col-index)) - :class [:board-grid-btn] - :variant (if (and spy-master? open?) :info :light) - :style {:border-radius 2 - :padding 5 - :width "100%" - :height "10vh" - :justify-content :center - :font-size "2.5vmin" - :color (when (or open? spy-master?) color)} - :disabled (or spy-master? open? disable?) - :size :sm - :on-click #(re-frame/dispatch - ; TODO - remove logic from view! - (if (= color :black) - [::events/announce-winner (utils/opp-color turn)] - [::events/open-tile row-index col-index]))} - (:word item)]])) - items)]) + Button + {:key (str "grid-cell-" (+ (* row-index 5) col-index)) + :class [:board-grid-btn] + :variant (if (and spy-master? open?) :info :light) + :style {:border-radius 2 + :padding 5 + :width "100%" + :height "10vh" + :justify-content :center + :font-size "2.5vmin" + :color (when (or open? spy-master?) color)} + :disabled (or spy-master? open? disable?) + :size :sm + :on-click #(re-frame/dispatch + ; TODO - remove logic from view! + (if (= color :black) + [::events/announce-winner (utils/opp-color turn)] + [::events/open-tile row-index col-index]))} + (:word item)]])) + items)]) (defn grid [board-tiles turn spy-master? disable?] (->> (partition 5 board-tiles) (map-indexed - #(grid-row %1 %2 turn spy-master? disable?)))) + #(grid-row %1 %2 turn spy-master? disable?)))) (defn hint-badge [hint] (when (not (clojure.string/blank? hint)) @@ -170,14 +170,14 @@ ; TODO - split this main-panel into multpple functions having their own subscriptions (let [spy-master? @(re-frame/subscribe [::subs/spy-master?]) board-tiles @(re-frame/subscribe [::subs/board]) - turn @(re-frame/subscribe [::subs/turn]) - red-left (utils/left-tiles-count-by-color board-tiles :red) - blue-left (utils/left-tiles-count-by-color board-tiles :blue) - turn-over? @(re-frame/subscribe [::subs/turn-over?]) - hint @(re-frame/subscribe [::subs/hint]) - limit @(re-frame/subscribe [::subs/limit]) - message @(re-frame/subscribe [::subs/message]) - game-over? @(re-frame/subscribe [::subs/game-over?])] + turn @(re-frame/subscribe [::subs/turn]) + red-left (utils/left-tiles-count-by-color board-tiles :red) + blue-left (utils/left-tiles-count-by-color board-tiles :blue) + turn-over? @(re-frame/subscribe [::subs/turn-over?]) + hint @(re-frame/subscribe [::subs/hint]) + limit @(re-frame/subscribe [::subs/limit]) + message @(re-frame/subscribe [::subs/message]) + game-over? @(re-frame/subscribe [::subs/game-over?])] (when (zero? red-left) (re-frame/dispatch-sync [::events/announce-winner :red])) (when (zero? blue-left) (re-frame/dispatch-sync [::events/announce-winner :blue])) [:>