Skip to content

Commit

Permalink
Bumped version to 1.2.0
Browse files Browse the repository at this point in the history
- added an error dialog when card files cannot be parsed
  • Loading branch information
demilich1 committed Aug 11, 2016
1 parent e0bfc06 commit 07cee1f
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version" : "1.1.1",
"version" : "1.2.0",
"whatsNew" : [
"- bugfixes"
"- added all 'One Night in Karazhan' cards"
]

}
2 changes: 1 addition & 1 deletion app/src/deploy/package/windows/Metastone.iss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[Setup]
AppId={{fxApplication}}
AppName=Metastone
AppVersion=1.1.1
AppVersion=1.2.0
AppVerName=Metastone
AppPublisher=demilich
AppComments=MetaStone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class ApplicationStartupCommand extends SimpleCommand<GameNotification> {

@Override
public void execute(INotification<GameNotification> notification) {
getFacade().registerMediator(new DialogMediator());

getFacade().registerProxy(new CardProxy());
getFacade().registerProxy(new DeckProxy());
getFacade().registerProxy(new DeckFormatProxy());
Expand All @@ -24,7 +26,6 @@ public void execute(INotification<GameNotification> notification) {
getFacade().registerProxy(new AnimationProxy());

getFacade().registerMediator(new ApplicationMediator());
getFacade().registerMediator(new DialogMediator());
getFacade().registerMediator(new AutoUpdateMediator());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.demilich.metastone.GameNotification;
import net.demilich.metastone.game.cards.CardCatalogue;
import net.demilich.metastone.game.cards.CardParseException;
import net.demilich.nittygrittymvc.Proxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -29,6 +30,8 @@ public CardProxy() {
} catch (IOException e) {
logger.error("Trouble creating " + Paths.get(CardCatalogue.CARDS_FOLDER_PATH));
e.printStackTrace();
} catch (CardParseException cpe) {
getFacade().sendNotification(GameNotification.CARD_PARSE_ERROR, cpe.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import net.demilich.nittygrittymvc.Mediator;
import net.demilich.nittygrittymvc.interfaces.INotification;
import javafx.scene.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.Pane;
import javafx.stage.Window;
import net.demilich.metastone.GameNotification;
Expand Down Expand Up @@ -38,6 +40,9 @@ public void handleNotification(final INotification<GameNotification> notificatio
case SHOW_MODAL_DIALOG:
showModalDialog((Node) notification.getBody());
break;
case CARD_PARSE_ERROR:
displayErrorMessage("Something is wrong with your card files", (String) notification.getBody());
break;
default:
logger.warn("Unhandled notification {} in {}", notification, getClass().getSimpleName());
break;
Expand All @@ -50,8 +55,17 @@ public List<GameNotification> listNotificationInterests() {
notificationInterests.add(GameNotification.CANVAS_CREATED);
notificationInterests.add(GameNotification.SHOW_MODAL_DIALOG);
notificationInterests.add(GameNotification.SHOW_USER_DIALOG);
notificationInterests.add(GameNotification.CARD_PARSE_ERROR);
return notificationInterests;
}

private void displayErrorMessage(String header, String message) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText(header);
alert.setContentText(message);
alert.showAndWait();
}

private void showModalDialog(Node content) {
new ModalDialog(root, content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.ArrayList;
import java.util.List;

import net.demilich.nittygrittymvc.Mediator;
import net.demilich.nittygrittymvc.interfaces.INotification;
import javafx.scene.Node;
import javafx.scene.layout.Pane;
import net.demilich.metastone.GameNotification;
Expand All @@ -16,6 +14,8 @@
import net.demilich.metastone.gui.sandboxmode.SandboxModeMediator;
import net.demilich.metastone.gui.simulationmode.SimulationMediator;
import net.demilich.metastone.gui.trainingmode.TrainingModeMediator;
import net.demilich.nittygrittymvc.Mediator;
import net.demilich.nittygrittymvc.interfaces.INotification;

public class ApplicationMediator extends Mediator<GameNotification> {

Expand Down Expand Up @@ -53,9 +53,10 @@ public List<GameNotification> listNotificationInterests() {
notificationInterests.add(GameNotification.CANVAS_CREATED);
notificationInterests.add(GameNotification.SHOW_VIEW);
notificationInterests.add(GameNotification.MAIN_MENU);
notificationInterests.add(GameNotification.CARD_PARSE_ERROR);
return notificationInterests;
}

private void removeOtherViews() {
getFacade().removeMediator(PlayModeMediator.NAME);
getFacade().removeMediator(PlayModeConfigMediator.NAME);
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ subprojects {

sourceCompatibility = 1.8

project.version = '1.1.1'
project.version = '1.2.0'

compileJava {
options.encoding = 'UTF-8'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -133,21 +134,22 @@ public static CardCollection query(DeckFormat deckFormat, Predicate<Card> filter
return result;
}

public static void loadLocalCards() throws IOException, URISyntaxException {
public static void loadLocalCards() throws IOException, URISyntaxException, CardParseException {
// load cards from ~/metastone/cards on the file system
Collection<ResourceInputStream> inputStreams = ResourceLoader.loadJsonInputStreams(CARDS_FOLDER, false);
loadCards(inputStreams);
}

public static void loadCards() throws IOException, URISyntaxException {
public static void loadCards() throws IOException, URISyntaxException, CardParseException {
// load cards from ~/metastone/cards on the file system
Collection<ResourceInputStream> inputStreams = ResourceLoader.loadJsonInputStreams(CARDS_FOLDER_PATH, true);
loadCards(inputStreams);
}


private static void loadCards(Collection<ResourceInputStream> inputStreams) throws IOException, URISyntaxException {
private static void loadCards(Collection<ResourceInputStream> inputStreams) throws IOException, URISyntaxException, CardParseException {
Map<String, CardDesc> cardDesc = new HashMap<String, CardDesc>();
ArrayList<String> badCards = new ArrayList<>();
CardParser cardParser = new CardParser();
for (ResourceInputStream resourceInputStream : inputStreams) {
try {
Expand All @@ -157,8 +159,8 @@ private static void loadCards(Collection<ResourceInputStream> inputStreams) thro
}
cardDesc.put(desc.id, desc);
} catch (Exception e) {
logger.error("Trouble reading " + resourceInputStream.fileName);
throw e;
logger.error("Error parsing card '{}'", resourceInputStream.fileName);
badCards.add(resourceInputStream.fileName);
}
}

Expand All @@ -167,6 +169,10 @@ private static void loadCards(Collection<ResourceInputStream> inputStreams) thro
CardCatalogue.add(instance);
logger.debug("Adding {} to CardCatalogue", instance);
}

if (!badCards.isEmpty()) {
throw new CardParseException(badCards);
}
}

public static void copyCardsFromResources() throws IOException, URISyntaxException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.demilich.metastone.game.cards;

import java.util.Arrays;
import java.util.List;

public class CardParseException extends Exception {

/**
*
*/
private static final long serialVersionUID = 1L;


public CardParseException(List<String> badCards) {
super(getMessage(badCards));
}

private static String getMessage(List<String> badCards) {
String message = "The following card files contain errors:\n";
message += Arrays.toString(badCards.toArray());
message+="\n\nYou can either fix the errors manually or remove the 'cards.copied' entry from your metastone.properties file to restore all cards.";
return message;
}

}
3 changes: 3 additions & 0 deletions game/src/test/java/net/demilich/metastone/tests/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.demilich.metastone.game.behaviour.Behaviour;
import net.demilich.metastone.game.cards.Card;
import net.demilich.metastone.game.cards.CardCatalogue;
import net.demilich.metastone.game.cards.CardParseException;
import net.demilich.metastone.game.cards.CardSet;
import net.demilich.metastone.game.cards.HeroCard;
import net.demilich.metastone.game.cards.MinionCard;
Expand Down Expand Up @@ -79,6 +80,8 @@ public void setTargetPreference(EntityReference targetPreference) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (CardParseException e) {
System.err.println(e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public enum GameNotification {
SHOW_VIEW,
CHECK_FOR_UPDATE,
NEW_VERSION_AVAILABLE,

CARD_PARSE_ERROR,

START_GAME,
PLAY_GAME,
Expand Down

0 comments on commit 07cee1f

Please sign in to comment.