diff --git a/src/main/ogres/app/component/panel_lobby.cljs b/src/main/ogres/app/component/panel_lobby.cljs index b6e383b..7e2ca7b 100644 --- a/src/main/ogres/app/component/panel_lobby.cljs +++ b/src/main/ogres/app/component/panel_lobby.cljs @@ -3,7 +3,6 @@ [ogres.app.const :refer [VERSION]] [ogres.app.hooks :refer [use-dispatch use-query]] [ogres.app.provider.release :as release] - [ogres.app.util :refer [comp-fn]] [uix.core :refer [defui $ use-context]])) (def ^:private query-footer @@ -108,7 +107,7 @@ ($ :legend (str "Players")) ($ :.session-players (if (seq conns) - (let [xf (filter (comp-fn = :user/type :conn))] + (let [xf (filter (comp #{:conn} :user/type))] (for [conn (->> conns (sequence xf) (sort-by :db/id))] ($ :.session-player {:key (:db/id conn)} ($ :.session-player-color {:data-color (:user/color conn)}) diff --git a/src/main/ogres/app/component/panel_tokens.cljs b/src/main/ogres/app/component/panel_tokens.cljs index 047f4c3..7a0593d 100644 --- a/src/main/ogres/app/component/panel_tokens.cljs +++ b/src/main/ogres/app/component/panel_tokens.cljs @@ -2,7 +2,7 @@ (:require [goog.object :as object :refer [getValueByKeys]] [ogres.app.component :refer [icon image pagination modal-fullscreen]] [ogres.app.hooks :refer [use-publish use-dispatch use-image use-image-uploader use-query use-shortcut]] - [ogres.app.util :refer [separate comp-fn]] + [ogres.app.util :refer [separate]] [uix.core :as uix :refer [defui $ use-callback use-ref use-state use-effect use-memo]] [uix.dom :refer [create-portal]] ["@dnd-kit/core" @@ -124,7 +124,7 @@ (let [result (use-query query-form [:db/ident :root]) {data :root/token-images {type :user/type} :root/user} result - [pub prv] (separate (comp-fn = :image/scope :public) data) + [pub prv] (separate (comp #{:public} :image/scope) data) data-pub (into [:default] (reverse pub)) data-prv (vec (reverse prv)) drop-pub (use-droppable #js {"id" "scope-pub"}) diff --git a/src/main/ogres/app/events.cljs b/src/main/ogres/app/events.cljs index e4e2b7c..249aae3 100644 --- a/src/main/ogres/app/events.cljs +++ b/src/main/ogres/app/events.cljs @@ -4,7 +4,7 @@ [clojure.string :refer [trim]] [ogres.app.const :refer [grid-size]] [ogres.app.geom :as geom] - [ogres.app.util :refer [comp-fn round round-grid]])) + [ogres.app.util :refer [round]])) (def ^:private suffix-max-xf (map (fn [[label tokens]] [label (apply max (map :initiative/suffix tokens))]))) @@ -272,14 +272,14 @@ :camera/point [0 0] :camera/scale 1}})) (= id (:db/id (:user/camera user))) - (let [host-cam (first (filter (comp-fn not= :db/id id) (:user/cameras user))) + (let [host-cam (first (filter (comp (complement #{id}) :db/id) (:user/cameras user))) host-scn (:db/id (:camera/scene host-cam))] (into [[:db/retractEntity (:db/id camera)] [:db/retractEntity (:db/id (:camera/scene camera))] {:db/ident :user :user/camera {:db/id (:db/id host-cam)}}] (for [[tmp conn] (sequence (indexed) (:session/conns session)) :let [cam (->> (:user/cameras conn) - (filter (comp-fn = (comp :db/id :camera/scene) host-scn)) + (filter (comp #{host-scn} :db/id :camera/scene)) (first)) idx (or (:db/id cam) tmp)]] {:db/id (:db/id conn) @@ -475,13 +475,16 @@ [ox oy] :scene/grid-origin} :camera/scene} :user/camera} user tx (+ (/ sx (or scale 1)) (or cx 0)) - ty (+ (/ sy (or scale 1)) (or cy 0))] + ty (+ (/ sy (or scale 1)) (or cy 0)) + rd (/ grid-size 2) + mx (mod ox grid-size) + my (mod oy grid-size)] [(cond-> {:db/id -1 :object/type :token/token} (some? hash) (assoc :token/image {:image/hash hash}) (not align?) (assoc :object/point [(round tx) (round ty)]) align? (assoc :object/point - [(round-grid tx (/ grid-size 2) (mod ox grid-size)) - (round-grid ty (/ grid-size 2) (mod oy grid-size))])) + [(+ (round (- tx rd mx) grid-size) rd mx) + (+ (round (- ty rd my) grid-size) rd my)])) {:db/id (:db/id (:user/camera user)) :camera/selected -1 :camera/draw-mode :select diff --git a/src/main/ogres/app/util.cljs b/src/main/ogres/app/util.cljs index 7a2647c..36445da 100644 --- a/src/main/ogres/app/util.cljs +++ b/src/main/ogres/app/util.cljs @@ -1,5 +1,4 @@ -(ns ogres.app.util - (:require [ogres.app.const :refer [grid-size]])) +(ns ogres.app.util) (defn key-by "Returns a map of the given `coll` whose keys are the result of calling `f` @@ -15,25 +14,11 @@ (vec (for [f [filter remove]] (map first (f second pcoll)))))) -(defn comp-fn - "Returns a function which applies f with the result of calling key-fn on the - given value and xs. Useful for passing to higher order functions like - filter and map." - [f key-fn & xs] - (fn [x] - (apply f (key-fn x) xs))) - (defn round "Round the scalar `x` to nearest `n` (default 1)." ([x] (round x 1)) ([x n] (* (js/Math.round (/ x n)) n))) -(defn round-grid - "Returns the given scalar `x` rounded to the nearest `grid-size`, accounting - for the radius `r` of the object and scalar offset `o`." - [x r o] - (+ (round (- x r o) grid-size) r o)) - (defn display-size "Returns the given size in bytes as a string using the most appropriate unit affix.