Skip to content

Commit

Permalink
Merge pull request #6085 from NoahTheDuke/nb/show-subroutine-menu-again
Browse files Browse the repository at this point in the history
Fix host issues, click ice menu for runner
  • Loading branch information
jwarwick authored Oct 8, 2021
2 parents 31f7a6e + bfe15ba commit b21a430
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 101 deletions.
1 change: 0 additions & 1 deletion src/clj/game/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@
is-type?
map->Card
operation?
private-card
program?
protecting-archives?
protecting-hq?
Expand Down
53 changes: 37 additions & 16 deletions src/clj/game/core/diffs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
runner-can-pay-and-install?]]
[game.core.payment :refer [can-pay?]]
[game.core.play-instants :refer [can-play-instant?]]
[game.utils :refer [select-non-nil-keys]]
[game.utils :refer [dissoc-in]]
[jinteki.utils :refer [select-non-nil-keys]]
[medley.core :refer [update-existing]]))

(defn playable? [card state side]
Expand Down Expand Up @@ -73,15 +74,9 @@
(select-non-nil-keys ability-keys)))

(defn abilities-summary [abilities card state side]
(->> abilities
(map-indexed (fn [ab-idx ab] (ability-summary state side card ab-idx ab)))
(into [])))

(defn card-abilities-summary [card state side]
(cond-> card
(seq (:abilities card)) (update :abilities abilities-summary card state side)
(seq (:corp-abilities card)) (update :corp-abilities abilities-summary card state side)
(seq (:runner-abilities card)) (update :runner-abilities abilities-summary card state side)))
(some->> (seq abilities)
(map-indexed (fn [ab-idx ab] (ability-summary state side card ab-idx ab)))
(into [])))

(def subroutine-keys
[:broken
Expand All @@ -94,6 +89,13 @@
(when (seq subroutines)
(mapv #(select-non-nil-keys % subroutine-keys) subroutines)))

(defn card-abilities-summary [card state side]
(cond-> card
(:abilities card) (update :abilities abilities-summary card state side)
(:corp-abilities card) (update :corp-abilities abilities-summary card state side)
(:runner-abilities card) (update :runner-abilities abilities-summary card state side)
(:subroutines card) (update :subroutines subroutines-summary)))

(def card-keys
[:abilities
:advance-counter
Expand All @@ -107,9 +109,11 @@
:current-advancement-requirement
:current-strength
:disabled
:extra-advance-counter
:face
:faces
:facedown
:host
:hosted
:icon
:images
Expand All @@ -118,7 +122,6 @@
:new
:normalizedtitle
:playable
:rec-counter
:rezzed
:runner-abilities
:seen
Expand All @@ -132,17 +135,35 @@
:type
:zone])

(def private-card-keys
[:advance-counter
:cid
:counter
:extra-advance-counter
:host
:hosted
:icon
:new
:side
:zone])

(defn private-card
"Returns only the public information of a given card when it's in a private state,
for example, when it's facedown or in the hand"
[card]
(select-non-nil-keys card private-card-keys))

(declare cards-summary)

(defn card-summary [card state side]
(if (not (is-public? card side))
(select-non-nil-keys (private-card card) card-keys)
(-> (if (:hosted card)
(update card :hosted cards-summary state side)
card)
(private-card card)
(-> (cond-> card
(:host card) (-> (dissoc-in [:host :hosted])
(update :host card-summary state side))
(:hosted card) (update :hosted cards-summary state side))
(playable? state side)
(card-abilities-summary state side)
(update-existing :subroutines subroutines-summary)
(select-non-nil-keys card-keys))))

(defn cards-summary [cards state side]
Expand Down
70 changes: 35 additions & 35 deletions src/clj/game/core/process_actions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,46 +39,46 @@
(say state side args))))

(def commands
{"ability" play-ability
"advance" click-advance
"change" change
"choice" resolve-prompt
"close-deck" close-deck
"concede" concede
"continue" continue
"corp-ability" play-corp-ability
"credit" click-credit
{"ability" #'play-ability
"advance" #'click-advance
"change" #'change
"choice" #'resolve-prompt
"close-deck" #'close-deck
"concede" #'concede
"continue" #'continue
"corp-ability" #'play-corp-ability
"credit" #'click-credit
"derez" #(derez %1 %2 (:card %3))
"draw" click-draw
"dynamic-ability" play-dynamic-ability
"end-phase-12" end-phase-12
"start-next-phase" start-next-phase
"end-turn" end-turn
"generate-install-list" generate-install-list
"generate-runnable-zones" generate-runnable-zones
"indicate-action" indicate-action
"jack-out" jack-out
"keep" keep-hand
"move" move-card
"mulligan" mulligan
"play" play
"purge" do-purge
"remove-tag" remove-tag
"draw" #'click-draw
"dynamic-ability" #'play-dynamic-ability
"end-phase-12" #'end-phase-12
"start-next-phase" #'start-next-phase
"end-turn" #'end-turn
"generate-install-list" #'generate-install-list
"generate-runnable-zones" #'generate-runnable-zones
"indicate-action" #'indicate-action
"jack-out" #'jack-out
"keep" #'keep-hand
"move" #'move-card
"mulligan" #'mulligan
"play" #'play
"purge" #'do-purge
"remove-tag" #'remove-tag
"rez" #(rez %1 %2 (make-eid %1) (:card %3) (dissoc %3 :card))
"run" click-run
"runner-ability" play-runner-ability
"run" #'click-run
"runner-ability" #'play-runner-ability
"score" #(score %1 %2 (make-eid %1) (get-card %1 (:card %3)) nil)
"select" select
"shuffle" shuffle-deck
"start-turn" start-turn
"subroutine" play-subroutine
"select" #'select
"shuffle" #'shuffle-deck
"start-turn" #'start-turn
"subroutine" #'play-subroutine
"system-msg" #(system-msg %1 %2 (:msg %3))
"toast" toast
"toggle-auto-no-action" toggle-auto-no-action
"toast" #'toast
"toggle-auto-no-action" #'toggle-auto-no-action
"trash" #(trash %1 %2 (make-eid %1) (get-card %1 (:card %3)) (dissoc %3 :card))
"trash-resource" trash-resource
"unbroken-subroutines" play-unbroken-subroutines
"view-deck" view-deck})
"trash-resource" #'trash-resource
"unbroken-subroutines" #'play-unbroken-subroutines
"view-deck" #'view-deck})

(defn process-action
[command state side args]
Expand Down
15 changes: 0 additions & 15 deletions src/clj/game/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,3 @@
(when (pred x)
idx))
coll))

(defn select-non-nil-keys
"Returns a map containing only those entries in map whose key is in keys and whose value is non-nil"
[m keyseq]
(loop [ret (transient {})
keyseq (seq keyseq)]
(if keyseq
(let [entry (clojure.lang.RT/find m (first keyseq))]
(recur
(if (and (some? entry)
(some? (val entry)))
(conj! ret entry)
ret)
(next keyseq)))
(with-meta (persistent! ret) (meta m)))))
8 changes: 1 addition & 7 deletions src/cljc/game/core/card.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
faces
faction
format
host
hosted
icon
images
Expand All @@ -41,7 +42,6 @@
previous-versions
previous-zone
quantity
rec-counter
rezzed
rotated
runner-abilities
Expand All @@ -61,12 +61,6 @@
uniqueness
zone])

(defn private-card
"Returns only the public information of a given card when it's in a private state,
for example, when it's facedown or in the hand"
[card]
(select-keys card [:zone :cid :side :new :host :counter :advance-counter :hosted :icon]))

(defn get-cid
"Gets the cid of a given card when wrapped in an effect-handler map"
[card]
Expand Down
16 changes: 16 additions & 0 deletions src/cljc/jinteki/utils.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,19 @@
(str cost-label ": " label)
:else
label)))

(defn select-non-nil-keys
"Returns a map containing only those entries in map whose key is in keys and whose value is non-nil"
[m keyseq]
(loop [ret (transient {})
keyseq (seq keyseq)]
(if keyseq
(let [k (first keyseq)
entry (get m k ::not-found)]
(recur
(if (and (not= entry ::not-found)
(some? entry))
(assoc! ret k entry)
ret)
(next keyseq)))
(with-meta (persistent! ret) (meta m)))))
Loading

0 comments on commit b21a430

Please sign in to comment.