mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Simplify reading of region and events files
This commit is contained in:
@@ -92,6 +92,16 @@ public class FCollection<T> implements List<T>, Set<T>, FCollectionView<T>, Clon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an {@link FCollection} from an {@link FCollectionReader}.
|
||||||
|
*
|
||||||
|
* @param reader
|
||||||
|
* a reader used to populate collection
|
||||||
|
*/
|
||||||
|
public FCollection(final FCollectionReader<T> reader) {
|
||||||
|
reader.readAll(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether an {@link Iterable} contains any iterable, silently
|
* Check whether an {@link Iterable} contains any iterable, silently
|
||||||
* returning {@code false} when {@code null} is passed as an argument.
|
* returning {@code false} when {@code null} is passed as an argument.
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ Name:Bant Renowned|Deck:Bant Renowned.dck|Variant:None|Avatar:Citadel Castellan|
|
|||||||
Name:Bant Top Cards|Deck:Bant Top Cards.dck|Variant:None|Avatar:Noble Hierarch|Desc:
|
Name:Bant Top Cards|Deck:Bant Top Cards.dck|Variant:None|Avatar:Noble Hierarch|Desc:
|
||||||
Name:Roon of the Hidden Realm|Deck:Roon of the Hidden Realm.dck|Variant:Commander|Avatar:Roon of the Hidden Realm|Desc:
|
Name:Roon of the Hidden Realm|Deck:Roon of the Hidden Realm.dck|Variant:Commander|Avatar:Roon of the Hidden Realm|Desc:
|
||||||
Name:Derevi, Empyrial Tactician|Deck:Derevi, Empyrial Tactician.dck|Variant:Commander|Avatar:Derevi, Empyrial Tactician|Desc:
|
Name:Derevi, Empyrial Tactician|Deck:Derevi, Empyrial Tactician.dck|Variant:Commander|Avatar:Derevi, Empyrial Tactician|Desc:
|
||||||
Name:Gwafa Hazid, Profiteer|Deck:Gwafa Hazid, Profiteer.dck|Variant:Commander|Avatar:Gwafa Hazid, Profiteer|Desc:
|
|
||||||
Name:Jenara, Asura of War|Deck:Jenara, Asura of War.dck|Variant:Commander|Avatar:Jenara, Asura of War|Desc:
|
Name:Jenara, Asura of War|Deck:Jenara, Asura of War.dck|Variant:Commander|Avatar:Jenara, Asura of War|Desc:
|
||||||
Name:Rafiq of the Many|Deck:Rafiq of the Many.dck|Variant:Commander|Avatar:Rafiq of the Many|Desc:
|
Name:Rafiq of the Many|Deck:Rafiq of the Many.dck|Variant:Commander|Avatar:Rafiq of the Many|Desc:
|
||||||
Name:Dauntless Escort Vanguard|Deck:Dauntless Escort Vanguard.dck|Variant:Vanguard|Avatar:Dauntless Escort|Desc:
|
Name:Dauntless Escort Vanguard|Deck:Dauntless Escort Vanguard.dck|Variant:Vanguard|Avatar:Dauntless Escort|Desc:
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import java.io.File;
|
|||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
|
|
||||||
import forge.LobbyPlayer;
|
import forge.LobbyPlayer;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.deck.io.DeckSerializer;
|
import forge.deck.io.DeckSerializer;
|
||||||
@@ -18,7 +16,7 @@ import forge.util.Aggregates;
|
|||||||
import forge.util.XmlReader;
|
import forge.util.XmlReader;
|
||||||
import forge.util.XmlWriter;
|
import forge.util.XmlWriter;
|
||||||
import forge.util.XmlWriter.IXmlWritable;
|
import forge.util.XmlWriter.IXmlWritable;
|
||||||
import forge.util.storage.StorageReaderFile;
|
import forge.util.collect.FCollectionReader;
|
||||||
|
|
||||||
public class ConquestEvent {
|
public class ConquestEvent {
|
||||||
private final ConquestRegion region;
|
private final ConquestRegion region;
|
||||||
@@ -89,23 +87,16 @@ public class ConquestEvent {
|
|||||||
return new ConquestEventBattle(location0, tier0);
|
return new ConquestEventBattle(location0, tier0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Function<ConquestEvent, String> FN_GET_NAME = new Function<ConquestEvent, String>() {
|
public static class Reader extends FCollectionReader<ConquestEvent> {
|
||||||
@Override
|
|
||||||
public String apply(ConquestEvent event) {
|
|
||||||
return event.getName();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static class Reader extends StorageReaderFile<ConquestEvent> {
|
|
||||||
private final ConquestRegion region;
|
private final ConquestRegion region;
|
||||||
|
|
||||||
public Reader(ConquestRegion region0) {
|
public Reader(ConquestRegion region0) {
|
||||||
super(region0.getPlane().getDirectory() + region0.getName() + ForgeConstants.PATH_SEPARATOR + "_events.txt", ConquestEvent.FN_GET_NAME);
|
super(region0.getPlane().getDirectory() + region0.getName() + ForgeConstants.PATH_SEPARATOR + "_events.txt");
|
||||||
region = region0;
|
region = region0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConquestEvent read(String line, int i) {
|
protected ConquestEvent read(String line) {
|
||||||
String name = null;
|
String name = null;
|
||||||
String deck = null;
|
String deck = null;
|
||||||
Set<GameType> variants = EnumSet.noneOf(GameType.class);
|
Set<GameType> variants = EnumSet.noneOf(GameType.class);
|
||||||
|
|||||||
@@ -36,8 +36,6 @@ import forge.properties.ForgeConstants;
|
|||||||
import forge.util.FileUtil;
|
import forge.util.FileUtil;
|
||||||
import forge.util.collect.FCollection;
|
import forge.util.collect.FCollection;
|
||||||
import forge.util.collect.FCollectionView;
|
import forge.util.collect.FCollectionView;
|
||||||
import forge.util.storage.IStorage;
|
|
||||||
import forge.util.storage.StorageBase;
|
|
||||||
import forge.util.storage.StorageReaderFile;
|
import forge.util.storage.StorageReaderFile;
|
||||||
|
|
||||||
|
|
||||||
@@ -148,7 +146,7 @@ public class ConquestPlane {
|
|||||||
if (regions != null) { return; }
|
if (regions != null) { return; }
|
||||||
|
|
||||||
//load regions
|
//load regions
|
||||||
regions = new FCollection<ConquestRegion>(new StorageBase<ConquestRegion>("Conquest regions", new ConquestRegion.Reader(this)));
|
regions = new FCollection<ConquestRegion>(new ConquestRegion.Reader(this));
|
||||||
|
|
||||||
//load events
|
//load events
|
||||||
int eventIndex = 0;
|
int eventIndex = 0;
|
||||||
@@ -156,7 +154,7 @@ public class ConquestPlane {
|
|||||||
int regionEndIndex = eventsPerRegion;
|
int regionEndIndex = eventsPerRegion;
|
||||||
events = new ConquestEvent[regions.size() * eventsPerRegion];
|
events = new ConquestEvent[regions.size() * eventsPerRegion];
|
||||||
for (ConquestRegion region : regions) {
|
for (ConquestRegion region : regions) {
|
||||||
IStorage<ConquestEvent> regionEvents = new StorageBase<ConquestEvent>(region.getName() + " events", new ConquestEvent.Reader(region));
|
FCollection<ConquestEvent> regionEvents = new FCollection<ConquestEvent>(new ConquestEvent.Reader(region));
|
||||||
for (ConquestEvent event : regionEvents) {
|
for (ConquestEvent event : regionEvents) {
|
||||||
events[eventIndex++] = event;
|
events[eventIndex++] = event;
|
||||||
if (eventIndex == regionEndIndex) {
|
if (eventIndex == regionEndIndex) {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
|
||||||
import forge.GuiBase;
|
import forge.GuiBase;
|
||||||
@@ -15,8 +14,8 @@ import forge.deck.generation.DeckGenPool;
|
|||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.model.FModel;
|
import forge.model.FModel;
|
||||||
import forge.util.collect.FCollection;
|
import forge.util.collect.FCollection;
|
||||||
|
import forge.util.collect.FCollectionReader;
|
||||||
import forge.util.collect.FCollectionView;
|
import forge.util.collect.FCollectionView;
|
||||||
import forge.util.storage.StorageReaderFile;
|
|
||||||
|
|
||||||
public class ConquestRegion {
|
public class ConquestRegion {
|
||||||
private final ConquestPlane plane;
|
private final ConquestPlane plane;
|
||||||
@@ -75,23 +74,16 @@ public class ConquestRegion {
|
|||||||
return plane.getName() + " - " + name;
|
return plane.getName() + " - " + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Function<ConquestRegion, String> FN_GET_NAME = new Function<ConquestRegion, String>() {
|
public static class Reader extends FCollectionReader<ConquestRegion> {
|
||||||
@Override
|
|
||||||
public String apply(ConquestRegion region) {
|
|
||||||
return region.getName();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static class Reader extends StorageReaderFile<ConquestRegion> {
|
|
||||||
private final ConquestPlane plane;
|
private final ConquestPlane plane;
|
||||||
|
|
||||||
public Reader(ConquestPlane plane0) {
|
public Reader(ConquestPlane plane0) {
|
||||||
super(plane0.getDirectory() + "regions.txt", ConquestRegion.FN_GET_NAME);
|
super(plane0.getDirectory() + "regions.txt");
|
||||||
plane = plane0;
|
plane = plane0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConquestRegion read(String line, int index) {
|
protected ConquestRegion read(String line) {
|
||||||
String name = null;
|
String name = null;
|
||||||
String artCardName = null;
|
String artCardName = null;
|
||||||
ColorSet colorSet = ColorSet.ALL_COLORS;
|
ColorSet colorSet = ColorSet.ALL_COLORS;
|
||||||
|
|||||||
Reference in New Issue
Block a user