Fix null pointer when creating a custom constructed game. Enforce deck conformance check for ai deck.

This commit is contained in:
RedDeckWins
2013-04-26 02:03:03 +00:00
parent 40ef9e0bcd
commit 86d07620c4
2 changed files with 17 additions and 5 deletions

View File

@@ -116,6 +116,10 @@ public enum DeckFormat {
@SuppressWarnings("incomplete-switch") @SuppressWarnings("incomplete-switch")
public String getDeckConformanceProblem(Deck deck) { public String getDeckConformanceProblem(Deck deck) {
if(deck == null) {
return "is not selected";
}
// That's really a bad dependence // That's really a bad dependence
if (!Singletons.getModel().getPreferences().getPrefBoolean(FPref.ENFORCE_DECK_LEGALITY)) { if (!Singletons.getModel().getPreferences().getPrefBoolean(FPref.ENFORCE_DECK_LEGALITY)) {
return null; return null;

View File

@@ -92,14 +92,22 @@ public enum CSubmenuConstructed implements ICDoc {
view.getCbRemoveSmall().setSelected(prefs.getPrefBoolean(FPref.DECKGEN_NOSMALL)); view.getCbRemoveSmall().setSelected(prefs.getPrefBoolean(FPref.DECKGEN_NOSMALL));
} }
/** @param gameType /**
* @param lists0 &emsp; {@link java.util.List}<{@link javax.swing.JList}> */ *
* @param gameType
*/
private void startGame(final GameType gameType) { private void startGame(final GameType gameType) {
Deck humanDeck = VSubmenuConstructed.SINGLETON_INSTANCE.getDcHuman().getDeck(); Deck humanDeck = VSubmenuConstructed.SINGLETON_INSTANCE.getDcHuman().getDeck();
String humanDeckErrorMessage = gameType.getDecksFormat().getDeckConformanceProblem(humanDeck);
if (null != humanDeckErrorMessage) {
JOptionPane.showMessageDialog(null, "Your deck " + humanDeckErrorMessage, "Invalid deck", JOptionPane.ERROR_MESSAGE);
return;
}
String errorMessage = gameType.getDecksFormat().getDeckConformanceProblem(humanDeck); Deck aiDeck = VSubmenuConstructed.SINGLETON_INSTANCE.getDcAi().getDeck();
if (null != errorMessage) { String aiDeckErrorMessage = gameType.getDecksFormat().getDeckConformanceProblem(aiDeck);
JOptionPane.showMessageDialog(null, "Your deck " + errorMessage, "Invalid deck", JOptionPane.ERROR_MESSAGE); if (null != aiDeckErrorMessage) {
JOptionPane.showMessageDialog(null, "AI deck " + aiDeckErrorMessage, "Invalid deck", JOptionPane.ERROR_MESSAGE);
return; return;
} }