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 "";
}
private JFileChooser fcJumpstartSelectDeck = null;
protected String playerLoadJumpstartPacks() {
if (fcSelectDeck == null) {
fcSelectDeck = new JFileChooser();
fcSelectDeck.setAcceptAllFileFilterUsed(false);
fcSelectDeck.addChoosableFileFilter(new DeckFileFilter("txt", "Jumpstart Packs (*.txt)"));
if (fcJumpstartSelectDeck == null) {
fcJumpstartSelectDeck = new JFileChooser();
fcJumpstartSelectDeck.setAcceptAllFileFilterUsed(false);
fcJumpstartSelectDeck.addChoosableFileFilter(new DeckFileFilter("txt", "Jumpstart Packs (*.txt)"));
}
String lastFolder = MageFrame.getPreferences().get("lastDeckFolder", "");
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) {
File file = fcSelectDeck.getSelectedFile();
File file = fcJumpstartSelectDeck.getSelectedFile();
return (file.getPath());
}
return "";
@ -1234,6 +1236,10 @@ public class NewTournamentDialog extends MageDialog {
String jumpstartPacksData = "";
try {
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) {
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
*/
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 {
CharSource source;
if (useDefault) {
@ -77,19 +82,19 @@ public class JumpstartPoolGenerator {
}
}
}
JUMPSTART_PACKS = Collections.unmodifiableList(packs);
return packs;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
private static Set<Card> doGeneratePool() {
private static Set<Card> doGeneratePool(List<JumpstartPack> packs) {
try {
DeckCardLists list = new DeckCardLists();
SecureRandom random = new SecureRandom();
for (int i = 0; i < 2; i++) {
int index = random.nextInt(JUMPSTART_PACKS.size());
list.getCards().addAll(JUMPSTART_PACKS.get(index).getCards());
int index = random.nextInt(packs.size());
list.getCards().addAll(packs.get(index).getCards());
}
return Deck.load(list, false, false).getCards();
} catch (GameException e) {
@ -111,13 +116,15 @@ public class JumpstartPoolGenerator {
* https://mtg.gamepedia.com/Jumpstart#Marketing
*/
public static Set<Card> generatePool() {
setupPacks("", true);
return doGeneratePool();
return doGeneratePool(JUMPSTART_PACKS);
}
public static Set<Card> generatePool(String userJumpstartPacks) {
setupPacks(userJumpstartPacks, false);
return doGeneratePool();
if (userJumpstartPacks == null || userJumpstartPacks.length() > 300000) {
return generatePool();
}
List<JumpstartPack> packs = getPacks(userJumpstartPacks, false);
return doGeneratePool(packs);
}
public static class JumpstartPack {