mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Lazy-load cards in GameSimulatorTest to make it exec faster.
This commit is contained in:
@@ -50,7 +50,7 @@ public final class Singletons {
|
||||
view = FView.SINGLETON_INSTANCE;
|
||||
}
|
||||
|
||||
FModel.initialize(view == null ? null : view.getSplash().getProgressBar());
|
||||
FModel.initialize(view == null ? null : view.getSplash().getProgressBar(), null);
|
||||
|
||||
if (withUi) {
|
||||
control = FControl.instance;
|
||||
|
||||
@@ -27,7 +27,7 @@ import forge.util.Lang;
|
||||
|
||||
public class SimulateMatch {
|
||||
public static void simulate(String[] args) {
|
||||
FModel.initialize(null);
|
||||
FModel.initialize(null, null);
|
||||
|
||||
System.out.println("Simulation mode");
|
||||
if(args.length < 4) {
|
||||
|
||||
@@ -4,10 +4,12 @@ import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.GuiBase;
|
||||
import forge.GuiDesktop;
|
||||
import forge.StaticData;
|
||||
import forge.ai.ComputerUtilAbility;
|
||||
import forge.ai.LobbyPlayerAi;
|
||||
import forge.ai.simulation.GameStateEvaluator.Score;
|
||||
@@ -29,6 +31,8 @@ import forge.game.spellability.SpellAbility;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.model.FModel;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
|
||||
public class GameSimulatorTest extends TestCase {
|
||||
private static boolean initialized = false;
|
||||
@@ -45,7 +49,13 @@ public class GameSimulatorTest extends TestCase {
|
||||
|
||||
if (!initialized) {
|
||||
GuiBase.setInterface(new GuiDesktop());
|
||||
FModel.initialize(null);
|
||||
FModel.initialize(null, new Function<ForgePreferences, Void>() {
|
||||
@Override
|
||||
public Void apply(ForgePreferences preferences) {
|
||||
preferences.setPref(FPref.LOAD_CARD_SCRIPTS_LAZILY, true);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
initialized = true;
|
||||
}
|
||||
return game;
|
||||
@@ -93,6 +103,10 @@ public class GameSimulatorTest extends TestCase {
|
||||
|
||||
private Card createCard(String name, Player p) {
|
||||
IPaperCard paperCard = FModel.getMagicDb().getCommonCards().getCard(name);
|
||||
if (paperCard == null) {
|
||||
StaticData.instance().attemptToLoadCard(name, "");
|
||||
paperCard = FModel.getMagicDb().getCommonCards().getCard(name);
|
||||
}
|
||||
return Card.fromPaperCard(paperCard, p);
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ public class Forge implements ApplicationListener {
|
||||
AssetsDownloader.checkForUpdates(splashScreen);
|
||||
if (exited) { return; } //don't continue if user chose to exit or couldn't download required assets
|
||||
|
||||
FModel.initialize(splashScreen.getProgressBar());
|
||||
FModel.initialize(splashScreen.getProgressBar(), null);
|
||||
|
||||
splashScreen.getProgressBar().setDescription("Loading fonts...");
|
||||
FSkinFont.preloadAll();
|
||||
|
||||
@@ -56,6 +56,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* The default Model implementation for Forge.
|
||||
*
|
||||
@@ -91,7 +93,7 @@ public final class FModel {
|
||||
private static IStorage<QuestWorld> worlds;
|
||||
private static GameFormat.Collection formats;
|
||||
|
||||
public static void initialize(final IProgressBar progressBar) {
|
||||
public static void initialize(final IProgressBar progressBar, Function<ForgePreferences, Void> adjustPrefs) {
|
||||
ImageKeys.initializeDirs(
|
||||
ForgeConstants.CACHE_CARD_PICS_DIR, ForgeConstants.CACHE_CARD_PICS_SUBDIR,
|
||||
ForgeConstants.CACHE_TOKEN_PICS_DIR, ForgeConstants.CACHE_ICON_PICS_DIR,
|
||||
@@ -103,6 +105,9 @@ public final class FModel {
|
||||
// Preferences are initialized first so that the splash screen can be translated.
|
||||
try {
|
||||
preferences = new ForgePreferences();
|
||||
if (adjustPrefs != null) {
|
||||
adjustPrefs.apply(preferences);
|
||||
}
|
||||
GamePlayerUtil.getGuiPlayer().setName(preferences.getPref(FPref.PLAYER_NAME));
|
||||
}
|
||||
catch (final Exception exn) {
|
||||
|
||||
Reference in New Issue
Block a user