load missing cards in background thread, closes #946
parent
ab52fa8e26
commit
d6d1396b4b
|
@ -353,7 +353,7 @@ public class CardDefinitions {
|
|||
}
|
||||
}
|
||||
|
||||
private static void loadMissingCards() {
|
||||
public static void loadMissingCards() {
|
||||
missingCards = new HashMap<>();
|
||||
final File[] scriptFiles = getSortedMissingScriptFiles();
|
||||
if (scriptFiles != null) {
|
||||
|
@ -418,10 +418,8 @@ public class CardDefinitions {
|
|||
return card.hasStatus() ? isCardMissing(card) && !card.getStatus().contains("not supported") : isCardMissing(card);
|
||||
}
|
||||
|
||||
public static synchronized Collection<MagicCardDefinition> getMissingCards() {
|
||||
if (missingCards == null) {
|
||||
loadMissingCards();
|
||||
}
|
||||
public static Collection<MagicCardDefinition> getMissingCards() {
|
||||
MagicSystem.waitForMissingCards();
|
||||
return missingCards.values();
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,27 @@ final public class MagicSystem {
|
|||
}
|
||||
};
|
||||
|
||||
public static final FutureTask<Void> loadMissing = new FutureTask<Void>(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CardDefinitions.loadMissingCards();
|
||||
}
|
||||
}, null) {
|
||||
@Override
|
||||
protected void done() {
|
||||
try {
|
||||
if (!isCancelled()) {
|
||||
get();
|
||||
}
|
||||
} catch (ExecutionException ex) {
|
||||
throw new RuntimeException(ex.getCause());
|
||||
} catch (InterruptedException ex) {
|
||||
// Shouldn't happen, we're invoked when computation is finished
|
||||
throw new AssertionError(ex);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static void setIsTestGame(boolean b) {
|
||||
System.setProperty("testGame", b ? "Y" : "");
|
||||
}
|
||||
|
@ -124,6 +145,18 @@ final public class MagicSystem {
|
|||
return reporter.getMessage();
|
||||
}
|
||||
|
||||
public static void waitForMissingCards() {
|
||||
if (loadMissing.isDone()) {
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
loadMissing.get();
|
||||
} catch (final InterruptedException|ExecutionException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void waitForAllCards() {
|
||||
if (loadCards.isDone()) {
|
||||
return;
|
||||
|
@ -178,6 +211,7 @@ final public class MagicSystem {
|
|||
CardDefinitions.postCardDefinitions();
|
||||
}
|
||||
});
|
||||
background.execute(loadMissing);
|
||||
background.shutdown();
|
||||
|
||||
// if parse scripts missing or pre-load abilities then load cards synchronously
|
||||
|
|
Loading…
Reference in New Issue