-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
181 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)})))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.