Skip to content

Commit

Permalink
Merge pull request #4375 from NoahTheDuke/nb/revert-carry-over-log-fr…
Browse files Browse the repository at this point in the history
…om-lobby

Revert "Initialize log with messages from the lobby"
  • Loading branch information
NoahTheDuke authored Aug 12, 2019
2 parents dc02aa0 + 48e533d commit 813782c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/clj/game/core/state.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
winning-user])

(defn new-state
[gameid room log now spectatorhands corp runner]
[gameid room now spectatorhands corp runner]
(map->State
{:gameid gameid :log log :active-player :runner :end-turn true
{:gameid gameid :log [] :active-player :runner :end-turn true
:room room
:rid 0 :turn 0 :eid 0
:sfx [] :sfx-current-id 0
Expand Down
4 changes: 1 addition & 3 deletions src/clj/game/core/turns.clj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

(defn- init-game-state
"Initialises the game state"
[{:keys [players gameid log spectatorhands room] :as game}]
[{:keys [players gameid spectatorhands room] :as game}]
(let [corp (some #(when (corp? %) %) players)
runner (some #(when (runner? %) %) players)
corp-deck (create-deck (:deck corp) (:user corp))
Expand All @@ -61,7 +61,6 @@
(new-state
gameid
room
log
(t/now)
spectatorhands
(new-corp (:user corp) corp-identity corp-options (zone :deck corp-deck) corp-deck-id corp-quote)
Expand All @@ -73,7 +72,6 @@
(let [state (init-game-state game)
corp-identity (get-in @state [:corp :identity])
runner-identity (get-in @state [:runner :identity])]
(system-say state :corp "[hr]")
(init-identity state :corp corp-identity)
(init-identity state :runner runner-identity)
(let [side :corp]
Expand Down
60 changes: 26 additions & 34 deletions src/clj/web/lobby.clj
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,10 @@
:room room
:format format
:players [{:user user
:ws-id client-id
:ws-id client-id
:side side
:options options}]
:spectators []
:log []
:last-update (t/now)}]
(swap! all-games assoc gameid game)
(swap! client-gameids assoc client-id gameid)
Expand All @@ -240,26 +239,22 @@
(when-let [{gameid :gameid} (game-for-client client-id)]
(when (player-or-spectator client-id gameid)
(remove-user client-id gameid)
(let [message {:user "__system__"
:text (str username " left the game.")}]
(swap! all-games update-in [gameid :log] conj message)
(ws/broadcast-to! (lobby-clients gameid)
:lobby/message
message)))))
(ws/broadcast-to! (lobby-clients gameid)
:lobby/message
{:user "__system__"
:text (str username " left the game.")}))))

(defn handle-lobby-say
[{{{:keys [username] :as user} :user} :ring-req
client-id :client-id
{:keys [msg gameid]} :?data}]
(when (player-or-spectator client-id gameid)
(let [game (game-for-id gameid)
message {:user user
:text msg}]
(swap! all-games update-in [gameid :log] conj message)
(let [game (game-for-id gameid)]
(ws/broadcast-to!
(map :ws-id (concat (:players game) (:spectators game)))
:lobby/message
message))))
{:user user
:text msg}))))

(defn handle-swap-sides
[{{{:keys [username] :as user} :user} :ring-req
Expand Down Expand Up @@ -291,16 +286,14 @@
(if (and (not (already-in-game? user game))
(or (empty? game-password)
(bcrypt/check password game-password)))
(let [message {:user "__system__"
:notification "ting"
:text (str username " joined the game.")}]
(join-game user client-id gameid)
(swap! all-games update-in [gameid :log] conj message)
(ws/broadcast-to! (lobby-clients gameid)
:lobby/message
message)
(ws/send! client-id [:lobby/select {:gameid gameid}])
(when reply-fn (reply-fn 200)))
(do (join-game user client-id gameid)
(ws/broadcast-to! (lobby-clients gameid)
:lobby/message
{:user "__system__"
:notification "ting"
:text (str username " joined the game.")})
(ws/send! client-id [:lobby/select {:gameid gameid}])
(when reply-fn (reply-fn 200)))
(when reply-fn (reply-fn 403))))
(when reply-fn (reply-fn 404))))

Expand All @@ -318,17 +311,16 @@
(if (and (not (already-in-game? user game))
(or (empty? game-password)
(bcrypt/check password game-password)))
(let [message {:user "__system__"
:notification "ting"
:text (str username " joined the game as a spectator.")}]
(spectate-game user client-id gameid)
(swap! all-games update-in [gameid :log] conj message)
(ws/broadcast-to! (lobby-clients gameid)
:lobby/message
message)
(ws/send! client-id [:lobby/select {:gameid gameid :started started}])
(when reply-fn (reply-fn 200))
true)
(do (spectate-game user client-id gameid)

(ws/broadcast-to! (lobby-clients gameid)
:lobby/message
{:user "__system__"
:notification "ting"
:text (str username " joined the game as a spectator.")})
(ws/send! client-id [:lobby/select {:gameid gameid :started started}])
(when reply-fn (reply-fn 200))
true)
(when reply-fn
(reply-fn 403)
false))))
Expand Down
1 change: 0 additions & 1 deletion test/clj/game_test/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
[{:keys [corp runner mulligan start-as dont-start-turn dont-start-game] :as players}]
(let [state (core/init-game
{:gameid 1
:log []
:players [{:side "Corp"
:user {:username "Corp"}
:deck {:identity (:identity corp)
Expand Down

0 comments on commit 813782c

Please sign in to comment.