(ns bombnet.web.display) (defn init-display [] (let [display (new js/ROT.Display (js-obj "height" 17 "width" 36))] (.appendChild (.. js/document -body) (.getContainer display)) display)) (defonce display (init-display)) (defn ^:private %c [color & strings] (str "%c{" color "}" (apply str strings) "%c{}")) (defn render-game [game] (let [{state :state {local-id :id} :local} @game {:keys [board players bombs explosion]} state board-list (apply concat (map-indexed (fn [y row] (map-indexed (fn [x c] [x y c]) row)) board))] (.clear display) (doseq [[x y c] board-list] (.draw display x y c)) (doseq [[x y] explosion] (.draw display x y "X" "orange")) (doseq [{[x y] :pos counter :counter :or {counter -1}} bombs] (if (< counter 0) (.draw display x y "Q" "orange") (.draw display x y counter "orange"))) (doseq [{[x y] :pos color :color} players] (.draw display x y "@" color)) (.drawText display 23 0 "Players") (doseq [[index {id :id color :color}] (map-indexed #(vector % %2) (sort-by :color players))] (if (= local-id id) (.drawText display 22 (+ 2 index) (str "*" (%c color id))) (.drawText display 23 (+ 2 index) (%c color id))))))