Skip to content

Commit 7f15a52

Browse files
MostCromulentclaude
andcommitted
Refresh local-player controller keys on match restart
Root-cause fix for docked zone tabs showing the previous game's cards after "Start New Match". getLocalPlayers() returns gameControllers.keySet(), keyed by PlayerView (equality is by id). Desktop reuses the GUI across matches without clearing the map, so when setOriginalGameController re-registers the new game's live PlayerView, HashMap.put keeps the id-equal old key and only swaps the value -- keySet() then hands back the prior game's orphaned view, which never updates. registerZoneDocs binds docked zones to that stale view. Removing the id-equal entry before re-putting makes the live instance the key, so getLocalPlayers() returns live views for every consumer. Only the key changes; the value and all id-based lookups are untouched, so existing callers behave identically. Reverts the desktop-scoped registerZoneDocs workaround. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 3fe6e02 commit 7f15a52

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -940,14 +940,7 @@ public void updateTurn(final PlayerView player) {
940940
@Override
941941
public void updatePlayerControl() {
942942
initHandViews();
943-
// Use live PlayerViews; getLocalPlayers() can hand back an orphaned key from the prior game (equality is by id)
944-
final List<PlayerView> localPlayers = new ArrayList<>();
945-
for (final PlayerView p : getGameView().getPlayers()) {
946-
if (isLocalPlayer(p)) {
947-
localPlayers.add(p);
948-
}
949-
}
950-
FloatingZone.registerZoneDocs(this, localPlayers);
943+
FloatingZone.registerZoneDocs(this, getLocalPlayers());
951944
SLayoutIO.loadLayout(null);
952945
FloatingZone.pruneUnparentedDocks();
953946
view.populate();

forge-gui/src/main/java/forge/gamemodes/match/AbstractGuiGame.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,12 @@ public void setOriginalGameController(PlayerView player, final IGameController g
190190

191191
player = TrackableTypes.PlayerViewType.lookup(player); //ensure we use the correct player
192192

193+
// HashMap.put keeps the existing key on an id-equal put and PlayerView equality is by id, so without
194+
// removing first, re-registration across matches would retain the prior game's stale PlayerView
193195
final boolean doSetCurrentPlayer = originalGameControllers.isEmpty();
196+
originalGameControllers.remove(player);
194197
originalGameControllers.put(player, gameController);
198+
gameControllers.remove(player);
195199
gameControllers.put(player, gameController);
196200
if (doSetCurrentPlayer) {
197201
setCurrentPlayer(player);

0 commit comments

Comments
 (0)