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

Fix for when purchase delegate isn't named "purchase". #12285

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -13,7 +13,6 @@
import games.strategy.triplea.TripleA;
import games.strategy.triplea.delegate.AbstractMoveDelegate;
import games.strategy.triplea.delegate.PoliticsDelegate;
import games.strategy.triplea.delegate.PurchaseDelegate;
import games.strategy.triplea.delegate.TechTracker;
import games.strategy.triplea.delegate.TechnologyDelegate;
import games.strategy.triplea.delegate.battle.BattleDelegate;
Expand Down Expand Up @@ -487,11 +486,6 @@ public PoliticsDelegate getPoliticsDelegate() {
return (PoliticsDelegate) findDelegate("politics");
}

@Override
public PurchaseDelegate getPurchaseDelegate() {
return (PurchaseDelegate) findDelegate("purchase");
}

private IDelegate findDelegate(final String delegateName) {
final IDelegate delegate = this.getDelegate(delegateName);
if (delegate == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import games.strategy.engine.data.properties.GameProperties;
import games.strategy.triplea.delegate.AbstractMoveDelegate;
import games.strategy.triplea.delegate.PoliticsDelegate;
import games.strategy.triplea.delegate.PurchaseDelegate;
import games.strategy.triplea.delegate.TechTracker;
import games.strategy.triplea.delegate.TechnologyDelegate;
import games.strategy.triplea.delegate.battle.BattleDelegate;
Expand Down Expand Up @@ -71,8 +70,6 @@ public interface GameState {

PoliticsDelegate getPoliticsDelegate();

PurchaseDelegate getPurchaseDelegate();

AbstractMoveDelegate getMoveDelegate();

TechnologyDelegate getTechDelegate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import games.strategy.engine.data.Territory;
import games.strategy.engine.data.Unit;
import games.strategy.engine.data.UnitType;
import games.strategy.engine.delegate.IDelegate;
import games.strategy.triplea.Properties;
import games.strategy.triplea.UnitUtils;
import games.strategy.triplea.attachments.RulesAttachment;
Expand Down Expand Up @@ -54,13 +55,15 @@ public class PurchasePanel extends ActionPanel {
public void actionPerformed(final ActionEvent e) {
final GamePlayer player = getCurrentPlayer();
final GameData data = getData();
final PurchaseDelegate purchaseDelegate = data.getPurchaseDelegate();

// Restore pending production that was loaded from the save game.
if (purchaseDelegate.getPendingProductionRules() == null) {
// Use the delegate from the step, since it may not actually be named 'purchase'.
final IDelegate delegate = data.getSequence().getStep().getDelegate();
if (delegate instanceof PurchaseDelegate) {
purchase = ((PurchaseDelegate) delegate).getPendingProductionRules();
}
if (purchase == null) {
purchase = new IntegerMap<>();
} else {
purchase = purchaseDelegate.getPendingProductionRules();
}

purchase =
Expand All @@ -72,8 +75,10 @@ public void actionPerformed(final ActionEvent e) {
purchase,
getMap().getUiContext());

// Keeping actualized pending production in PurchaseDelegate for later saving game.
purchaseDelegate.setPendingProductionRules(purchase);
if (delegate instanceof PurchaseDelegate) {
// Set pending production on the PurchaseDelegate for saving the game.
((PurchaseDelegate) delegate).setPendingProductionRules(purchase);
}

purchasedUnits.setUnitsFromProductionRuleMap(purchase, player);
if (purchase.totalValues() == 0) {
Expand Down