diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn new file mode 100644 index 000000000..4e901577e --- /dev/null +++ b/.clj-kondo/config.edn @@ -0,0 +1,32 @@ +{:linters {:if {:level :off} + :unused-namespace {:level :off} + :unused-binding {:level :off} + :unresolved-symbol + {:exclude + [(clojure.core.match/match) + (cljs.core.match/match) + (io.pedestal.interceptor.error/error-dispatch) + (orcpub.modifiers/modifier) + (orcpub.modifiers/deferred-modifier) + (orcpub.modifiers/cum-sum-mod) + (orcpub.modifiers/vec-mod) + (orcpub.modifiers/set-mod) + (orcpub.modifiers/map-mod) + (orcpub.modifiers/fn-mod) + (orcpub.dnd.e5.modifiers/spells-known-cfg) + (orcpub.dnd.e5.modifiers/prop-trait) + (orcpub.dnd.e5.modifiers/dependent-trait) + (orcpub.dnd.e5.modifiers/dependent-trait-2) + (orcpub.dnd.e5.modifiers/skill-proficiency) + (orcpub.dnd.e5.modifiers/skill-expertise) + (orcpub.dnd.e5.modifiers/tool-expertise) + (orcpub.dnd.e5.modifiers/ac-bonus-fn) + (orcpub.dnd.e5.modifiers/attack) + (orcpub.dnd.e5.modifiers/action) + (orcpub.dnd.e5.modifiers/bonus-action) + (orcpub.dnd.e5.modifiers/reaction) + (orcpub.dnd.e5.modifiers/level-val) + (orcpub.entity-spec/make-entity) + (orcpub.routes-test/with-conn)]}} + :lint-as {reagent.core/with-let clojure.core/let + hiccup.def/defhtml clojure.core/defn}} diff --git a/.ebextensions/https-instance-securitygroup.config b/.ebextensions/https-instance-securitygroup.config deleted file mode 100644 index 578ee1f92..000000000 --- a/.ebextensions/https-instance-securitygroup.config +++ /dev/null @@ -1,9 +0,0 @@ -Resources: - sslSecurityGroupIngress: - Type: AWS::EC2::SecurityGroupIngress - Properties: - GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]} - IpProtocol: tcp - ToPort: 443 - FromPort: 443 - CidrIp: 0.0.0.0/0 \ No newline at end of file diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a9c346212..7a2718f01 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -3,21 +3,19 @@ name: Continuous Integration on: [pull_request] jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Run linter + run: lein lint build-and-test: name: Build and Test runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 - - name: Setup java - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Setup Clojure tools - uses: DeLaGuardo/setup-clojure@master - with: - tools-deps: latest - lein: latest - boot: latest - name: Run tests run: lein test diff --git a/.gitignore b/.gitignore index 55677f550..aacb42646 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ pom.xml /out/ /target/ /node_modules/ +/.clj-kondo/.cache .lein-deps-sum .lein-repl-history .lein-plugins/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 079130527..000000000 --- a/.travis.yml +++ /dev/null @@ -1 +0,0 @@ -language: clojure diff --git a/project.clj b/project.clj index 45911895d..ffade8bd5 100644 --- a/project.clj +++ b/project.clj @@ -62,13 +62,14 @@ [vvvvalvalval/datomock "0.2.0"] [com.datomic/datomic-free "0.9.5697"] [funcool/cuerdas "2.2.0"] - [camel-snake-kebab "0.4.0"] - ] + [camel-snake-kebab "0.4.0"]] :plugins [[lein-figwheel "0.5.19"] [lein-cljsbuild "1.1.7" :exclusions [[org.clojure/clojure]]] [lein-garden "0.3.0"] [lein-environ "1.1.0"] + [lein-cljfmt "0.6.8"] + [lein-kibit "0.1.8"] #_[lein-resource "16.9.1"]] :source-paths ["src/clj" "src/cljc" "src/cljs"] @@ -81,14 +82,14 @@ :uberjar-name "orcpub.jar" - :garden {:builds [{ ;; Optional name of the build: + :garden {:builds [{;; Optional name of the build: :id "screen" ;; Source paths where the stylesheet source code is :source-paths ["src/clj" "src/cljc"] ;; The var containing your stylesheet: :stylesheet orcpub.styles.core/app ;; Compiler flags passed to `garden.core/css`: - :compiler { ;; Where to save the file: + :compiler {;; Where to save the file: :output-to "resources/public/css/compiled/styles.css" ;; Compress the output? :pretty-print? false}}]} @@ -97,8 +98,7 @@ :cljsbuild {:builds {:dev - { - :source-paths ["web/cljs" "src/cljc" "src/cljs"] + {:source-paths ["web/cljs" "src/cljc" "src/cljs"] ;; the presence of a :figwheel configuration here ;; will cause figwheel to inject the figwheel client @@ -114,10 +114,9 @@ :asset-path "/js/compiled/out" :output-to "resources/public/js/compiled/orcpub.js" :output-dir "resources/public/js/compiled/out" - :source-map-timestamp true}}} - } + :source-map-timestamp true}}}} - :figwheel { ;; :http-server-root "public" ;; default and assumes "resources" + :figwheel {;; :http-server-root "public" ;; default and assumes "resources" ;; :server-port 3449 ;; default ;; :server-ip "127.0.0.1" @@ -153,12 +152,11 @@ ;; :server-logfile "tmp/logs/figwheel-logfile.log" } - :repl-options { - ;; If nREPL takes too long to load it may timeout, + :repl-options {;; If nREPL takes too long to load it may timeout, ;; increase this to wait longer before timing out. ;; Defaults to 30000 (30 seconds) - :timeout 300000 ; 5 mins to wait - } + :timeout 300000 ; 5 mins to wait + } ;; setting up nREPL for Figwheel and ClojureScript dev ;; Please see: @@ -172,6 +170,7 @@ "externs" ["do" "clean" ["run" "-m" "externs"]] "rebuild-modules" ["run" "-m" "user" "--rebuild-modules"] + "lint" ["with-profile" "lint" "run" "-m" "clj-kondo.main" "--lint" "src"] "prod-build" ^{:doc "Recompile code with prod profile."} ["externs" ["with-profile" "prod" "cljsbuild" "once" "main"]]} @@ -219,14 +218,14 @@ :omit-source true :cljsbuild {:builds {:prod - { - :source-paths ["web/cljs" "src/cljc" "src/cljs"] + {:source-paths ["web/cljs" "src/cljc" "src/cljs"] :compiler {:main orcpub.core :asset-path "/js/compiled/out" :output-to "resources/public/js/compiled/orcpub.js" ;;:output-dir "resources/public/js/compiled/out" :optimizations :advanced :pretty-print false}}}}} + :lint {:dependencies [[clj-kondo "RELEASE"]]} ;; Use like: lein with-profile +start-server repl :start-server {:repl-options {:init-ns user :init (start-server)}}}) diff --git a/src/clj/orcpub/db/schema.clj b/src/clj/orcpub/db/schema.clj index 1b4e88553..6ddbbe9d0 100644 --- a/src/clj/orcpub/db/schema.clj +++ b/src/clj/orcpub/db/schema.clj @@ -21,12 +21,6 @@ :db/cardinality :db.cardinality/one :db/noHistory true}) -(defn fulltext-prop [key] - {:db/ident key - :db/valueType :db.type/string - :db/cardinality :db.cardinality/one - :db/fulltext true}) - (defn fulltext-prop [key] {:db/ident key :db/valueType :db.type/string diff --git a/src/clj/orcpub/email.clj b/src/clj/orcpub/email.clj index acffc4a81..258d48c47 100644 --- a/src/clj/orcpub/email.clj +++ b/src/clj/orcpub/email.clj @@ -85,7 +85,7 @@ :subject "Exception" :body [{:type "text/plain" :content (let [writer (java.io.StringWriter.)] - (do (clojure.pprint/pprint (:request context) writer) - (clojure.pprint/pprint (or (ex-data exception) exception) writer) - (str writer)))}]}))) + (clojure.pprint/pprint (:request context) writer) + (clojure.pprint/pprint (or (ex-data exception) exception) writer) + (str writer))}]}))) diff --git a/src/clj/orcpub/pdf.clj b/src/clj/orcpub/pdf.clj index 92f4e1126..22363019b 100644 --- a/src/clj/orcpub/pdf.clj +++ b/src/clj/orcpub/pdf.clj @@ -1,18 +1,15 @@ (ns orcpub.pdf (:require [clojure.string :as s] + [clojure.stacktrace :as strace] + [clojure.java.io :as io] [orcpub.common :as common] [orcpub.dnd.e5.display :as dis5e] [orcpub.dnd.e5.monsters :as monsters] - [orcpub.dnd.e5.options :as options] - [clojure.java.io :as io]) - (:import (org.apache.pdfbox.pdmodel.interactive.form PDCheckBox PDComboBox PDListBox PDRadioButton PDTextField) - (org.apache.pdfbox.cos COSName) + [orcpub.dnd.e5.options :as options]) + (:import (org.apache.pdfbox.pdmodel.interactive.form PDCheckBox PDTextField) (org.apache.pdfbox.pdmodel PDPage PDDocument PDPageContentStream PDResources) - (org.apache.pdfbox.pdmodel.graphics.image PDImageXObject) - (java.io ByteArrayOutputStream ByteArrayInputStream) (org.apache.pdfbox.pdmodel.graphics.image JPEGFactory LosslessFactory) (org.apache.pdfbox.pdmodel.font PDType1Font PDFont PDType0Font) - (org.eclipse.jetty.server.handler.gzip GzipHandler) (javax.imageio ImageIO) (java.net URL))) @@ -52,7 +49,7 @@ (instance? PDCheckBox field) (if v "Yes" "Off") (instance? PDTextField field) (str v) :else nil)))) - (catch Exception e (prn "failed writing field: " k v (clojure.stacktrace/print-stack-trace e))))) + (catch Exception e (prn "failed writing field: " k v (strace/print-stack-trace e))))) (when flatten (.setNeedAppearances form false) (.flatten form)))) @@ -150,7 +147,7 @@ (defn draw-lines-to-box [cs lines font font-size x y height] (let [leading (* font-size 1.1) - max-lines (- (/ (* 72 height) leading) 1) + max-lines (dec (/ (* 72 height) leading)) units-x (* 72 x) units-y (* 72 y) fitting-lines (vec (take max-lines lines))] @@ -356,131 +353,128 @@ :let [spell-index (+ i (* j num-boxes-x))]] (if-let [{:keys [class-nm dc attack-bonus spell] :as spell-data} (get (vec spells) spell-index)] - (do - (if spell - (do - (let [{:keys [description - casting-time - duration - level - ritual - range]} spell - x (+ margin-x (* box-width i)) - y (+ margin-y (* box-height j)) - - {:keys [page source description summary components]} spell - - dc-str (str "DC " dc) - remaining-desc-lines - (draw-text-to-box cs - (or description - (if summary - (str summary - " (see " - (if source - (s/upper-case (name source)) - "PHB") - " " - page - " for more details)") - "")) - (:plain fonts) - 8 - (+ x 0.12) ; from the left - (- 11.0 y 1.08) ;from the top down - (- box-width 0.24) - (- box-height 1.13))] - (if (-> components :material-component) - (draw-text-to-box cs - (str (s/capitalize (-> components :material-component))) - (:italic fonts) - 8 - (+ x 0.12) - (- 11.0 y 0.55) - (- box-width 0.24) - 0.5)) - (draw-imagex cs - card-logo-img - (+ x 1.9) - (+ y 0.02) - 1.0 + (let [{:keys [description + casting-time + duration + level + ritual + range]} spell + x (+ margin-x (* box-width i)) + y (+ margin-y (* box-height j)) + + {:keys [page source description summary components]} spell + + dc-str (str "DC " dc) + remaining-desc-lines + (draw-text-to-box cs + (or description + (if summary + (str summary + " (see " + (if source + (s/upper-case (name source)) + "PHB") + " " + page + " for more details)") + "")) + (:plain fonts) + 8 + (+ x 0.12) ; from the left + (- 11.0 y 1.08) ;from the top down + (- box-width 0.24) + (- box-height 1.13))] + (if (:material-component components) + (draw-text-to-box cs + (str (s/capitalize (:material-component components))) + (:italic fonts) + 8 + (+ x 0.12) + (- 11.0 y 0.55) + (- box-width 0.24) + 0.5)) + (draw-imagex cs + card-logo-img + (+ x 1.9) + (+ y 0.02) + 1.0 + 0.25) + (draw-text-to-box cs + (:name spell) + (:bold fonts) + 10 + (+ x 0.12) + (- 11.0 y) + (- box-width 0.3) + 0.2) + (draw-text-to-box cs + (if ritual " (ritual)" "") + (:italic fonts) + 10 + (+ x 0.12 (string-width (:name spell) (:bold fonts) 10)) + (- 11.0 y) + (- box-width 0.3) + 0.2) + (draw-text-to-box cs + (if (not= class-nm "Homebrew") + (str (spell-school-level spell class-nm) " " dc-str (str " Spell Mod " (common/bonus-str attack-bonus))) + (spell-school-level spell class-nm)) + (:italic fonts) + 8 + (+ x 0.12) + (- 11.0 y 0.19) + (- box-width 0.24) 0.25) - (draw-text-to-box cs - (:name spell) - (:bold fonts) - 10 - (+ x 0.12) - (- 11.0 y) - (- box-width 0.3) - 0.2) - (draw-text-to-box cs - (if ritual " (ritual)" "") - (:italic fonts) - 10 - (+ x 0.12 (string-width (:name spell) (:bold fonts) 10)) - (- 11.0 y) - (- box-width 0.3) - 0.2) - (draw-text-to-box cs - (if (not= class-nm "Homebrew") - (str (spell-school-level spell class-nm) " " dc-str (str " Spell Mod " (common/bonus-str attack-bonus))) - (spell-school-level spell class-nm)) - (:italic fonts) - 8 - (+ x 0.12) - (- 11.0 y 0.19) - (- box-width 0.24) - 0.25) - (if casting-time - (draw-spell-field cs - document - "magic-swirl" - (str (abbreviate-casting-time - (first - (s/split - casting-time - #",")))) - (+ x 0.12) - (- 11.0 y 0.45))) - (if range - (draw-spell-field cs - document - "arrow-dunk" - (abbreviate-range range) - (+ x 0.62) - (- 11.0 y 0.45))) - (draw-spell-field cs - document - "shiny-purse" - (s/join - "," - (remove - nil? - (map - (fn [[k v]] - (if (-> spell :components k) - v)) - {:verbal "V" - :somatic "S" - :material "M"}))) - (+ x 1.12) - (- 11.0 y 0.45)) - (if duration - (draw-spell-field cs - document - "sands-of-time" - (abbreviate-duration duration) - (+ x 1.62) - (- 11.0 y 0.45))) - (if (seq remaining-desc-lines) - (draw-imagex cs - over-img - (+ x 2.3) - (+ y 3.3) - 0.15 - 0.15)) - {:remaining-lines remaining-desc-lines - :spell-name (:name spell)}))))))))))) + (if casting-time + (draw-spell-field cs + document + "magic-swirl" + (str (abbreviate-casting-time + (first + (s/split + casting-time + #",")))) + (+ x 0.12) + (- 11.0 y 0.45))) + (if range + (draw-spell-field cs + document + "arrow-dunk" + (abbreviate-range range) + (+ x 0.62) + (- 11.0 y 0.45))) + (draw-spell-field cs + document + "shiny-purse" + (s/join + "," + (remove + nil? + (map + (fn [[k v]] + (if (-> spell :components k) + v)) + {:verbal "V" + :somatic "S" + :material "M"}))) + (+ x 1.12) + (- 11.0 y 0.45)) + (if duration + (draw-spell-field cs + document + "sands-of-time" + (abbreviate-duration duration) + (+ x 1.62) + (- 11.0 y 0.45))) + (if (seq remaining-desc-lines) + (draw-imagex cs + over-img + (+ x 2.3) + (+ y 3.3) + 0.15 + 0.15)) + {:remaining-lines remaining-desc-lines + :spell-name (:name spell)})))))))) (defn create-monsters-pdf [] (let [page (PDPage.) @@ -494,63 +488,63 @@ (doseq [i (range 0 5)] (let [monster (monsters i)] (draw-text-from-top cs - (:name monster) - PDType1Font/HELVETICA_BOLD - 14 - 0.1 - (+ (* i h) 0.25)) + (:name monster) + PDType1Font/HELVETICA_BOLD + 14 + 0.1 + (+ (* i h) 0.25)) (draw-text-from-top cs - (monsters/monster-subheader monster) - PDType1Font/HELVETICA_OBLIQUE - 12 - 0.1 - (+ (* i h) 0.45)) + (monsters/monster-subheader monster) + PDType1Font/HELVETICA_OBLIQUE + 12 + 0.1 + (+ (* i h) 0.45)) (doseq [j (range 0 6)] (let [ability ([:str :dex :con :int :wis :cha] j) x (+ 0.15 (* 0.65 j))] (draw-text-from-top cs - (name ability) - PDType1Font/HELVETICA_BOLD - 10 - x - (+ (* i h) 0.7)) - (draw-text-from-top cs - (str (ability monster) - " (" - (options/ability-bonus-str (ability monster)) - ")") - PDType1Font/HELVETICA - 12 - x - (+ (* i h) 0.85)))) - (draw-text-from-top cs - "Saving Throws" + (name ability) PDType1Font/HELVETICA_BOLD 10 - 0.1 - (+ (* i h) 1.1)) - (draw-text-from-top cs - (common/print-bonus-map (:saving-throws monster)) + x + (+ (* i h) 0.7)) + (draw-text-from-top cs + (str (ability monster) + " (" + (options/ability-bonus-str (ability monster)) + ")") PDType1Font/HELVETICA - 10 - (+ 0.1 (string-width - "Saving Throws " - PDType1Font/HELVETICA_BOLD - 10)) - (+ (* i h) 1.1)) + 12 + x + (+ (* i h) 0.85)))) (draw-text-from-top cs - "Skills" - PDType1Font/HELVETICA_BOLD - 10 - 0.1 - (+ (* i h) 1.3)) + "Saving Throws" + PDType1Font/HELVETICA_BOLD + 10 + 0.1 + (+ (* i h) 1.1)) (draw-text-from-top cs - (common/print-bonus-map (:skills monster)) - PDType1Font/HELVETICA - 10 - (+ 0.1 (string-width - "Skills " - PDType1Font/HELVETICA_BOLD - 10)) - (+ (* i h) 1.3))))))) + (common/print-bonus-map (:saving-throws monster)) + PDType1Font/HELVETICA + 10 + (+ 0.1 (string-width + "Saving Throws " + PDType1Font/HELVETICA_BOLD + 10)) + (+ (* i h) 1.1)) + (draw-text-from-top cs + "Skills" + PDType1Font/HELVETICA_BOLD + 10 + 0.1 + (+ (* i h) 1.3)) + (draw-text-from-top cs + (common/print-bonus-map (:skills monster)) + PDType1Font/HELVETICA + 10 + (+ 0.1 (string-width + "Skills " + PDType1Font/HELVETICA_BOLD + 10)) + (+ (* i h) 1.3))))))) (.save doc "/home/larry/Documents/test.pdf"))) \ No newline at end of file diff --git a/src/clj/orcpub/pedestal.clj b/src/clj/orcpub/pedestal.clj index f8c40525c..4e6733e85 100644 --- a/src/clj/orcpub/pedestal.clj +++ b/src/clj/orcpub/pedestal.clj @@ -1,8 +1,7 @@ (ns orcpub.pedestal (:require [com.stuartsierra.component :as component] [io.pedestal.http :as http] - [pandect.algo.sha1 :refer :all] - [ring.middleware.etag :refer [wrap-etag]] + [pandect.algo.sha1 :refer [sha1]] [datomic.api :as d] [clojure.string :as s] [clj-time.format :as tf] @@ -16,9 +15,9 @@ (defn db-interceptor [conn] {:name :db-interceptor :enter (fn [context] - (let [conn (:conn conn)] - (let [db (d/db conn)] - (update context :request assoc :db db :conn conn))))}) + (let [conn (:conn conn) + db (d/db conn)] + (update context :request assoc :db db :conn conn)))}) (defmulti calculate-etag class) diff --git a/src/clj/orcpub/routes.clj b/src/clj/orcpub/routes.clj index 24dc10f0a..09f694c1a 100644 --- a/src/clj/orcpub/routes.clj +++ b/src/clj/orcpub/routes.clj @@ -3,10 +3,8 @@ [io.pedestal.http.route :as route] [io.pedestal.test :as test] [io.pedestal.http.ring-middlewares :as ring] - [ring.middleware.cookies :only [wrap-cookies]] [ring.middleware.resource :as ring-resource] [ring.util.response :as ring-resp] - [ring.middleware.etag :refer [wrap-etag]] [io.pedestal.http.body-params :as body-params] [io.pedestal.interceptor.error :as error-int] [io.pedestal.interceptor.chain :refer [terminate]] @@ -16,12 +14,13 @@ [buddy.sign.jwt :as jwt] [buddy.hashers :as hashers] [buddy.auth.middleware :refer [authentication-request]] - [pandect.algo.sha1 :refer [sha1]] + [clojure.edn :as edn] [clojure.java.io :as io] [clj-time.core :as t :refer [hours from-now ago]] [clj-time.coerce :as tc :refer [from-date]] [clojure.string :as s] [clojure.spec.alpha :as spec] + [clojure.pprint] [orcpub.dnd.e5.skills :as skill5e] [orcpub.dnd.e5.character :as char5e] [orcpub.dnd.e5.spells :as spells] @@ -45,15 +44,8 @@ [hiccup.page :as page] [environ.core :as environ] [clojure.set :as sets]) - (:import (org.apache.pdfbox.pdmodel.interactive.form PDCheckBox PDComboBox PDListBox PDRadioButton PDTextField) - - (org.apache.pdfbox.pdmodel PDDocument PDPage PDPageContentStream) - (org.apache.pdfbox.pdmodel.graphics.image PDImageXObject) - (java.io ByteArrayOutputStream ByteArrayInputStream) - (org.apache.pdfbox.pdmodel.graphics.image JPEGFactory LosslessFactory) - (org.eclipse.jetty.server.handler.gzip GzipHandler) - (javax.imageio ImageIO) - (java.net URL)) + (:import (org.apache.pdfbox.pdmodel PDDocument PDPage PDPageContentStream) + (java.io ByteArrayOutputStream ByteArrayInputStream)) (:gen-class)) (deftype FixedBuffer [^long len]) @@ -233,7 +225,7 @@ (try (let [resp (login-response request)] resp) - (catch Throwable e (do (prn "E" e) (throw e))))) + (catch Throwable e (prn "E" e) (throw e)))) (defn user-for-email [db email] @@ -258,15 +250,15 @@ (defn do-verification [request params conn & [tx-data]] (let [verification-key (str (java.util.UUID/randomUUID)) now (java.util.Date.)] - (do @(d/transact - conn - [(merge - tx-data - {:orcpub.user/verified? false - :orcpub.user/verification-key verification-key - :orcpub.user/verification-sent now})]) - (send-verification-email request params verification-key) - {:status 200}))) + @(d/transact + conn + [(merge + tx-data + {:orcpub.user/verified? false + :orcpub.user/verification-key verification-key + :orcpub.user/verification-sent now})]) + (send-verification-email request params verification-key) + {:status 200})) (defn register [{:keys [json-params db conn] :as request}] (let [{:keys [username email password send-updates?]} json-params @@ -290,7 +282,7 @@ :orcpub.user/password (hashers/encrypt password) :orcpub.user/send-updates? send-updates? :orcpub.user/created (java.util.Date.)})) - (catch Throwable e (do (prn e) (throw e)))))) + (catch Throwable e (prn e) (throw e))))) (def user-for-verification-key-query '[:find ?e @@ -375,7 +367,7 @@ (if id (do-send-password-reset id email conn request) {:status 400 :body {:error :no-account}})) - (catch Throwable e (do (prn e) (throw e))))) + (catch Throwable e (prn e) (throw e)))) (defn do-password-reset [conn user-id password] @(d/transact @@ -395,7 +387,7 @@ (not= password verify-password) {:status 400 :message "Passwords do not match"} (seq (registration/validate-password password)) {:status 400 :message "New password is invalid"} :else (do-password-reset conn id password))) - (catch Throwable t (do (prn t) (throw t))))) + (catch Throwable t (prn t) (throw t)))) (def font-sizes (merge @@ -457,7 +449,7 @@ (catch Exception e (prn "FAILED ADDING SPELLS CARDS!" e)))) (defn character-pdf-2 [req] - (let [fields (-> req :form-params :body clojure.edn/read-string) + (let [fields (-> req :form-params :body edn/read-string) {:keys [image-url image-url-failed faction-image-url faction-image-url-failed spells-known custom-spells spell-save-dcs spell-attack-mods print-spell-cards?]} fields input (.openStream (io/resource (cond (find fields :spellcasting-class-6) "fillable-char-sheet-6-spells.pdf" @@ -653,12 +645,13 @@ (let [current-character (d/pull db '[*] id) problems [] #_(dnd-e5-char-type-problems current-character) current-valid? (spec/valid? ::se/entity current-character)] - (if (not current-valid?) - (do (prn "INVALID CHARACTER FOUND, REPLACING" #_current-character) - (prn "INVALID CHARACTER EXPLANATION" #_(spec/explain-data ::se/entity current-character)))) + (when-not current-valid? + (prn "INVALID CHARACTER FOUND, REPLACING" #_current-character) + (prn "INVALID CHARACTER EXPLANATION" #_(spec/explain-data ::se/entity current-character))) (if (seq problems) - {:status 400 :body problems} - (if (not current-valid?) + (throw (ex-info "Character has problems" + {:error :character-problems :problems problems})) + (if-not current-valid? (let [new-character (entity/remove-ids character) tx [[:db/retractEntity (:db/id current-character)] (-> new-character @@ -666,8 +659,7 @@ :orcpub.entity.strict/owner username) add-dnd-5e-character-tags)] result @(d/transact conn tx)] - {:status 200 - :body (d/pull (d/db conn) '[*] (-> result :tempids (get "tempid")))}) + (d/pull (d/db conn) '[*] (-> result :tempids (get "tempid")))) (let [new-character (entity/remove-orphan-ids character) current-ids (entity/db-ids current-character) new-ids (entity/db-ids new-character) @@ -681,9 +673,9 @@ (assoc :orcpub.entity.strict/owner username) add-dnd-5e-character-tags))] @(d/transact conn tx) - {:status 200 - :body (d/pull (d/db conn) '[*] id)})))) - {:status 401 :body "You do not own this character"}))) + (d/pull (d/db conn) '[*] id))))) + (throw (ex-info "Not user character" + {:error :not-user-character}))))) (defn create-new-character [conn character username] (let [result @(d/transact conn @@ -692,15 +684,14 @@ ::se/owner username) add-dnd-5e-character-tags)]) new-id (get-new-id "tempid" result)] - {:status 200 - :body (d/pull (d/db conn) '[*] new-id)})) + (d/pull (d/db conn) '[*] new-id))) (defn clean-up-character [character] (if (-> character ::se/values ::char5e/xps string?) (update-in character [::se/values ::char5e/xps] #(try - (if (not (s/blank? %)) + (if-not (s/blank? %) (Long/parseLong %) 0) (catch NumberFormatException e 0))) @@ -713,11 +704,17 @@ (try (if-let [data (spec/explain-data ::se/entity character)] {:status 400 :body data} - (let [clean-character (clean-up-character character)] - (if (:db/id clean-character) - (update-character db conn clean-character username) - (create-new-character conn clean-character username)))) - (catch Exception e (do (prn "ERROR" e) (throw e)))))) + (let [clean-character (clean-up-character character) + updated-character (if (:db/id clean-character) + (update-character db conn clean-character username) + (create-new-character conn clean-character username))] + {:status 200 :body updated-character})) + (catch clojure.lang.ExceptionInfo e + (let [data (ex-data e)] + (case (:error data) + :character-problems {:status 400 :body (:problems data)} + :not-user-character {:status 401 :body "You do not own this character"}))) + (catch Exception e (prn "ERROR" e) (throw e))))) (defn save-character [{:keys [db transit-params body conn identity] :as request}] (do-save-character db conn transit-params identity)) @@ -956,8 +953,7 @@ (def expanded-index-routes (route/expand-routes - (into #{} index-page-routes))) - + (set index-page-routes))) (def service-error-handler (error-int/error-dispatch [ctx ex] diff --git a/src/clj/orcpub/security.clj b/src/clj/orcpub/security.clj index c6d7c3696..ef64384d9 100644 --- a/src/clj/orcpub/security.clj +++ b/src/clj/orcpub/security.clj @@ -1,5 +1,5 @@ (ns orcpub.security - (:require [clj-time.core :as t :refer [ago now minutes hours]])) + (:require [clj-time.core :as t :refer [ago minutes]])) (defn compare-dates [attempt-1 attempt-2] (compare (:date attempt-1) (:date attempt-2))) @@ -54,10 +54,10 @@ @failed-login-attempts-by-username)) (defn usernames-for-attempts [attempts] - (into #{} (map :user attempts))) + (set (map :user attempts))) (defn ips-for-attempts [attempts] - (into #{} (map :ip attempts))) + (set (map :ip attempts))) (defn multiple-account-access-aux [ip attempts-by-ip] (some-> ip diff --git a/src/clj/orcpub/styles/core.clj b/src/clj/orcpub/styles/core.clj index 81d64d01e..34dbea4cb 100644 --- a/src/clj/orcpub/styles/core.clj +++ b/src/clj/orcpub/styles/core.clj @@ -1,6 +1,5 @@ (ns orcpub.styles.core - (:require [garden.def :refer [defstylesheet defstyles]] - [garden.stylesheet :refer [at-media at-keyframes]] + (:require [garden.stylesheet :refer [at-media at-keyframes]] [garden.units :refer [px]] [orcpub.constants :as const] [garden.selectors :as s])) diff --git a/src/clj/orcpub/system.clj b/src/clj/orcpub/system.clj index 169af70b7..f170f6eb2 100644 --- a/src/clj/orcpub/system.clj +++ b/src/clj/orcpub/system.clj @@ -1,6 +1,6 @@ (ns orcpub.system (:require [com.stuartsierra.component :as component] - [reloaded.repl :refer [init start stop go reset]] + [reloaded.repl :as rrepl] [io.pedestal.http :as http] [orcpub.pedestal :as pedestal] [orcpub.routes :as routes] @@ -53,4 +53,4 @@ (pedestal/new-pedestal) [:service-map :conn]))) -(reloaded.repl/set-init! #(system :prod)) +(rrepl/set-init! #(system :prod)) diff --git a/src/cljc/orcpub/components.cljc b/src/cljc/orcpub/components.cljc index a9bb3d7bf..a2c99c4e3 100644 --- a/src/cljc/orcpub/components.cljc +++ b/src/cljc/orcpub/components.cljc @@ -1,6 +1,5 @@ (ns orcpub.components - (:require [re-frame.core :refer [dispatch]] - [clojure.string :as s] + (:require [clojure.string :as s] #?(:cljs [reagent.core :refer [atom]]))) (defn checkbox [selected? disable?] diff --git a/src/cljc/orcpub/dice.cljc b/src/cljc/orcpub/dice.cljc index a9b1bc95b..a9ea7fb53 100644 --- a/src/cljc/orcpub/dice.cljc +++ b/src/cljc/orcpub/dice.cljc @@ -8,7 +8,7 @@ (inc (rand-int sides))) (defn roll-n [num sides] - (take num (repeatedly #(die-roll sides)))) + (repeatedly num #(die-roll sides))) (defn dice-roll [{:keys [num sides drop-num modifier]}] (apply + diff --git a/src/cljc/orcpub/dnd/e5/character/random.cljc b/src/cljc/orcpub/dnd/e5/character/random.cljc index 33949b9e9..13f8a4227 100644 --- a/src/cljc/orcpub/dnd/e5/character/random.cljc +++ b/src/cljc/orcpub/dnd/e5/character/random.cljc @@ -1643,7 +1643,7 @@ (def sexes [::male ::female]) -(def sexes-set (into #{} sexes)) +(def sexes-set (set sexes)) (def human-subraces [::calishite @@ -1655,7 +1655,7 @@ ::rashemi ::mulan]) -(def subraces-set (into #{} human-subraces)) +(def subraces-set (set human-subraces)) (def races [::elf @@ -1665,7 +1665,7 @@ ::human ::human]) -(def races-set (into #{} races)) +(def races-set (set races)) (defn random-sex [] (rand-nth sexes)) @@ -1788,7 +1788,7 @@ (set-name mulan-names ::female))) (def human-subraces-set - (into #{} human-subraces)) + (set human-subraces)) (def races-and-subraces (concat (vec human-subraces) diff --git a/src/cljc/orcpub/dnd/e5/classes.cljc b/src/cljc/orcpub/dnd/e5/classes.cljc index 522ad4d91..53524117a 100644 --- a/src/cljc/orcpub/dnd/e5/classes.cljc +++ b/src/cljc/orcpub/dnd/e5/classes.cljc @@ -13,7 +13,7 @@ [orcpub.dnd.e5.spells :as spells5e] [orcpub.dnd.e5.spell-lists :as sl5e] [orcpub.dnd.e5.template-base :as t-base] - [re-frame.core :refer [reg-sub reg-sub-raw dispatch subscribe]] + [re-frame.core :refer [subscribe]] [clojure.string :as s])) (spec/def ::name (spec/and string? common/starts-with-letter?)) @@ -1659,8 +1659,8 @@ (defn favored-enemy-option [language-map [enemy-type info]] (let [vec-info? (sequential? info) languages (if vec-info? info (:languages info)) - name (if vec-info? (common/kw-to-name enemy-type) (:name info))] - (let [language-options (zipmap languages (repeat true))] + name (if vec-info? (common/kw-to-name enemy-type) (:name info)) + language-options (zipmap languages (repeat true))] (t/option-cfg {:name name :selections (if (> (count languages) 1) @@ -1672,7 +1672,7 @@ nil? [(if (= 1 (count languages)) (mod5e/language (first languages))) - (mod/set-mod ?ranger-favored-enemies enemy-type)])})))) + (mod/set-mod ?ranger-favored-enemies enemy-type)])}))) (defn favored-enemy-selection [language-map order] (t/selection-cfg diff --git a/src/cljc/orcpub/dnd/e5/magic_items.cljc b/src/cljc/orcpub/dnd/e5/magic_items.cljc index 9db954dcb..941f540f7 100644 --- a/src/cljc/orcpub/dnd/e5/magic_items.cljc +++ b/src/cljc/orcpub/dnd/e5/magic_items.cljc @@ -3,7 +3,6 @@ [orcpub.common :as common] [orcpub.modifiers :as mod] [orcpub.entity :as entity] - [orcpub.dnd.e5.weapons :as weapons] [orcpub.dnd.e5.armor :as armor5e] [orcpub.dnd.e5.weapons :as weapons5e] [orcpub.dnd.e5.equipment :as equip5e] @@ -2914,8 +2913,8 @@ The boots regain 2 hours of flying capability for every 12 hours they aren’t i (def weapons-and-ammunition (concat - weapons/weapons - weapons/ammunition)) + weapons5e/weapons + weapons5e/ammunition)) (defn add-key [item] (assoc item :key (common/name-to-kw (name-key item)))) @@ -2931,7 +2930,7 @@ The boots regain 2 hours of flying capability for every 12 hours they aren’t i (types type))) (defn subtypes-fn [subtypes] - (fn [{:keys [::weapons/subtype]}] + (fn [{:keys [::weapons5e/subtype]}] (subtypes subtype))) (defn keys-fn [keys] @@ -3059,7 +3058,7 @@ The boots regain 2 hours of flying capability for every 12 hours they aren’t i (def all-weapons-map (merge - weapons/weapons-map + weapons5e/weapons-map magic-weapon-map)) (def magic-armor-xform diff --git a/src/cljc/orcpub/dnd/e5/options.cljc b/src/cljc/orcpub/dnd/e5/options.cljc index 5499f006e..a867e3e97 100644 --- a/src/cljc/orcpub/dnd/e5/options.cljc +++ b/src/cljc/orcpub/dnd/e5/options.cljc @@ -603,8 +603,8 @@ all-spells (select-keys (or spells (spell-lists (or spell-list-kw class-key))) (keys slots)) - acquire? (= :acquire known-mode)] - (let [options (flatten + acquire? (= :acquire known-mode) + options (flatten (map (fn [[lvl spell-keys]] (let [spell-keys (vec spell-keys) @@ -634,7 +634,7 @@ :class-name cls-nm :min num :max (if (not acquire?) num) - :options options}))])))) + :options options}))]))) {} spells-known)) diff --git a/src/cljc/orcpub/dnd/e5/selections.cljc b/src/cljc/orcpub/dnd/e5/selections.cljc index 348953b5c..2d2820256 100644 --- a/src/cljc/orcpub/dnd/e5/selections.cljc +++ b/src/cljc/orcpub/dnd/e5/selections.cljc @@ -13,7 +13,6 @@ [orcpub.dnd.e5.spells :as spells5e] [orcpub.dnd.e5.spell-lists :as sl5e] [orcpub.dnd.e5.template-base :as t-base] - [re-frame.core :refer [reg-sub reg-sub-raw dispatch subscribe]] [clojure.string :as s])) (spec/def ::name (spec/and string? common/starts-with-letter?)) diff --git a/src/cljc/orcpub/dnd/e5/templates/scag.cljc b/src/cljc/orcpub/dnd/e5/templates/scag.cljc index e10e3bee1..86dc1ac48 100644 --- a/src/cljc/orcpub/dnd/e5/templates/scag.cljc +++ b/src/cljc/orcpub/dnd/e5/templates/scag.cljc @@ -10,7 +10,7 @@ [orcpub.dnd.e5.equipment :as equip5e] [orcpub.dnd.e5.spell-lists :as sl] [orcpub.dnd.e5.options :as opt5e] - [re-frame.core :refer [subscribe]])) + #_[re-frame.core :refer [subscribe]])) #_(def scag-barbarian {:name "Barbarian" diff --git a/src/cljc/orcpub/dnd/e5/templates/ua_feats.cljc b/src/cljc/orcpub/dnd/e5/templates/ua_feats.cljc index ef411a2f6..e02b71f26 100644 --- a/src/cljc/orcpub/dnd/e5/templates/ua_feats.cljc +++ b/src/cljc/orcpub/dnd/e5/templates/ua_feats.cljc @@ -4,7 +4,7 @@ [orcpub.dnd.e5.character :as char5e] [orcpub.template :as t] [orcpub.common :as common] - [re-frame.core :refer [subscribe]] + #_[re-frame.core :refer [subscribe]] [clojure.string :as s])) #_(defn weapon-attack-bonus-mod [weapons bonus] diff --git a/src/cljc/orcpub/dnd/e5/templates/ua_race_feats.cljc b/src/cljc/orcpub/dnd/e5/templates/ua_race_feats.cljc index 896ceae12..45c12af54 100644 --- a/src/cljc/orcpub/dnd/e5/templates/ua_race_feats.cljc +++ b/src/cljc/orcpub/dnd/e5/templates/ua_race_feats.cljc @@ -5,7 +5,7 @@ [orcpub.dnd.e5.units :as units5e] [orcpub.template :as t] [orcpub.common :as common] - [re-frame.core :refer [subscribe]] + #_[re-frame.core :refer [subscribe]] [clojure.string :as s])) #_(def grudge-bearer-foe-selection diff --git a/src/cljc/orcpub/dnd/e5/templates/ua_revised_ranger.cljc b/src/cljc/orcpub/dnd/e5/templates/ua_revised_ranger.cljc index 33b358f49..f1fd28945 100644 --- a/src/cljc/orcpub/dnd/e5/templates/ua_revised_ranger.cljc +++ b/src/cljc/orcpub/dnd/e5/templates/ua_revised_ranger.cljc @@ -7,7 +7,7 @@ [orcpub.template :as t] [orcpub.common :as common] [clojure.string :as s] - [re-frame.core :refer [subscribe]])) + #_[re-frame.core :refer [subscribe]])) #_(defn favored-enemy-selection [name types] (t/selection-cfg diff --git a/src/cljc/orcpub/dnd/e5/templates/ua_skill_feats.cljc b/src/cljc/orcpub/dnd/e5/templates/ua_skill_feats.cljc index f70c23376..37c8fd77b 100644 --- a/src/cljc/orcpub/dnd/e5/templates/ua_skill_feats.cljc +++ b/src/cljc/orcpub/dnd/e5/templates/ua_skill_feats.cljc @@ -4,7 +4,7 @@ [orcpub.dnd.e5.character :as char5e] [orcpub.template :as t] [orcpub.common :as common] - [re-frame.core :refer [subscribe]] + #_[re-frame.core :refer [subscribe]] [clojure.string :as s])) #_(def action #(mod5e/action %)) diff --git a/src/cljc/orcpub/dnd/e5/templates/ua_warlock_and_wizard.cljc b/src/cljc/orcpub/dnd/e5/templates/ua_warlock_and_wizard.cljc index e9bdd40c6..ce9da9808 100644 --- a/src/cljc/orcpub/dnd/e5/templates/ua_warlock_and_wizard.cljc +++ b/src/cljc/orcpub/dnd/e5/templates/ua_warlock_and_wizard.cljc @@ -6,7 +6,7 @@ [orcpub.dnd.e5.units :as units5e] [orcpub.modifiers :as mod] [orcpub.template :as t] - [re-frame.core :refer [subscribe]])) + #_[re-frame.core :refer [subscribe]])) #_(def warlock-option-cfg diff --git a/src/cljc/orcpub/dnd/e5/views_2.cljc b/src/cljc/orcpub/dnd/e5/views_2.cljc index 1cabd4b44..a59e6fdb3 100644 --- a/src/cljc/orcpub/dnd/e5/views_2.cljc +++ b/src/cljc/orcpub/dnd/e5/views_2.cljc @@ -1,7 +1,6 @@ (ns orcpub.dnd.e5.views-2 (:require [orcpub.route-map :as routes] - [clojure.string :as s] - #?(:cljs [re-frame.core :refer [subscribe dispatch dispatch-sync]]))) + [clojure.string :as s])) (defn style [style] #?(:cljs style) diff --git a/src/cljc/orcpub/entity.cljc b/src/cljc/orcpub/entity.cljc index be83c6514..571f7dcdd 100644 --- a/src/cljc/orcpub/entity.cljc +++ b/src/cljc/orcpub/entity.cljc @@ -6,6 +6,7 @@ [orcpub.entity-spec :as es] [orcpub.template :as t] [orcpub.entity.strict :as strict] + [clojure.string :as s] [clojure.set :refer [difference union intersection]])) (spec/def ::key ::strict/key) @@ -229,7 +230,7 @@ (defn take-1 "Returns the pair [element, s'] where s' is set s with element removed." - [s] {:pre [(not (empty? s))]} + [s] {:pre [(seq s)]} (let [item (first s)] [item (without s item)])) @@ -694,8 +695,8 @@ (defn name-to-kw [name] (-> name - clojure.string/lower-case - (clojure.string/replace #"\W" "-") + s/lower-case + (s/replace #"\W" "-") keyword)) (defn get-option-value-path [template entity path] diff --git a/src/cljc/orcpub/route_map.cljc b/src/cljc/orcpub/route_map.cljc index 22a11778b..ba34805b0 100644 --- a/src/cljc/orcpub/route_map.cljc +++ b/src/cljc/orcpub/route_map.cljc @@ -190,4 +190,4 @@ (apply bidi/path-for routes args)) (defn match-route [path] - (->> path (bidi/match-route routes))) + (bidi/match-route routes path)) diff --git a/src/cljs/orcpub/character_builder.cljs b/src/cljs/orcpub/character_builder.cljs index 52f264f1e..5b3ffb055 100644 --- a/src/cljs/orcpub/character_builder.cljs +++ b/src/cljs/orcpub/character_builder.cljs @@ -33,21 +33,18 @@ [orcpub.dnd.e5.equipment :as equip5e] [orcpub.dnd.e5.skills :as skill5e] [orcpub.dnd.e5.events :as events5e] - [orcpub.dnd.e5.db :as db5e] + [orcpub.dnd.e5.db :as db] [orcpub.dnd.e5.views :as views5e] [orcpub.route-map :as routes] [orcpub.pdf-spec :as pdf-spec] [orcpub.user-agent :as user-agent] - [orcpub.dnd.e5.db :as db] [clojure.spec.alpha :as spec] [clojure.spec.test.alpha :as stest] - [cljs.core.async :refer [ num-resources 1) has-homebrew? @(subscribe [:has-homebrew?]) mobile? @(subscribe [:mobile?]) diff --git a/src/cljs/orcpub/dnd/e5/db.cljs b/src/cljs/orcpub/dnd/e5/db.cljs index 435499cf3..a3613ecf7 100644 --- a/src/cljs/orcpub/dnd/e5/db.cljs +++ b/src/cljs/orcpub/dnd/e5/db.cljs @@ -49,9 +49,8 @@ (defn parse-route [] (let [route (if js/window.location (bidi/match-route route-map/routes js/window.location.pathname))] - (if route - route - default-route))) + (or route + default-route))) (def default-character (char5e/set-class t5e/character :barbarian 0 (class5e/barbarian-option nil nil nil nil nil))) @@ -229,9 +228,9 @@ (if-let [stored-str (if js/window.localStorage (.getItem js/window.localStorage local-storage-key))] (try (reader/read-string stored-str) - (catch js/Object e (do (prn "E" e) - (js/console.warn "UNREADABLE ITEM FOUND, REMOVING.." local-storage-key stored-str) - (.removeItem js/window.localStorage local-storage-key)))))) + (catch js/Object e (prn "E" e) + (js/console.warn "UNREADABLE ITEM FOUND, REMOVING.." local-storage-key stored-str) + (.removeItem js/window.localStorage local-storage-key))))) (defn reg-local-store-cofx [key local-storage-key item-spec & [item-fn]] (re-frame/reg-cofx diff --git a/src/cljs/orcpub/dnd/e5/equipment_subs.cljs b/src/cljs/orcpub/dnd/e5/equipment_subs.cljs index dac80f98c..32e6deb75 100644 --- a/src/cljs/orcpub/dnd/e5/equipment_subs.cljs +++ b/src/cljs/orcpub/dnd/e5/equipment_subs.cljs @@ -41,7 +41,7 @@ {:headers (auth-headers @app-db)}))] (dispatch [:set-loading false]) (case (:status response) - 200 (dispatch [::mi5e/set-custom-items (-> response :body)]) + 200 (dispatch [::mi5e/set-custom-items (:body response)]) 401 nil ;;(dispatch [:route routes/login-page-route {:secure? true}]) 500 (dispatch (events/show-generic-error))))) (ra/make-reaction @@ -251,7 +251,7 @@ {:headers (auth-headers @app-db)}))] (dispatch [:set-loading false]) (case (:status response) - 200 (dispatch [::mi5e/add-remote-item (-> response :body)]) + 200 (dispatch [::mi5e/add-remote-item (:body response)]) 500 (dispatch (events/show-generic-error))))) (ra/make-reaction (fn [] (get-in @app-db [::mi5e/remote-items id] {}))))) diff --git a/src/cljs/orcpub/dnd/e5/events.cljs b/src/cljs/orcpub/dnd/e5/events.cljs index de09a3b0e..c0b83a856 100644 --- a/src/cljs/orcpub/dnd/e5/events.cljs +++ b/src/cljs/orcpub/dnd/e5/events.cljs @@ -63,8 +63,8 @@ default-class default-subclass]] [orcpub.dnd.e5.autosave-fx] - [re-frame.core :refer [reg-event-db reg-event-fx reg-fx inject-cofx path trim-v - after dispatch dispatch-sync subscribe ->interceptor]] + [re-frame.core :refer [reg-event-db reg-event-fx reg-fx inject-cofx path + after dispatch subscribe ->interceptor]] [cljs.spec.alpha :as spec] [cljs-http.client :as http] [cljs.core.async :refer [= (count text) 3) + name-result (name-result search-text) + top-result (cond + dice-result {:type :dice-roll + :result dice-result} + (spells/spell-map kw) {:type :spell + :result (spells/spell-map kw)} + (monsters/monster-map kw) {:type :monster + :result (monsters/monster-map kw)} + (mi/magic-item-map kw) {:type :magic-item + :result (mi/magic-item-map kw)} + (= "tavern name" search-text) {:type :tavern-name + :result (char-rand5e/random-tavern-name)} + name-result name-result + :else nil) + filter-xform (filter-by-name-xform search-text :name) + top-spells (if (>= (count text) 3) + (sequence + filter-xform + spells/spells)) + top-monsters (if (>= (count text) 3) (sequence filter-xform - spells/spells)) - top-monsters (if (>= (count text) 3) - (sequence - filter-xform - monsters/monsters))] - (cond-> {} - top-result (assoc :top-result top-result) - (seq top-spells) (update :results conj {:type :spell - :results top-spells}) - (seq top-monsters) (update :results conj {:type :monster - :results top-monsters}))))) + monsters/monsters))] + (cond-> {} + top-result (assoc :top-result top-result) + (seq top-spells) (update :results conj {:type :spell + :results top-spells}) + (seq top-monsters) (update :results conj {:type :monster + :results top-monsters})))) (reg-event-db @@ -2075,7 +2075,7 @@ (reg-event-fx ::char5e/add-level (fn [{:keys [db]} [_ id]] - (update-character-fx db id #(add-level %)))) + (update-character-fx db id add-level))) (reg-event-fx ::char5e/level-up @@ -2405,27 +2405,27 @@ (or (first (drop-while #(>= % current-initiative) initiatives)) (first initiatives)) (second initiatives)) - round (get combat :round 1)] - (let [next-round? (and current-initiative - (> next-initiative current-initiative)) - updated (cond-> combat - true (assoc :current-initiative next-initiative) - next-round? (assoc :round (inc round)) - next-round? update-conditions) - removed-conditions (if next-round? - (filter - (comp seq :removed-conditions) - (flatten - (map - (fn [[monster-kw individuals]] - (map - (fn [[individual-index {:keys [removed-conditions]}]] - {:type :monster - :index individual-index - :name (get-in monster-map [monster-kw :name]) - :removed-conditions (map :type removed-conditions)}) - individuals)) - (:monster-data updated)))))] + round (get combat :round 1) + next-round? (and current-initiative + (> next-initiative current-initiative)) + updated (cond-> combat + true (assoc :current-initiative next-initiative) + next-round? (assoc :round (inc round)) + next-round? update-conditions) + removed-conditions (if next-round? + (filter + (comp seq :removed-conditions) + (flatten + (map + (fn [[monster-kw individuals]] + (map + (fn [[individual-index {:keys [removed-conditions]}]] + {:type :monster + :index individual-index + :name (get-in monster-map [monster-kw :name]) + :removed-conditions (map :type removed-conditions)}) + individuals)) + (:monster-data updated)))))] {:dispatch-n (cond-> [[::combat/set-combat updated]] (seq removed-conditions) (conj [:show-message @@ -2435,7 +2435,7 @@ (fn [i {:keys [name index removed-conditions]}] ^{:key i} [:div.m-b-5 (str name " #" (inc index) " is no longer " (common/list-print (map common/kw-to-name removed-conditions) "or") ".")]) - removed-conditions))]]))})))) + removed-conditions))]]))}))) (reg-event-db ::encounters/set-encounter-path-prop diff --git a/src/cljs/orcpub/dnd/e5/spell_subs.cljs b/src/cljs/orcpub/dnd/e5/spell_subs.cljs index ff91bcf1d..2014fe6a0 100644 --- a/src/cljs/orcpub/dnd/e5/spell_subs.cljs +++ b/src/cljs/orcpub/dnd/e5/spell_subs.cljs @@ -1,5 +1,5 @@ (ns orcpub.dnd.e5.spell-subs - (:require [re-frame.core :refer [reg-sub reg-sub-raw dispatch subscribe]] + (:require [re-frame.core :refer [reg-sub]] [orcpub.common :as common] [orcpub.template :as t] [orcpub.modifiers :as mod] @@ -29,9 +29,7 @@ [orcpub.dnd.e5.template-base :as t-base] [reagent.ratom :as ra] [clojure.string :as s] - [cljs-http.client :as http] - [cljs.core.async :refer [ response :body)]) + 200 (dispatch [::char5e/set-characters (:body response)]) 401 (if (not login-optional?) (dispatch [:route-to-login])) 500 (dispatch (events/show-generic-error))))) @@ -348,7 +348,7 @@ {:headers (auth-headers @app-db)}))] (dispatch [:set-loading false]) (case (:status response) - 200 (dispatch [::party5e/set-parties (-> response :body)]) + 200 (dispatch [::party5e/set-parties (:body response)]) 401 (if (not login-optional?) (dispatch [:route-to-login])) 500 (dispatch (events/show-generic-error))))) @@ -374,7 +374,7 @@ :following-users :<- [:user] (fn [user _] - (into #{} (:following user)))) + (set (:following user)))) (reg-sub ::char5e/character-map @@ -415,7 +415,7 @@ (case (:status response) 200 (dispatch [::char5e/set-character int-id - (char5e/from-strict (-> response :body))]) + (char5e/from-strict (:body response))]) 401 (dispatch [:route-to-login]) 500 (dispatch (events/show-generic-error)))))) (ra/make-reaction @@ -808,17 +808,17 @@ (reg-sub ::char5e/monster-types (fn [_ _] - (into #{} (map :type monsters5e/monsters)))) + (set (map :type monsters5e/monsters)))) (reg-sub ::char5e/monster-subtypes (fn [_ _] - (into #{} (mapcat :subtypes monsters5e/monsters)))) + (set (mapcat :subtypes monsters5e/monsters)))) (reg-sub ::char5e/monster-sizes (fn [_ _] - (into #{} (map :size monsters5e/monsters)))) + (set (map :size monsters5e/monsters)))) (reg-sub ::char5e/spell-text-filter diff --git a/src/cljs/orcpub/dnd/e5/views.cljs b/src/cljs/orcpub/dnd/e5/views.cljs index 2e497e0e2..661b3823b 100644 --- a/src/cljs/orcpub/dnd/e5/views.cljs +++ b/src/cljs/orcpub/dnd/e5/views.cljs @@ -22,7 +22,6 @@ [orcpub.dnd.e5.party :as party] [orcpub.dnd.e5.character.random :as char-random] [orcpub.dnd.e5.character.equipment :as char-equip] - [cljs.pprint :refer [pprint]] [orcpub.registration :as registration] [orcpub.dnd.e5 :as e5] [orcpub.dnd.e5.magic-items :as mi] @@ -44,10 +43,8 @@ [clojure.string :as s] [cljs.reader :as reader] [orcpub.user-agent :as user-agent] - [cljs.core.async :refer [ saved-character ::se/summary ::char5e/character-name))) + (is (= "Charry-2" (-> updated-character ::se/summary ::char5e/character-name)))))))) + (deftest test-save-entity (with-conn conn (let [mocked-conn (dm/fork-conn conn)] @@ -47,11 +103,11 @@ (is (= "testy" (::mi/owner saved-entity))) (is (int? (:db/id saved-entity))) (is (= "Cool Item" (::mi/name saved-entity))))) - + (testing "Create and update entity" (let [entity {::mi/modifiers [{::mod/key :saving-throw-bonus - ::mod/args [{::mod/keyword-arg ::char/str} - {::mod/int-arg 1}]}]} + ::mod/args [{::mod/keyword-arg ::char5e/str} + {::mod/int-arg 1}]}]} saved-entity (routes/save-entity mocked-conn "testy" entity ::mi/owner)] (is (= "testy" (::mi/owner saved-entity))) (is (int? (:db/id saved-entity))) @@ -60,7 +116,7 @@ (testing "Update other user's entity" (let [entity {::mi/modifiers [{::mod/key :saving-throw-bonus - ::mod/args [{::mod/keyword-arg ::char/str} + ::mod/args [{::mod/keyword-arg ::char5e/str} {::mod/int-arg 1}]}]} saved-entity (routes/save-entity mocked-conn "testy" entity ::mi/owner) saved-entity-2 (routes/save-entity mocked-conn "testy-2" entity ::mi/owner)] @@ -69,7 +125,7 @@ (testing "Removal of orphans" (let [entity {::mi/modifiers [{::mod/key :saving-throw-bonus - ::mod/args [{::mod/keyword-arg ::char/str} + ::mod/args [{::mod/keyword-arg ::char5e/str} {::mod/int-arg 1}]}]} saved-entity (routes/save-entity mocked-conn "testy" entity ::mi/owner) root-id (:db/id saved-entity) @@ -82,7 +138,7 @@ (testing "Removal of non-children ids" (let [entity {::mi/modifiers [{::mod/key :saving-throw-bonus - ::mod/args [{::mod/keyword-arg ::char/str} + ::mod/args [{::mod/keyword-arg ::char5e/str} {::mod/int-arg 1}]}]} saved-entity (routes/save-entity mocked-conn "testy" entity ::mi/owner) root-id (:db/id saved-entity) diff --git a/web/cljs/orcpub/core.cljs b/web/cljs/orcpub/core.cljs index 43568d3f7..5b42a792e 100644 --- a/web/cljs/orcpub/core.cljs +++ b/web/cljs/orcpub/core.cljs @@ -1,5 +1,4 @@ (ns orcpub.core - (:require-macros [cljs.core.async.macros :refer [go]]) (:require [orcpub.character-builder :as ch] [orcpub.dnd.e5.subs] [orcpub.dnd.e5.equipment-subs] @@ -8,7 +7,6 @@ [orcpub.dnd.e5.views-2 :as views-2] [orcpub.route-map :as routes] [cljs-http.client :as http] - [cljs.core.async :refer [