Refactor TrackableObjects to support copy forward changed properties without completely overwriting references

This commit is contained in:
drdev
2015-06-27 22:41:04 +00:00
parent 61f5424b2e
commit e03156cd0c
8 changed files with 102 additions and 50 deletions

View File

@@ -65,8 +65,15 @@ public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards {
return gameView;
}
@Override
public void setGameView(final GameView gameView) {
this.gameView = gameView;
public void setGameView(final GameView gameView0) {
if (gameView == null || gameView0 == null) {
gameView = gameView0;
return;
}
//if game view set to another instance without being first cleared,
//update existing game view object instead of overwriting it
gameView.copyChangedProps(gameView0);
}
public final IGameController getGameController() {

View File

@@ -44,6 +44,7 @@ import forge.quest.QuestController;
import forge.sound.MusicPlaylist;
import forge.sound.SoundSystem;
import forge.trackable.TrackableCollection;
import forge.trackable.TrackableTypes;
import forge.util.CollectionSuppliers;
import forge.util.collect.FCollectionView;
import forge.util.maps.HashMapOfLists;
@@ -127,6 +128,11 @@ public class HostedMatch {
}
public void startGame() {
//ensure lookup dictionaries are cleared before each game
TrackableTypes.CardViewType.clearLookupDictionary();
TrackableTypes.PlayerViewType.clearLookupDictionary();
TrackableTypes.StackItemViewType.clearLookupDictionary();
nextGameDecisions.clear();
SoundSystem.instance.setBackgroundMusic(MusicPlaylist.MATCH);
@@ -168,6 +174,7 @@ public class HostedMatch {
final PlayerControllerHuman humanController = (PlayerControllerHuman) p.getController();
final IGuiGame gui = guis.get(p.getRegisteredPlayer());
humanController.setGui(gui);
gui.setGameView(null); //clear out game view first so we don't copy into old game view
gui.setGameView(gameView);
gui.setOriginalGameController(p.getView(), humanController);