Moved formats into single files with new "Order", "Core" and "Name" properties.

This commit is contained in:
austinio7116
2018-03-30 21:57:13 +01:00
committed by maustin
parent 3810475ee8
commit c78d235b07
13 changed files with 88 additions and 47 deletions

View File

@@ -32,16 +32,20 @@ import forge.deck.Deck;
import forge.item.IPaperCard; import forge.item.IPaperCard;
import forge.item.PaperCard; import forge.item.PaperCard;
import forge.util.FileSection; import forge.util.FileSection;
import forge.util.FileUtil;
import forge.util.storage.StorageBase; import forge.util.storage.StorageBase;
import forge.util.storage.StorageReaderFileSections; import forge.util.storage.StorageReaderFileSections;
import forge.util.storage.StorageReaderFolder;
import java.io.File; import java.io.File;
import java.io.FilenameFilter;
import java.util.*; import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
public class GameFormat implements Comparable<GameFormat> { public class GameFormat implements Comparable<GameFormat> {
private final String name; private final String name;
private final Boolean isCore;
// contains allowed sets, when empty allows all sets // contains allowed sets, when empty allows all sets
protected final List<String> allowedSetCodes; // this is mutable to support quest mode set unlocks protected final List<String> allowedSetCodes; // this is mutable to support quest mode set unlocks
@@ -59,14 +63,15 @@ public class GameFormat implements Comparable<GameFormat> {
private final int index; private final int index;
public GameFormat(final String fName, final Iterable<String> sets, final List<String> bannedCards) { public GameFormat(final String fName, final Iterable<String> sets, final List<String> bannedCards) {
this(fName, sets, bannedCards, null, null, 0); this(fName, sets, bannedCards, null, null, 0, false);
} }
public static final GameFormat NoFormat = new GameFormat("(none)", null, null, null, null, Integer.MAX_VALUE); public static final GameFormat NoFormat = new GameFormat("(none)", null, null, null, null, Integer.MAX_VALUE, false);
public GameFormat(final String fName, final Iterable<String> sets, final List<String> bannedCards, public GameFormat(final String fName, final Iterable<String> sets, final List<String> bannedCards,
final List<String> restrictedCards, final List<CardRarity> rarities, int compareIdx) { final List<String> restrictedCards, final List<CardRarity> rarities, int compareIdx, Boolean isCore) {
this.index = compareIdx; this.index = compareIdx;
this.isCore = isCore;
this.name = fName; this.name = fName;
allowedSetCodes = sets == null ? new ArrayList<String>() : Lists.newArrayList(sets); allowedSetCodes = sets == null ? new ArrayList<String>() : Lists.newArrayList(sets);
bannedCardNames = bannedCards == null ? new ArrayList<String>() : Lists.newArrayList(bannedCards); bannedCardNames = bannedCards == null ? new ArrayList<String>() : Lists.newArrayList(bannedCards);
@@ -109,6 +114,10 @@ public class GameFormat implements Comparable<GameFormat> {
return this.name; return this.name;
} }
public Boolean isCore() {
return this.isCore;
}
public List<String> getAllowedSetCodes() { public List<String> getAllowedSetCodes() {
return this.allowedSetCodes_ro; return this.allowedSetCodes_ro;
} }
@@ -199,7 +208,7 @@ public class GameFormat implements Comparable<GameFormat> {
return index; return index;
} }
public static class Reader extends StorageReaderFileSections<GameFormat> { public static class Reader extends StorageReaderFolder<GameFormat> {
List<GameFormat> naturallyOrdered = new ArrayList<GameFormat>(); List<GameFormat> naturallyOrdered = new ArrayList<GameFormat>();
public Reader(File file0) { public Reader(File file0) {
@@ -207,12 +216,16 @@ public class GameFormat implements Comparable<GameFormat> {
} }
@Override @Override
protected GameFormat read(String title, Iterable<String> body, int idx) { protected GameFormat read(File file) {
final Map<String, List<String>> contents = FileSection.parseSections(FileUtil.readFile(file));
List<String> sets = null; // default: all sets allowed List<String> sets = null; // default: all sets allowed
List<String> bannedCards = null; // default: nothing banned List<String> bannedCards = null; // default: nothing banned
List<String> restrictedCards = null; // default: nothing restricted List<String> restrictedCards = null; // default: nothing restricted
List<CardRarity> rarities = null; List<CardRarity> rarities = null;
FileSection section = FileSection.parse(body, ":"); FileSection section = FileSection.parse(contents.get("format"), ":");
String title = section.get("name");
Boolean isCore = section.getBoolean("core");
Integer idx = section.getInt("order");
String strSets = section.get("sets"); String strSets = section.get("sets");
if ( null != strSets ) { if ( null != strSets ) {
sets = Arrays.asList(strSets.split(", ")); sets = Arrays.asList(strSets.split(", "));
@@ -239,10 +252,22 @@ public class GameFormat implements Comparable<GameFormat> {
} }
} }
GameFormat result = new GameFormat(title, sets, bannedCards, restrictedCards, rarities, 1 + idx); GameFormat result = new GameFormat(title, sets, bannedCards, restrictedCards, rarities, idx, isCore);
naturallyOrdered.add(result); naturallyOrdered.add(result);
return result; return result;
} }
@Override
protected FilenameFilter getFileFilter() {
return TXT_FILE_FILTER;
}
public static final FilenameFilter TXT_FILE_FILTER = new FilenameFilter() {
@Override
public boolean accept(final File dir, final String name) {
return name.endsWith(".txt");
}
};
} }
public static class Collection extends StorageBase<GameFormat> { public static class Collection extends StorageBase<GameFormat> {
@@ -251,12 +276,23 @@ public class GameFormat implements Comparable<GameFormat> {
public Collection(GameFormat.Reader reader) { public Collection(GameFormat.Reader reader) {
super("Format collections", reader); super("Format collections", reader);
naturallyOrdered = reader.naturallyOrdered; naturallyOrdered = reader.naturallyOrdered;
Collections.sort(naturallyOrdered);
} }
public Iterable<GameFormat> getOrderedList() { public Iterable<GameFormat> getOrderedList() {
return naturallyOrdered; return naturallyOrdered;
} }
public Iterable<GameFormat> getCoreList() {
List<GameFormat> coreList = new ArrayList<>();
for(GameFormat format: naturallyOrdered){
if(format.isCore()){
coreList.add(format);
}
}
return coreList;
}
public GameFormat getStandard() { public GameFormat getStandard() {
return this.map.get("Standard"); return this.map.get("Standard");
} }

View File

@@ -0,0 +1,4 @@
[format]
Name:Commander
Order:106
Banned:Adriana's Valor; Advantageous Proclamation; Ashnod's Coupon; Assemble the Rank and Vile; Backup Plan; Brago's Favor; Double Cross; Double Deal; Double Dip; Double Play; Double Stroke; Double Take; Echoing Boon; Emissary's Ploy; Enter the Dungeon; Hired Heist; Hold the Perimeter; Hymn of the Wilds; Immediate Action; Incendiary Dissent; Iterative Analysis; Magical Hacker; Mox Lotus; Muzzio's Preparations; Natural Unity; Once More with Feeling; Power Play; R&D's Secret Lair; Richard Garfield, Ph.D.; Secret Summoning; Secrets of Paradise; Sentinel Dispatch; Sovereign's Realm; Staying Power; Summoner's Bond; Time Machine; Unexpected Potential; Weight Advantage; Worldknit; Amulet of Quoz; Bronze Tablet; Contract from Below; Darkpact; Demonic Attorney; Jeweled Bird; Rebirth; Tempest Efreet; Timmerian Fiends; Ancestral Recall; Balance; Biorhythm; Black Lotus; Braids, Cabal Minion; Chaos Orb; Coalition Victory; Channel; Emrakul, the Aeons Torn; Erayo, Soratami Ascendant; Falling Star; Fastbond; Gifts Ungiven; Griselbrand; Karakas; Leovold, Emissary of Trest; Library of Alexandria; Limited Resources; Mox Emerald; Mox Jet; Mox Pearl; Mox Ruby; Mox Sapphire; Painter's Servant; Panoptic Mirror; Primeval Titan; Prophet of Kruphix; Recurring Nightmare; Rofellos, Llanowar Emissary; Shahrazad; Staying Power; Sundering Titan; Sway of the Stars; Sylvan Primordial; Time Machine; Time Vault; Time Walk; Tinker; Tolarian Academy; Trade Secrets; Upheaval; Worldfire; Yawgmoth's Bargain

View File

@@ -0,0 +1,6 @@
[format]
Name:Extended
Order:107
Core:true
Sets:SOM, MBS, NPH, M12, ISD, DKA, AVR, M13, RTR, GTC, DGM, M14, THS, BNG, JOU, M15
Banned:Ponder; Mental Misstep

View File

@@ -0,0 +1,5 @@
[format]
Name:Kaladesh Block
Order:109
Core:true
Sets:KLD, AER

View File

@@ -0,0 +1,5 @@
[format]
Name:Legacy
Order:105
Core:true
Banned:Adriana's Valor; Advantageous Proclamation; Assemble the Rank and Vile; Backup Plan; Brago's Favor; Double Stroke; Echoing Boon; Emissary's Ploy; Hired Heist; Hold the Perimeter; Hymn of the Wilds; Immediate Action; Incendiary Dissent; Iterative Analysis; Muzzio's Preparations; Natural Unity; Power Play; Secret Summoning; Secrets of Paradise; Sentinel Dispatch; Sovereign's Realm; Summoner's Bond; Unexpected Potential; Weight Advantage; Worldknit; Amulet of Quoz; Bronze Tablet; Contract from Below; Darkpact; Demonic Attorney; Jeweled Bird; Rebirth; Tempest Efreet; Timmerian Fiends; Ancestral Recall; Balance; Bazaar of Baghdad; Black Lotus; Channel; Chaos Orb; Demonic Consultation; Demonic Tutor; Dig Through Time; Earthcraft; Falling Star; Fastbond; Flash; Frantic Search; Goblin Recruiter; Gush; Hermit Druid; Imperial Seal; Library of Alexandria; Mana Crypt; Mana Drain; Mana Vault; Memory Jar; Mental Misstep; Mind Twist; Mind's Desire; Mishra's Workshop; Mox Emerald; Mox Jet; Mox Pearl; Mox Ruby; Mox Sapphire; Mystical Tutor; Necropotence; Oath of Druids; Sensei's Divining Top; Shahrazad; Skullclamp; Sol Ring; Strip Mine; Survival of the Fittest; Time Vault; Time Walk; Timetwister; Tinker; Tolarian Academy; Treasure Cruise; Vampiric Tutor; Wheel of Fortune; Windfall; Yawgmoth's Bargain; Yawgmoth's Will

View File

@@ -0,0 +1,6 @@
[format]
Name:Modern
Order:102
Core:true
Sets:8ED, MRD, DST, 5DN, CHK, BOK, SOK, 9ED, RAV, GPT, DIS, CSP, TSP, TSB, PLC, FUT, 10E, LRW, EVE, SHM, MOR, ALA, CFX, ARB, M10, ZEN, WWK, ROE, M11, SOM, MBS, NPH, M12, ISD, DKA, AVR, M13, RTR, GTC, DGM, M14, THS, BNG, JOU, M15, KTK, FRF, DTK, MM2, ORI, BFZ, OGW, SOI, EMN, KLD, AER, AKH, W17, HOU, XLN, RIX
Banned:Ancient Den; Birthing Pod; Blazing Shoal; Chrome Mox; Cloudpost; Dark Depths; Deathrite Shaman; Dig Through Time; Dread Return; Eye of Ugin; Gitaxian Probe; Glimpse of Nature; Golgari Grave-Troll; Great Furnace; Green Sun's Zenith; Hypergenesis; Mental Misstep; Ponder; Preordain; Punishing Fire; Rite of Flame; Seat of the Synod; Second Sunrise; Seething Song; Sensei's Divining Top; Skullclamp; Splinter Twin; Stoneforge Mystic; Summer Bloom; Treasure Cruise; Tree of Tales; Umezawa's Jitte; Vault of Whispers

View File

@@ -0,0 +1,7 @@
[format]
Name:Vintage
Order:104
Core:true
Banned:Adriana's Valor; Advantageous Proclamation; Assemble the Rank and Vile; Backup Plan; Brago's Favor; Double Stroke; Echoing Boon; Emissary's Ploy; Hired Heist; Hold the Perimeter; Hymn of the Wilds; Immediate Action; Incendiary Dissent; Iterative Analysis; Muzzio's Preparations; Natural Unity; Power Play; Secret Summoning; Secrets of Paradise; Sentinel Dispatch; Sovereign's Realm; Summoner's Bond; Unexpected Potential; Weight Advantage; Worldknit; Amulet of Quoz; Bronze Tablet; Contract from Below; Darkpact; Demonic Attorney; Jeweled Bird; Rebirth; Tempest Efreet; Timmerian Fiends; Chaos Orb; Falling Star; Shahrazad
Restricted:Ancestral Recall; Balance; Black Lotus; Brainstorm; Chalice of the Void; Channel; Demonic Consultation; Demonic Tutor; Dig Through Time; Fastbond; Flash; Gitaxian Probe; Gush; Imperial Seal; Library of Alexandria; Lion's Eye Diamond; Lodestone Golem; Lotus Petal; Mana Crypt; Mana Vault; Memory Jar; Merchant Scroll; Mind's Desire; Monastery Mentor; Mox Emerald; Mox Jet; Mox Pearl; Mox Ruby; Mox Sapphire; Mystical Tutor; Necropotence; Ponder; Sol Ring; Strip Mine; Thorn of Amethyst; Time Vault; Time Walk; Timetwister; Tinker; Tolarian Academy; Treasure Cruise; Trinisphere; Vampiric Tutor; Wheel of Fortune; Windfall; Yawgmoth's Will

View File

@@ -1,2 +0,0 @@
[Kaladesh_Block]
Sets:KLD, AER

View File

@@ -1,21 +0,0 @@
[Standard]
Sets:KLD, AER, AKH, W17, HOU, XLN, RIX
Banned: Attune with Aether; Rogue Refiner; Rampaging Ferocidon; Ramunap Ruins; Smuggler's Copter; Aetherworks Marvel; Felidar Guardian
[Modern]
Sets:8ED, MRD, DST, 5DN, CHK, BOK, SOK, 9ED, RAV, GPT, DIS, CSP, TSP, TSB, PLC, FUT, 10E, LRW, EVE, SHM, MOR, ALA, CFX, ARB, M10, ZEN, WWK, ROE, M11, SOM, MBS, NPH, M12, ISD, DKA, AVR, M13, RTR, GTC, DGM, M14, THS, BNG, JOU, M15, KTK, FRF, DTK, MM2, ORI, BFZ, OGW, SOI, EMN, KLD, AER, AKH, W17, HOU, XLN, RIX
Banned:Ancient Den; Birthing Pod; Blazing Shoal; Chrome Mox; Cloudpost; Dark Depths; Deathrite Shaman; Dig Through Time; Dread Return; Eye of Ugin; Gitaxian Probe; Glimpse of Nature; Golgari Grave-Troll; Great Furnace; Green Sun's Zenith; Hypergenesis; Mental Misstep; Ponder; Preordain; Punishing Fire; Rite of Flame; Seat of the Synod; Second Sunrise; Seething Song; Sensei's Divining Top; Skullclamp; Splinter Twin; Stoneforge Mystic; Summer Bloom; Treasure Cruise; Tree of Tales; Umezawa's Jitte; Vault of Whispers
[Vintage]
Banned:Adriana's Valor; Advantageous Proclamation; Assemble the Rank and Vile; Backup Plan; Brago's Favor; Double Stroke; Echoing Boon; Emissary's Ploy; Hired Heist; Hold the Perimeter; Hymn of the Wilds; Immediate Action; Incendiary Dissent; Iterative Analysis; Muzzio's Preparations; Natural Unity; Power Play; Secret Summoning; Secrets of Paradise; Sentinel Dispatch; Sovereign's Realm; Summoner's Bond; Unexpected Potential; Weight Advantage; Worldknit; Amulet of Quoz; Bronze Tablet; Contract from Below; Darkpact; Demonic Attorney; Jeweled Bird; Rebirth; Tempest Efreet; Timmerian Fiends; Chaos Orb; Falling Star; Shahrazad
Restricted:Ancestral Recall; Balance; Black Lotus; Brainstorm; Chalice of the Void; Channel; Demonic Consultation; Demonic Tutor; Dig Through Time; Fastbond; Flash; Gitaxian Probe; Gush; Imperial Seal; Library of Alexandria; Lion's Eye Diamond; Lodestone Golem; Lotus Petal; Mana Crypt; Mana Vault; Memory Jar; Merchant Scroll; Mind's Desire; Monastery Mentor; Mox Emerald; Mox Jet; Mox Pearl; Mox Ruby; Mox Sapphire; Mystical Tutor; Necropotence; Ponder; Sol Ring; Strip Mine; Thorn of Amethyst; Time Vault; Time Walk; Timetwister; Tinker; Tolarian Academy; Treasure Cruise; Trinisphere; Vampiric Tutor; Wheel of Fortune; Windfall; Yawgmoth's Will
[Legacy]
Banned:Adriana's Valor; Advantageous Proclamation; Assemble the Rank and Vile; Backup Plan; Brago's Favor; Double Stroke; Echoing Boon; Emissary's Ploy; Hired Heist; Hold the Perimeter; Hymn of the Wilds; Immediate Action; Incendiary Dissent; Iterative Analysis; Muzzio's Preparations; Natural Unity; Power Play; Secret Summoning; Secrets of Paradise; Sentinel Dispatch; Sovereign's Realm; Summoner's Bond; Unexpected Potential; Weight Advantage; Worldknit; Amulet of Quoz; Bronze Tablet; Contract from Below; Darkpact; Demonic Attorney; Jeweled Bird; Rebirth; Tempest Efreet; Timmerian Fiends; Ancestral Recall; Balance; Bazaar of Baghdad; Black Lotus; Channel; Chaos Orb; Demonic Consultation; Demonic Tutor; Dig Through Time; Earthcraft; Falling Star; Fastbond; Flash; Frantic Search; Goblin Recruiter; Gush; Hermit Druid; Imperial Seal; Library of Alexandria; Mana Crypt; Mana Drain; Mana Vault; Memory Jar; Mental Misstep; Mind Twist; Mind's Desire; Mishra's Workshop; Mox Emerald; Mox Jet; Mox Pearl; Mox Ruby; Mox Sapphire; Mystical Tutor; Necropotence; Oath of Druids; Sensei's Divining Top; Shahrazad; Skullclamp; Sol Ring; Strip Mine; Survival of the Fittest; Time Vault; Time Walk; Timetwister; Tinker; Tolarian Academy; Treasure Cruise; Vampiric Tutor; Wheel of Fortune; Windfall; Yawgmoth's Bargain; Yawgmoth's Will
[Commander]
Banned:Adriana's Valor; Advantageous Proclamation; Ashnod's Coupon; Assemble the Rank and Vile; Backup Plan; Brago's Favor; Double Cross; Double Deal; Double Dip; Double Play; Double Stroke; Double Take; Echoing Boon; Emissary's Ploy; Enter the Dungeon; Hired Heist; Hold the Perimeter; Hymn of the Wilds; Immediate Action; Incendiary Dissent; Iterative Analysis; Magical Hacker; Mox Lotus; Muzzio's Preparations; Natural Unity; Once More with Feeling; Power Play; R&D's Secret Lair; Richard Garfield, Ph.D.; Secret Summoning; Secrets of Paradise; Sentinel Dispatch; Sovereign's Realm; Staying Power; Summoner's Bond; Time Machine; Unexpected Potential; Weight Advantage; Worldknit; Amulet of Quoz; Bronze Tablet; Contract from Below; Darkpact; Demonic Attorney; Jeweled Bird; Rebirth; Tempest Efreet; Timmerian Fiends; Ancestral Recall; Balance; Biorhythm; Black Lotus; Braids, Cabal Minion; Chaos Orb; Coalition Victory; Channel; Emrakul, the Aeons Torn; Erayo, Soratami Ascendant; Falling Star; Fastbond; Gifts Ungiven; Griselbrand; Karakas; Leovold, Emissary of Trest; Library of Alexandria; Limited Resources; Mox Emerald; Mox Jet; Mox Pearl; Mox Ruby; Mox Sapphire; Painter's Servant; Panoptic Mirror; Primeval Titan; Prophet of Kruphix; Recurring Nightmare; Rofellos, Llanowar Emissary; Shahrazad; Staying Power; Sundering Titan; Sway of the Stars; Sylvan Primordial; Time Machine; Time Vault; Time Walk; Tinker; Tolarian Academy; Trade Secrets; Upheaval; Worldfire; Yawgmoth's Bargain
[Extended]
Sets:SOM, MBS, NPH, M12, ISD, DKA, AVR, M13, RTR, GTC, DGM, M14, THS, BNG, JOU, M15
Banned:Ponder; Mental Misstep

View File

@@ -1,2 +1,5 @@
[Pauper] [format]
Name:Pauper
Order:108
Core:true
Rarities:L, C Rarities:L, C

View File

@@ -0,0 +1,6 @@
[format]
Name:Standard
Order:101
Core:true
Sets:KLD, AER, AKH, W17, HOU, XLN, RIX
Banned: Attune with Aether; Rogue Refiner; Rampaging Ferocidon; Ramunap Ruins; Smuggler's Copter; Aetherworks Marvel; Felidar Guardian

View File

@@ -166,21 +166,7 @@ public final class FModel {
ForgePreferences.DEV_MODE = preferences.getPrefBoolean(FPref.DEV_MODE_ENABLED); ForgePreferences.DEV_MODE = preferences.getPrefBoolean(FPref.DEV_MODE_ENABLED);
ForgePreferences.UPLOAD_DRAFT = ForgePreferences.NET_CONN; ForgePreferences.UPLOAD_DRAFT = ForgePreferences.NET_CONN;
formats = new GameFormat.Collection(new GameFormat.Reader( new File(ForgeConstants.FORMATS_DATA_DIR + "coreformats.txt"))); formats = new GameFormat.Collection(new GameFormat.Reader( new File(ForgeConstants.FORMATS_DATA_DIR)));
final File[] files = new File(ForgeConstants.FORMATS_DATA_DIR).listFiles();
for (final File file : files) {
if (!file.getName().equals("coreformats.txt")){
GameFormat.Collection additionalformats = new GameFormat.Collection(new GameFormat.Reader(file));
for (GameFormat format:additionalformats) {
formats.add(format);
}
}
}
//still support old user custom formats if file present
GameFormat.Collection customFormats = new GameFormat.Collection(new GameFormat.Reader(new File(ForgeConstants.USER_PREFS_DIR + "customformats.txt")));
for (GameFormat format:customFormats){
formats.add(format);
}
magicDb.setStandardPredicate(formats.getStandard().getFilterRules()); magicDb.setStandardPredicate(formats.getStandard().getFilterRules());
magicDb.setModernPredicate(formats.getModern().getFilterRules()); magicDb.setModernPredicate(formats.getModern().getFilterRules());

View File

@@ -63,7 +63,7 @@ public final class GameFormatQuest extends GameFormat {
*/ */
public GameFormatQuest(final GameFormat toCopy, boolean allowSetUnlocks) { public GameFormatQuest(final GameFormat toCopy, boolean allowSetUnlocks) {
super(toCopy.getName(), toCopy.getAllowedSetCodes(), toCopy.getBannedCardNames(), toCopy.getRestrictedCards(), super(toCopy.getName(), toCopy.getAllowedSetCodes(), toCopy.getBannedCardNames(), toCopy.getRestrictedCards(),
toCopy.getAllowedRarities(), toCopy.getIndex()); toCopy.getAllowedRarities(), toCopy.getIndex(), false);
allowUnlocks = allowSetUnlocks; allowUnlocks = allowSetUnlocks;
} }