Adding in Jumpstart Custom (requested fixes)

This commit is contained in:
spjspj 2021-02-06 00:19:36 +11:00
parent 1e428105d5
commit b64806606c
2 changed files with 30 additions and 17 deletions

View file

@ -785,19 +785,21 @@ public class NewTournamentDialog extends MageDialog {
return ""; return "";
} }
private JFileChooser fcJumpstartSelectDeck = null;
protected String playerLoadJumpstartPacks() { protected String playerLoadJumpstartPacks() {
if (fcSelectDeck == null) { if (fcJumpstartSelectDeck == null) {
fcSelectDeck = new JFileChooser(); fcJumpstartSelectDeck = new JFileChooser();
fcSelectDeck.setAcceptAllFileFilterUsed(false); fcJumpstartSelectDeck.setAcceptAllFileFilterUsed(false);
fcSelectDeck.addChoosableFileFilter(new DeckFileFilter("txt", "Jumpstart Packs (*.txt)")); fcJumpstartSelectDeck.addChoosableFileFilter(new DeckFileFilter("txt", "Jumpstart Packs (*.txt)"));
} }
String lastFolder = MageFrame.getPreferences().get("lastDeckFolder", ""); String lastFolder = MageFrame.getPreferences().get("lastDeckFolder", "");
if (!lastFolder.isEmpty()) { if (!lastFolder.isEmpty()) {
fcSelectDeck.setCurrentDirectory(new File(lastFolder)); fcJumpstartSelectDeck.setCurrentDirectory(new File(lastFolder));
} }
int ret = fcSelectDeck.showDialog(this, "Select Jumpstart Packs file"); int ret = fcJumpstartSelectDeck.showDialog(this, "Select Jumpstart Packs file");
if (ret == JFileChooser.APPROVE_OPTION) { if (ret == JFileChooser.APPROVE_OPTION) {
File file = fcSelectDeck.getSelectedFile(); File file = fcJumpstartSelectDeck.getSelectedFile();
return (file.getPath()); return (file.getPath());
} }
return ""; return "";
@ -1234,6 +1236,10 @@ public class NewTournamentDialog extends MageDialog {
String jumpstartPacksData = ""; String jumpstartPacksData = "";
try { try {
jumpstartPacksData = new String(Files.readAllBytes(Paths.get(jumpstartPacksFilename))); jumpstartPacksData = new String(Files.readAllBytes(Paths.get(jumpstartPacksFilename)));
if (jumpstartPacksData.length() > 300000) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Chosen file too big", "Jumpstart Packs data is too long. Please trim or choose another file.", JOptionPane.ERROR_MESSAGE);
jumpstartPacksData = "";
}
} catch (IOException e2) { } catch (IOException e2) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), e2.getMessage(), "Error loading Jumpstart Packs data", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(MageFrame.getDesktop(), e2.getMessage(), "Error loading Jumpstart Packs data", JOptionPane.ERROR_MESSAGE);
} }

View file

@ -48,9 +48,14 @@ public class JumpstartPoolGenerator {
* Deck Lists: https://magic.wizards.com/en/articles/archive/feature/jumpstart-decklists-2020-06-18 * Deck Lists: https://magic.wizards.com/en/articles/archive/feature/jumpstart-decklists-2020-06-18
*/ */
private static final String RESOURCE_NAME = "jumpstart/jumpstart.txt"; private static final String RESOURCE_NAME = "jumpstart/jumpstart.txt";
private static List<JumpstartPack> JUMPSTART_PACKS; private static final List<JumpstartPack> JUMPSTART_PACKS;
private static void setupPacks(String jumpstartPacks, boolean useDefault) { static {
List<JumpstartPack> packs = getPacks ("", true);
JUMPSTART_PACKS = Collections.unmodifiableList(packs);
}
private static List<JumpstartPack> getPacks(String jumpstartPacks, boolean useDefault) {
try { try {
CharSource source; CharSource source;
if (useDefault) { if (useDefault) {
@ -77,19 +82,19 @@ public class JumpstartPoolGenerator {
} }
} }
} }
JUMPSTART_PACKS = Collections.unmodifiableList(packs); return packs;
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
} }
private static Set<Card> doGeneratePool() { private static Set<Card> doGeneratePool(List<JumpstartPack> packs) {
try { try {
DeckCardLists list = new DeckCardLists(); DeckCardLists list = new DeckCardLists();
SecureRandom random = new SecureRandom(); SecureRandom random = new SecureRandom();
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
int index = random.nextInt(JUMPSTART_PACKS.size()); int index = random.nextInt(packs.size());
list.getCards().addAll(JUMPSTART_PACKS.get(index).getCards()); list.getCards().addAll(packs.get(index).getCards());
} }
return Deck.load(list, false, false).getCards(); return Deck.load(list, false, false).getCards();
} catch (GameException e) { } catch (GameException e) {
@ -111,13 +116,15 @@ public class JumpstartPoolGenerator {
* https://mtg.gamepedia.com/Jumpstart#Marketing * https://mtg.gamepedia.com/Jumpstart#Marketing
*/ */
public static Set<Card> generatePool() { public static Set<Card> generatePool() {
setupPacks("", true); return doGeneratePool(JUMPSTART_PACKS);
return doGeneratePool();
} }
public static Set<Card> generatePool(String userJumpstartPacks) { public static Set<Card> generatePool(String userJumpstartPacks) {
setupPacks(userJumpstartPacks, false); if (userJumpstartPacks == null || userJumpstartPacks.length() > 300000) {
return doGeneratePool(); return generatePool();
}
List<JumpstartPack> packs = getPacks(userJumpstartPacks, false);
return doGeneratePool(packs);
} }
public static class JumpstartPack { public static class JumpstartPack {