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

Save games should save pending purchase selections #11819 #12084

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.triplea.io.IoUtils;
import org.triplea.java.ObjectUtils;
import org.triplea.java.RemoveOnNextMajorRelease;
import org.triplea.java.collections.IntegerMap;
import org.triplea.map.description.file.MapDescriptionYaml;
import org.triplea.map.game.notes.GameNotes;
import org.triplea.util.Tuple;
Expand Down Expand Up @@ -88,6 +89,7 @@ public class GameData implements Serializable, GameState {
private final GameMap map = new GameMap(this);
private final PlayerList playerList = new PlayerList(this);
private final ProductionFrontierList productionFrontierList = new ProductionFrontierList(this);
private IntegerMap<ProductionRule> pendingProductionRules;
asvitkine marked this conversation as resolved.
Show resolved Hide resolved
private final ProductionRuleList productionRuleList = new ProductionRuleList(this);
private final RepairFrontierList repairFrontierList = new RepairFrontierList(this);
private final RepairRules repairRules = new RepairRules(this);
Expand Down Expand Up @@ -241,6 +243,14 @@ public IDelegate getDelegate(final String name) {
return delegates.get(name);
}

public IntegerMap<ProductionRule> getPendingProductionRules() {
return pendingProductionRules;
}

public void setPendingProductionRules(IntegerMap<ProductionRule> pendingProductionRules) {
this.pendingProductionRules = pendingProductionRules;
}

@Override
public UnitHolder getUnitHolder(final String name, final String type) {
switch (type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void actionPerformed(final ActionEvent e) {
bid,
purchase,
getMap().getUiContext());
data.setPendingProductionRules(purchase);
purchasedUnits.setUnitsFromProductionRuleMap(purchase, player);
if (purchase.totalValues() == 0) {
purchasedLabel.setText("");
Expand Down Expand Up @@ -92,7 +93,12 @@ public void display(final GamePlayer gamePlayer) {
if (keepCurrentPurchase) {
keepCurrentPurchase = false;
} else {
purchase = new IntegerMap<>();
GameData gameData = getData();
if (gameData.getPendingProductionRules() != null) {
asvitkine marked this conversation as resolved.
Show resolved Hide resolved
purchase = gameData.getPendingProductionRules();
} else {
purchase = new IntegerMap<>();
}
}
SwingUtilities.invokeLater(
() -> {
Expand Down Expand Up @@ -191,6 +197,7 @@ public void performDone() {
}
}
}
getData().setPendingProductionRules(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're only relying on clearing this from PurchasePanel, it means it won't work if you load a save game from a human player and then change that player to AI and another player to human before starting, since I assume it won't run this code.

If this is moved to PurchaseDelegete, then I think this likely won't have the problem if this is put in end(). But you should test.

release();
}

Expand Down