mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
Support creating custom gauntlet for mobile game
This commit is contained in:
@@ -85,7 +85,7 @@ public enum CSubmenuGauntletLoad implements ICDoc {
|
||||
}
|
||||
|
||||
private void updateData() {
|
||||
final File[] files = GauntletIO.getGauntletFilesUnlocked();
|
||||
final File[] files = GauntletIO.getGauntletFilesUnlocked(null);
|
||||
final List<GauntletData> data = new ArrayList<GauntletData>();
|
||||
|
||||
for (final File f : files) {
|
||||
|
||||
@@ -96,7 +96,7 @@ public class GauntletScreen extends LaunchScreen {
|
||||
}
|
||||
});
|
||||
|
||||
final File[] files = GauntletIO.getGauntletFilesUnlocked();
|
||||
final File[] files = GauntletIO.getGauntletFilesUnlocked(null);
|
||||
final List<GauntletData> data = new ArrayList<GauntletData>();
|
||||
|
||||
for (final File f : files) {
|
||||
@@ -131,7 +131,7 @@ public class GauntletScreen extends LaunchScreen {
|
||||
}
|
||||
|
||||
private void createQuickGauntlet() {
|
||||
GuiChoose.getInteger("How many opponents are you willing to face?", 5, 50, new Callback<Integer>() {
|
||||
GuiChoose.getInteger("How many opponents are you willing to face?", 3, 50, new Callback<Integer>() {
|
||||
@Override
|
||||
public void run(final Integer numOpponents) {
|
||||
if (numOpponents == null) { return; }
|
||||
@@ -148,7 +148,7 @@ public class GauntletScreen extends LaunchScreen {
|
||||
public void run(final List<DeckType> allowedDeckTypes) {
|
||||
if (allowedDeckTypes == null || allowedDeckTypes.isEmpty()) { return; }
|
||||
|
||||
FDeckChooser.promptForDeck("Select Deck for Gauntlet", GameType.Gauntlet, false, new Callback<Deck>() {
|
||||
FDeckChooser.promptForDeck("Select Your Deck", GameType.Gauntlet, false, new Callback<Deck>() {
|
||||
@Override
|
||||
public void run(Deck userDeck) {
|
||||
if (userDeck == null) { return; }
|
||||
@@ -165,7 +165,48 @@ public class GauntletScreen extends LaunchScreen {
|
||||
}
|
||||
|
||||
private void createCustomGauntlet() {
|
||||
|
||||
GuiChoose.getInteger("How many opponents are you willing to face?", 3, 50, new Callback<Integer>() {
|
||||
@Override
|
||||
public void run(final Integer numOpponents) {
|
||||
if (numOpponents == null) { return; }
|
||||
|
||||
GauntletData gauntlet = new GauntletData();
|
||||
gauntlet.setDecks(new ArrayList<Deck>());
|
||||
promptForAiDeck(gauntlet, numOpponents);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void promptForAiDeck(final GauntletData gauntlet, final int numOpponents) {
|
||||
final int opponentNum = gauntlet.getDecks().size() + 1;
|
||||
FDeckChooser.promptForDeck("Select Deck for Opponent " + opponentNum + " / " + numOpponents, GameType.Gauntlet, true, new Callback<Deck>() {
|
||||
@Override
|
||||
public void run(Deck aiDeck) {
|
||||
if (aiDeck == null) { return; }
|
||||
|
||||
gauntlet.getDecks().add(aiDeck);
|
||||
gauntlet.getEventNames().add(aiDeck.getName());
|
||||
|
||||
if (opponentNum < numOpponents) {
|
||||
promptForAiDeck(gauntlet, numOpponents);
|
||||
}
|
||||
else {
|
||||
//once all ai decks have been selected, prompt for user deck
|
||||
FDeckChooser.promptForDeck("Select Your Deck", GameType.Gauntlet, false, new Callback<Deck>() {
|
||||
@Override
|
||||
public void run(Deck userDeck) {
|
||||
if (userDeck == null) { return; }
|
||||
|
||||
gauntlet.setUserDeck(userDeck);
|
||||
GauntletUtil.setDefaultGauntletName(gauntlet, GauntletIO.PREFIX_CUSTOM);
|
||||
FModel.setGauntletData(gauntlet);
|
||||
gauntlet.reset();
|
||||
lstGauntlets.addGauntlet(gauntlet);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createGauntletContest() {
|
||||
|
||||
@@ -25,9 +25,11 @@ public class GauntletIO {
|
||||
/** Prompt in text field for new (unsaved) built gauntlets. */
|
||||
public static final String TXF_PROMPT = "[New Gauntlet]";
|
||||
/** suffix for all gauntlet data files */
|
||||
public static final String SUFFIX_DATA = ".dat";
|
||||
public static final String SUFFIX_DATA = ".dat";
|
||||
/** Prefix for quick gauntlet save files. */
|
||||
public static final String PREFIX_QUICK = "Quick_";
|
||||
/** Prefix for custom gauntlet save files. */
|
||||
public static final String PREFIX_CUSTOM = "Custom_";
|
||||
/** Regex for locked gauntlet save files. */
|
||||
public static final String PREFIX_LOCKED = "LOCKED_";
|
||||
|
||||
@@ -45,24 +47,12 @@ public class GauntletIO {
|
||||
public static File getGauntletFile(GauntletData gd) {
|
||||
return getGauntletFile(gd.getName());
|
||||
}
|
||||
|
||||
public static File[] getGauntletFilesUnlocked() {
|
||||
|
||||
public static File[] getGauntletFilesUnlocked(final String prefix) {
|
||||
final FilenameFilter filter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return (name.endsWith(SUFFIX_DATA));
|
||||
}
|
||||
};
|
||||
|
||||
File folder = new File(ForgeConstants.GAUNTLET_DIR.userPrefLoc);
|
||||
return folder.listFiles(filter);
|
||||
}
|
||||
|
||||
public static File[] getGauntletFilesQuick() {
|
||||
final FilenameFilter filter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return (name.startsWith(PREFIX_QUICK) && name.endsWith(SUFFIX_DATA));
|
||||
return ((prefix == null || name.startsWith(prefix)) && name.endsWith(SUFFIX_DATA));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -13,58 +13,64 @@ import forge.model.FModel;
|
||||
|
||||
public class GauntletUtil {
|
||||
public static GauntletData createQuickGauntlet(final Deck userDeck, final int numOpponents, final List<DeckType> allowedDeckTypes) {
|
||||
final File[] arrFiles = GauntletIO.getGauntletFilesQuick();
|
||||
final Set<String> setNames = new HashSet<String>();
|
||||
for (File f : arrFiles) {
|
||||
setNames.add(f.getName());
|
||||
}
|
||||
|
||||
int num = 1;
|
||||
while (setNames.contains(GauntletIO.PREFIX_QUICK + num + GauntletIO.SUFFIX_DATA)) { num++; }
|
||||
GauntletData gauntlet = new GauntletData();
|
||||
gauntlet.setName(GauntletIO.PREFIX_QUICK + num);
|
||||
setDefaultGauntletName(gauntlet, GauntletIO.PREFIX_QUICK);
|
||||
FModel.setGauntletData(gauntlet);
|
||||
|
||||
// Generate gauntlet decks
|
||||
final List<String> lstEventNames = new ArrayList<String>();
|
||||
final List<Deck> lstGauntletDecks = new ArrayList<Deck>();
|
||||
Deck tempDeck;
|
||||
Deck deck;
|
||||
final List<String> eventNames = new ArrayList<String>();
|
||||
final List<Deck> decks = new ArrayList<Deck>();
|
||||
|
||||
for (int i = 0; i < numOpponents; i++) {
|
||||
int randType = (int)Math.floor(Math.random() * allowedDeckTypes.size());
|
||||
switch (allowedDeckTypes.get(randType)) {
|
||||
case COLOR_DECK:
|
||||
tempDeck = DeckgenUtil.getRandomColorDeck(true);
|
||||
lstEventNames.add("Random colors deck");
|
||||
deck = DeckgenUtil.getRandomColorDeck(true);
|
||||
eventNames.add("Random colors deck");
|
||||
break;
|
||||
case CUSTOM_DECK:
|
||||
tempDeck = DeckgenUtil.getRandomCustomDeck();
|
||||
lstEventNames.add(tempDeck.getName());
|
||||
deck = DeckgenUtil.getRandomCustomDeck();
|
||||
eventNames.add(deck.getName());
|
||||
break;
|
||||
case PRECONSTRUCTED_DECK:
|
||||
tempDeck = DeckgenUtil.getRandomPreconDeck();
|
||||
lstEventNames.add(tempDeck.getName());
|
||||
deck = DeckgenUtil.getRandomPreconDeck();
|
||||
eventNames.add(deck.getName());
|
||||
break;
|
||||
case QUEST_OPPONENT_DECK:
|
||||
tempDeck = DeckgenUtil.getRandomQuestDeck();
|
||||
lstEventNames.add(tempDeck.getName());
|
||||
deck = DeckgenUtil.getRandomQuestDeck();
|
||||
eventNames.add(deck.getName());
|
||||
break;
|
||||
case THEME_DECK:
|
||||
tempDeck = DeckgenUtil.getRandomThemeDeck();
|
||||
lstEventNames.add(tempDeck.getName());
|
||||
deck = DeckgenUtil.getRandomThemeDeck();
|
||||
eventNames.add(deck.getName());
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
lstGauntletDecks.add(tempDeck);
|
||||
decks.add(deck);
|
||||
}
|
||||
|
||||
gauntlet.setDecks(lstGauntletDecks);
|
||||
gauntlet.setEventNames(lstEventNames);
|
||||
gauntlet.setDecks(decks);
|
||||
gauntlet.setEventNames(eventNames);
|
||||
gauntlet.setUserDeck(userDeck);
|
||||
|
||||
// Reset all variable fields to 0, stamps and saves automatically.
|
||||
gauntlet.reset();
|
||||
return gauntlet;
|
||||
}
|
||||
|
||||
public static void setDefaultGauntletName(GauntletData gauntlet, String prefix) {
|
||||
final File[] arrFiles = GauntletIO.getGauntletFilesUnlocked(prefix);
|
||||
final Set<String> setNames = new HashSet<String>();
|
||||
for (File f : arrFiles) {
|
||||
setNames.add(f.getName());
|
||||
}
|
||||
|
||||
int num = 1;
|
||||
while (setNames.contains(prefix + num + GauntletIO.SUFFIX_DATA)) {
|
||||
num++;
|
||||
}
|
||||
gauntlet.setName(prefix + num);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user