Skip to content

Commit

Permalink
Highlight player name in logs to more easily determine side
Browse files Browse the repository at this point in the history
  • Loading branch information
butzopower committed Dec 20, 2023
1 parent d6364aa commit 63158c0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
9 changes: 5 additions & 4 deletions src/cljs/nr/gameboard/log.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[nr.gameboard.state :refer [game-state not-spectator?]]
[nr.help :refer [command-info]]
[nr.translations :refer [tr]]
[nr.utils :refer [influence-dot render-message]]
[nr.utils :refer [highlight-side influence-dot render-message]]
[nr.ws :as ws]
[reagent.core :as r]
[reagent.dom :as rdom]))
Expand Down Expand Up @@ -175,9 +175,10 @@
[indicate-action]
[command-menu !input-ref state]]))))


(defn log-messages []
(let [log (r/cursor game-state [:log])]
(let [log (r/cursor game-state [:log])
corp (r/cursor game-state [:corp :user :username])
runner (r/cursor game-state [:runner :user :username])]
(r/create-class
{:display-name "log-messages"

Expand Down Expand Up @@ -211,7 +212,7 @@
(fn [{:keys [user text timestamp]}]
^{:key timestamp}
(if (= user "__system__")
[:div.system (render-message text)]
[:div.system (render-message (highlight-side text @corp @runner))]
[:div.message
[avatar user {:opts {:size 38}}]
[:div.content
Expand Down
10 changes: 6 additions & 4 deletions src/cljs/nr/stats.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
[nr.avatar :refer [avatar]]
[nr.end-of-game-stats :refer [build-game-stats]]
[nr.translations :refer [tr tr-format tr-lobby tr-side]]
[nr.utils :refer [day-word-with-time-formatter faction-icon
format-date-time notnum->zero num->percent render-message
[nr.utils :refer [day-word-with-time-formatter faction-icon format-date-time
highlight-side notnum->zero num->percent render-message
set-scroll-top store-scroll-top]]
[nr.ws :as ws]
[reagent.core :as r]))
Expand Down Expand Up @@ -129,15 +129,17 @@
:component-will-unmount #(store-scroll-top % log-scroll-top)
:reagent-render
(fn [state _log-scroll-top]
(let [game (:view-game @state)]
(let [game (:view-game @state)
corp (get-in game [:corp :player :username])
runner (get-in game [:runner :player :username])]
[:div {:style {:overflow "auto"}}
[:div.panel.messages
(if (seq (:log game))
(doall (map-indexed
(fn [i msg]
(when-not (and (= (:user msg) "__system__") (= (:text msg) "typing"))
(if (= (:user msg) "__system__")
[:div.system {:key i} (render-message (:text msg))]
[:div.system {:key i} (render-message (highlight-side (:text msg) corp runner))]
[:div.message {:key i}
[avatar (:user msg) {:opts {:size 38}}]
[:div.content
Expand Down
23 changes: 14 additions & 9 deletions src/cljs/nr/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,7 @@
(defn render-cards
"Render all cards in a given text or HTML fragment input"
[input]
(cond
(re-find (contains-card-pattern) (or input ""))
(render-input input (card-patterns))
(string? input) [:<> input]
(vector? input) input
:else [:<>]))
(render-input input (card-patterns)))

(defn render-specials
"Render all special codes in a given text or HTML fragment input"
Expand All @@ -307,9 +302,19 @@
(defn render-message
"Render icons, cards and special codes in a message"
[input]
(if (string? input)
(render-specials (render-icons (render-cards input)))
input))
(render-specials (render-icons (render-cards input))))

(defn highlight-patterns-impl [corp runner]
(letfn [(regex-of [player-name] (re-pattern (str "(?i)" (regex-escape player-name))))]
(->> {corp [:span.corp-username corp]
runner [:span.runner-username runner]}
(filter (fn [[k _]] (not-empty k)))
(map (fn [[k v]] [(regex-of k) v]))
(sort-by (comp count str first) >))))
(def highlight-patterns (memoize highlight-patterns-impl))

(defn highlight-side [message corp runner]
(render-input message (highlight-patterns corp runner)))

(defn cond-button
[text cond f]
Expand Down
8 changes: 8 additions & 0 deletions src/css/chat.styl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@
button
margin-right: 0

.corp-username
font-weight: bold
color: blue-light

.runner-username
font-weight: bold
color: red-core

.typing
position: absolute
margin: 0
Expand Down

0 comments on commit 63158c0

Please sign in to comment.