Skip to content

Commit

Permalink
Merge pull request #7600 from butzopower/undo-click-perf
Browse files Browse the repository at this point in the history
Remove nested state histories being stored in click-states and turn-state
  • Loading branch information
NoahTheDuke authored Jul 30, 2024
2 parents c1bdbc9 + d574a72 commit 5397b0a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/clj/game/core/actions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"Update :click-states to hold latest 4 moments before performing actions."
[state ability]
(when (:action ability)
(let [state' (dissoc @state :log :history)
click-states (vec (take-last 4 (conj (:click-states state') state')))]
(let [state' (dissoc @state :log :history :click-states :turn-state)
click-states (vec (take-last 4 (conj (:click-states @state) state')))]
(swap! state assoc :click-states click-states))))

;;; Neutral actions
Expand Down
22 changes: 19 additions & 3 deletions src/clj/game/core/commands.clj
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,19 @@
(defn command-undo-click
"Resets the game state back to start of the click"
[state side]
(when-let [click-state (peek (:click-states @state))]
(when-let [last-click-state (peek (:click-states @state))]
(when (= (:active-player @state) side)
(reset! state (assoc click-state :log (:log @state) :click-states (pop (:click-states @state)) :run nil :history (:history @state)))
(let [current-log (:log @state)
current-history (:history @state)
previous-click-states (pop (:click-states @state))
turn-state (:turn-state @state)
last-click-state (assoc last-click-state
:log current-log
:click-states previous-click-states
:turn-state turn-state
:history current-history
:run nil)]
(reset! state last-click-state))
(system-say state side (str "[!] " (if (= side :corp) "Corp" "Runner") " uses the undo-click command"))
(doseq [s [:runner :corp]]
(toast state s "Game reset to start of click")))))
Expand All @@ -188,7 +198,13 @@
(when-let [turn-state (:turn-state @state)]
(swap! state assoc-in [side :undo-turn] true)
(when (and (-> @state :runner :undo-turn) (-> @state :corp :undo-turn))
(reset! state (assoc turn-state :log (:log @state) :turn-state turn-state :history (:history @state)))
(let [current-log (:log @state)
current-history (:history @state)
original-turn-state (assoc turn-state
:log current-log
:history current-history
:turn-state turn-state)]
(reset! state original-turn-state))
(doseq [s [:runner :corp]]
(toast state s "Game reset to start of turn")))))

Expand Down
2 changes: 1 addition & 1 deletion src/clj/game/core/turns.clj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
; Functions to set up state for undo-turn functionality
(doseq [s [:runner :corp]] (swap! state dissoc-in [s :undo-turn]))
(swap! state assoc :click-states [])
(swap! state assoc :turn-state (dissoc @state :log :turn-state))
(swap! state assoc :turn-state (dissoc @state :log :history :turn-state))

(when (= side :corp)
(swap! state update-in [:turn] inc))
Expand Down

0 comments on commit 5397b0a

Please sign in to comment.