mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 13:02:06 -08:00
Deck editor:
+ added warning messages dialog after load/import decks with errors (instead throw exception); + added loading cursors on import-load decks; - fixed null exception error on empty/error deck loading;
This commit is contained in:
parent
1efc062f66
commit
5fc0393bc7
3 changed files with 96 additions and 34 deletions
|
|
@ -45,7 +45,14 @@ public abstract class DeckImporter {
|
|||
protected StringBuilder sbMessage = new StringBuilder(); //TODO we should stop using this not garbage collectable StringBuilder. It just bloats
|
||||
protected int lineCount;
|
||||
|
||||
public DeckCardLists importDeck(String file) {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file file to import
|
||||
* @param errorMessages you can setup output messages to showup to user (set null for fatal exception on messages.count > 0)
|
||||
* @return decks list
|
||||
*/
|
||||
public DeckCardLists importDeck(String file, StringBuilder errorMessages) {
|
||||
File f = new File(file);
|
||||
DeckCardLists deckList = new DeckCardLists();
|
||||
if (!f.exists()) {
|
||||
|
|
@ -62,8 +69,15 @@ public abstract class DeckImporter {
|
|||
lineCount++;
|
||||
readLine(line, deckList);
|
||||
}
|
||||
|
||||
if (sbMessage.length() > 0) {
|
||||
logger.fatal(sbMessage);
|
||||
if(errorMessages != null) {
|
||||
// normal output for user
|
||||
errorMessages.append(sbMessage);
|
||||
}else{
|
||||
// fatal error
|
||||
logger.fatal(sbMessage);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.fatal(null, ex);
|
||||
|
|
@ -74,6 +88,10 @@ public abstract class DeckImporter {
|
|||
return deckList;
|
||||
}
|
||||
|
||||
public DeckCardLists importDeck(String file) {
|
||||
return importDeck(file, null);
|
||||
}
|
||||
|
||||
public String getErrors(){
|
||||
return sbMessage.toString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,12 +51,16 @@ public final class DeckImporterUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static DeckCardLists importDeck(String file) {
|
||||
public static DeckCardLists importDeck(String file, StringBuilder errorMessages) {
|
||||
DeckImporter deckImporter = getDeckImporter(file);
|
||||
if (deckImporter != null) {
|
||||
return deckImporter.importDeck(file);
|
||||
return deckImporter.importDeck(file, errorMessages);
|
||||
} else {
|
||||
return new DeckCardLists();
|
||||
}
|
||||
}
|
||||
|
||||
public static DeckCardLists importDeck(String file) {
|
||||
return importDeck(file, null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue