Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RwR bugfixes #7307

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -52,58 +52,6 @@
game.core/effect game.core/wait-for]}
:unused-namespace {:exclude ["game.core.*"]}
:refer-all {:level :off}
:type-mismatch
{:namespaces
{monger.collection
{insert {:arities {3 {:args [:any :any :map]}
4 {:args [:any :any :map :any]}}}
insert-and-return {:arities {3 {:args [:any :any :map]}
4 {:args [:any :any :map :any]}}}
insert-batch {:arities {3 {:args [:any :any :seq]}
4 {:args [:any :any :seq :any]}}}
find {:arities {2 {:args [:any :any]}
3 {:args [:any :any :any]}
4 {:args [:any :any :any :any]}}}
find-maps {:arities {2 {:args [:any :any]}
3 {:args [:any :any :any]}
4 {:args [:any :any :any :any]}}}
find-seq {:arities {2 {:args [:any :any]}
3 {:args [:any :any :any]}
4 {:args [:any :any :any :any]}}}
find-one {:arities {3 {:args [:any :any :any]}
4 {:args [:any :any :any :any]}}}
find-one-as-map {:arities {3 {:args [:any :any :any]}
4 {:args [:any :any :any :any]}
5 {:args [:any :any :any :any :any]}}}
find-and-modify {:arities {5 {:args [:any :any :any :any :any]}}}
find-by-id {:arities {3 {:args [:any :any :any]}
4 {:args [:any :any :any :any]}}}
find-map-by-id {:arities {3 {:args [:any :any :any]}
4 {:args [:any :any :any :any]}
5 {:args [:any :any :any :any :any]}}}
count {:arities {2 {:args [:any :any]}
3 {:args [:any :any :any]}}}
any? {:arities {2 {:args [:any :any]}
3 {:args [:any :any :any]}}}
empty? {:arities {2 {:args [:any :any]}}}
update {:arities {4 {:args [:any :any :any :any]}
5 {:args [:any :any :any :any :any]}}}
upsert {:arities {4 {:args [:any :any :any :any]}
5 {:args [:any :any :any :any :any]}}}
update-by-id {:arities {4 {:args [:any :any :any :any]}
5 {:args [:any :any :any :any :any]}}}
update-by-ids {:arities {4 {:args [:any :any :any :any]}
5 {:args [:any :any :any :any :any]}}}
save {:arities {3 {:args [:any :any :any]}
4 {:args [:any :any :any :any]}}}
save-and-return {:arities {3 {:args [:any :any :any]}
4 {:args [:any :any :any :any]}}}
remove {:arities {2 {:args [:any :any]}
3 {:args [:any :any :any]}}}
remove-by-id {:arities {3 {:args [:any :any :any]}}}
purge-many {:arities {2 {:args [:any :any]}}}
create-index {:arities {3 {:args [:any :any :any]}
4 {:args [:any :any :any :any]}}}}}}
}
:lint-as {game.test-framework/before-each clojure.core/let
reagent.core/with-let clojure.core/let
Expand Down
7 changes: 5 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ services:

database:
image: mongo
restart: always
container_name: mongodb
restart: unless-stopped
ports:
- 27017:27017
- 27017-27019:27017-27019
volumes:
- ./data:/data/db

cljs:
entrypoint: npm run cljs:watch
Expand Down
6 changes: 2 additions & 4 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
:init-ns web.dev
:init (go)}

:dependencies [[org.clojure/clojure "1.10.3"]
[org.clojure/clojurescript "1.10.891"
:dependencies [[org.clojure/clojure "1.11.2"]
[org.clojure/clojurescript "1.11.132"
:exclusions [org.clojure/google-closure-library
org.clojure/data.json
org.clojure/tools.reader
Expand All @@ -33,8 +33,6 @@
[ring/ring-devel "1.9.4" :exclusions [org.clojure/java.classpath]]
[ring/ring-anti-forgery "1.3.0"]
[ring/ring-json "0.5.1"]
[puppetlabs/ring-middleware "1.3.1"
:exclusions [prismatic/schema org.bouncycastle/bcpkix-jdk15on]]
[ring-cors "0.1.13"]
[compojure "1.6.2"]
[hiccup "1.0.5"]
Expand Down
1 change: 1 addition & 0 deletions src/clj/game/cards/agendas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,7 @@
:async true
:optional
{:prompt (msg "Remove 1 hosted agenda counter to rez up to 2 ice protecting " (zone->name (:server context)) ", ignoring all costs?")
:req (req (pos? (get-counters card :agenda)))
:yes-ability
{:cost [:agenda 1]
:effect (req (let [current-server (first (:server (:run @state)))]
Expand Down
77 changes: 43 additions & 34 deletions src/clj/game/cards/assets.clj
Original file line number Diff line number Diff line change
Expand Up @@ -493,19 +493,23 @@

(defcard "Charlotte Caçador"
(let [ability {:label "Gain 4 [Credits] and draw 1 card"
:optional {:once :per-turn
:prompt "Remove 1 hosted advancement counter to gain 4 [Credits] and draw 1 card?"
:req (req (pos? (get-counters card :advancement)))
:yes-ability {:msg "remove 1 hosted advancement counter from itself to gain 4 [Credits] and draw 1 card"
:async true
:effect (req
(add-prop state :corp card :advance-counter -1)
(wait-for
(gain-credits state side 4)
(draw state side eid 1)))}}}
:interactive (req true)
:optional
{:once :per-turn
:prompt "Remove 1 hosted advancement counter to gain 4 [Credits] and draw 1 card?"
:req (req (pos? (get-counters card :advancement)))
:yes-ability
{:msg "remove 1 hosted advancement counter from itself to gain 4 [Credits] and draw 1 card"
:async true
:effect (req
(add-prop state :corp card :advance-counter -1)
(wait-for
(gain-credits state side 4)
(draw state side eid 1)))}}}
trash-ab {:cost [:advancement 1 :trash-can]
:label "Gain 3 [Credits]"
:msg (msg "gain 3 [Credits]")
:async true
:effect (req (gain-credits state :corp eid 3))}]
{:advanceable :always
:flags {:corp-phase-12 (req true)}
Expand Down Expand Up @@ -1240,32 +1244,37 @@
:choices {:card #(and (can-be-advanced? %)
(installed? %))}
:msg (msg "place 1 advancement counter on " (card-str state target))
:effect (effect (add-prop target :advance-counter 1 {:placed true}))}]
:effect (effect (add-prop target :advance-counter 1 {:placed true}))}
ability {:req (req (:corp-phase-12 @state))
:label "Move 1 hosted advancement counter to another card you can advance (start of turn)"
:once :per-turn
:waiting-prompt true
:prompt "Choose an installed card to move 1 hosted advancement counter from"
:choices {:card #(and (installed? %)
(get-counters % :advancement))}
:async true
:effect (effect
(continue-ability
(let [from-ice target]
{:prompt "Choose an installed card you can advance"
:choices {:card #(and (installed? %)
(can-be-advanced? %)
(not (same-card? from-ice %)))}
:msg (msg "move 1 hosted advancement counter from "
(card-str state from-ice)
" to "
(card-str state target))
:async true
:effect (effect (add-prop :corp target :advance-counter 1)
(add-prop :corp from-ice :advance-counter -1)
(continue-ability political card nil))
:cancel-effect (effect (continue-ability political card nil))})
card nil))
:cancel-effect (effect (continue-ability political card nil))}]
{:derezzed-events [corp-rez-toast]
:flags {:corp-phase-12 (req true)}
:abilities [{:label "Move 1 hosted advancement counter to another card you can advance (start of turn)"
:once :per-turn
:waiting-prompt true
:prompt "Choose an installed card to move 1 hosted advancement counter from"
:choices {:card #(and (installed? %)
(get-counters % :advancement))}
:effect (effect
(continue-ability
(let [from-ice target]
{:prompt "Choose an installed card you can advance"
:choices {:card #(and (installed? %)
(can-be-advanced? %)
(not (same-card? from-ice %)))}
:msg (msg "move 1 hosted advancement counter from "
(card-str state from-ice)
" to "
(card-str state target))
:effect (effect (add-prop :corp target :advance-counter 1)
(add-prop :corp from-ice :advance-counter -1)
(continue-ability political card nil))
:cancel-effect (effect (continue-ability political card nil))})
card nil))
:cancel-effect (effect (continue-ability political card nil))}]}))
:events [(assoc ability :event :corp-turn-begins)]
:abilities [ability]}))

(defcard "Honeyfarm"
{:flags {:rd-reveal (req true)}
Expand Down
37 changes: 16 additions & 21 deletions src/clj/game/cards/upgrades.clj
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,22 @@
(defn mobile-sysop-event
([] (mobile-sysop-event :corp-turn-ends))
([ev] (mobile-sysop-event ev nil))
([ev callback] {:event ev
:optional
{:prompt (msg "Move " (:title card) " to another server?")
:waiting-prompt true
:yes-ability
{:async true
:effect (effect (continue-ability
{:prompt "Choose a server"
:waiting-prompt true
:choices (server-list state)
:msg (msg "move itself to " target)
:async true
:effect (req (let [c (move state side card
(conj (server->zone state target) :content))]
(unregister-events state side card)
(register-default-events state side c)
(if callback
(continue-ability state side callback c nil)
(effect-completed state side eid))
))}
card nil))}}}))
([ev callback]
{:event ev
:optional
{:prompt (msg "Move " (:title card) " to another server?")
:waiting-prompt true
:yes-ability
{:prompt "Choose a server"
:waiting-prompt true
:choices (req (server-list state))
:msg (msg "move itself to " target)
:async true
:effect (req (let [c (move state side card
(conj (server->zone state target) :content))]
(unregister-events state side card)
(register-default-events state side c)
(continue-ability state side callback c nil)))}}}))

;; Card definitions

Expand Down
11 changes: 5 additions & 6 deletions src/clj/game/core/toasts.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
(ns game.core.toasts
(:require
[clj-uuid :as uuid]))
(ns game.core.toasts)

(defn toast
"Adds a message to toast with specified severity (default as a warning) to the toast message list.
Expand All @@ -15,13 +13,14 @@
([state side message msg-type] (toast state side message msg-type nil))
([state side message msg-type options]
;; Allows passing just the toast msg-type as the options parameter
(when message
(when message
;; normal toast - add to list
(swap! state update-in [side :toast] #(conj % {:msg message :type msg-type :options options :id (uuid/v4)})))))
(swap! state update-in [side :toast] #(conj % {:msg message :type msg-type :options options :id (random-uuid)})))))

(defn ack-toast
([state side {:keys [id]}]
(swap! state update-in [side :toast] (fn [toasts] (remove #(= (:id %) (uuid/as-uuid id)) toasts)))))
(when-let [id (when (string? id) (parse-uuid id))]
(swap! state update-in [side :toast] (fn [toasts] (remove #(= (:id %) id) toasts))))))

(defn show-error-toast
[state side]
Expand Down
15 changes: 14 additions & 1 deletion src/clj/web/api.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns web.api
(:require
[cheshire.generate :refer [add-encoder encode-str]]
[puppetlabs.ring-middleware.core :refer [wrap-add-cache-headers]]
[reitit.core :as r]
[reitit.ring :as ring]
[ring.middleware.anti-forgery :refer [wrap-anti-forgery]]
Expand Down Expand Up @@ -38,6 +37,20 @@
((ring/ring-handler (base-routes)) {:request-method :get :uri "/"})
)

;; Taken from puppetlabs/ring-middleware
(defn wrap-add-cache-headers
"Adds cache control invalidation headers to GET and PUT requests if they are handled by the handler"
[handler]
(fn [request]
(let [request-method (:request-method request)
response (handler request)]
(when-not (nil? response)
(if (or
(= request-method :get)
(= request-method :put))
(assoc-in response [:headers "cache-control"] "no-store")
response)))))

(defn api-routes []
(ring/router
[["/chsk" {:get ws/handshake-handler
Expand Down
44 changes: 19 additions & 25 deletions src/clj/web/data.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,22 @@
[clojure.edn :as edn]))

(defn news-handler [{db :system/db}]
(let [data (mq/with-collection db "news"
(let [data (mq/with-collection db (.getCollection db "news")
(mq/find {})
(mq/fields [:_id :item :date])
(mq/sort (array-map :date -1)))
data (map #(update % :date mongo-time-to-utc-string) data)]
data (mapv #(update % :date mongo-time-to-utc-string) data)]
(response 200 data)))

(defn- cards-version-impl [db]
(defn- cards-version [db]
(:cards-version (mc/find-one-as-map db "config" nil)))

(def cards-version (memoize cards-version-impl))

(defn cards-version-handler [{db :system/db}]
(response 200 {:version (int (cards-version db))}))

(defn- enriched-cards-impl [db]
(defn- enriched-cards [db]
(let [cards (mc/find-maps db "cards")]
(->> cards
(map #(assoc % :implementation (card-implemented %)))
(map #(dissoc % :_id)))))

(def enriched-cards (memoize enriched-cards-impl))
(mapv #(-> % (assoc :implementation (card-implemented %)) (dissoc :_id)) cards)))

(defn cards-handler [{db :system/db}]
(response 200 (enriched-cards db)))
Expand All @@ -38,29 +32,29 @@

(defn lang-handler [{db :system/db {lang :lang} :path-params}]
(if (validate-lang lang)
(response 200 (map #(dissoc % :_id) (mc/find-maps db (str "cards-" lang))))
(response 200 {})))
(response 200 (mapv #(dissoc % :_id) (mc/find-maps db (str "cards-" lang))))
(response 200 {})))

(defn alt-arts-handler [{db :system/db}]
(response 200 (map #(dissoc % :_id) (mc/find-maps db "altarts"))))
(response 200 (mapv #(dissoc % :_id) (mc/find-maps db "altarts"))))

(defn sets-handler [{db :system/db}]
(response 200 (map #(dissoc % :_id) (mc/find-maps db "sets"))))
(response 200 (mapv #(dissoc % :_id) (mc/find-maps db "sets"))))

(defn mwl-handler [{db :system/db}]
(response 200 (map #(dissoc % :_id) (mc/find-maps db "mwls"))))
(response 200 (mapv #(dissoc % :_id) (mc/find-maps db "mwls"))))

(defn cycles-handler [{db :system/db}]
(response 200 (map #(dissoc % :_id) (mc/find-maps db "cycles"))))
(response 200 (mapv #(dissoc % :_id) (mc/find-maps db "cycles"))))

(defn donors-handler [{db :system/db}]
(response 200 (->> (mc/find-maps db "donators")
(map #(let [amount (:amount %)]
(assoc % :amount (if (string? amount)
(edn/read-string amount)
amount))))
(mapv #(let [amount (:amount %)]
(assoc % :amount (if (string? amount)
(edn/read-string amount)
amount))))
(sort-by :amount >)
(map #(let [username (:username %)]
(if (empty? username)
(:name %)
username))))))
(mapv #(let [username (:username %)]
(if (empty? username)
(:name %)
username))))))
4 changes: 2 additions & 2 deletions src/clj/web/system.clj
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@

(defmethod ig/init-key :jinteki/cards [_ {{:keys [db]} :mongo}]
(let [cards (mc/find-maps db "cards" nil)
stripped-cards (map #(update % :_id str) cards)
all-cards (into {} (map (juxt :title identity) stripped-cards))
stripped-cards (mapv #(update % :_id str) cards)
all-cards (into {} (map (juxt :title identity)) stripped-cards)
sets (mc/find-maps db "sets" nil)
cycles (mc/find-maps db "cycles" nil)
mwl (mc/find-maps db "mwls" nil)
Expand Down
Loading
Loading