use of delta.common.utils.files.TextFileReader in project lotro-tools by dmorcellet.
the class ScalableItemsSamplesLoader method loadTable.
/**
* Load items from a table.
* @param filename Name of file to read.
* @return A list of items.
*/
public List<Item> loadTable(String filename) {
URL url = URLTools.getFromClassPath(filename, ScalableItemsSamplesLoader.class.getPackage());
TextFileReader reader = new TextFileReader(url, EncodingNames.UTF_8);
List<String> lines = TextUtils.readAsLines(reader);
List<Item> items = new ArrayList<Item>();
lines.remove(0);
for (String line : lines) {
Item item = buildItemFromLine(line);
if (item != null) {
items.add(item);
}
}
return items;
}
use of delta.common.utils.files.TextFileReader in project lotro-tools by dmorcellet.
the class LotroPlanItemsDbLoader method loadTable.
/**
* Load the items in a table.
* @param filename Table name.
* @return A list of items.
*/
public List<Item> loadTable(String filename) {
_section = null;
URL url = URLTools.getFromClassPath(filename, LotroPlanItemsDbLoader.class.getPackage());
TextFileReader reader = new TextFileReader(url, EncodingNames.UTF_8);
List<String> lines = TextUtils.readAsLines(reader);
List<Item> items = new ArrayList<Item>();
// _fields=StringSplitter.split(lines.get(0),'\t');
lines.remove(0);
boolean mordor = useMordorFormat(filename);
LotroPlanTable table = new LotroPlanTable(mordor);
for (String line : lines) {
Item item = buildItemFromLine(table, line);
if (item != null) {
items.add(item);
}
}
return items;
}
use of delta.common.utils.files.TextFileReader in project lotro-tools by dmorcellet.
the class EssenceStatsInjector method loadTiers.
private List<Integer> loadTiers() {
List<Integer> ret = new ArrayList<Integer>();
URL url = URLTools.getFromClassPath("tiers.txt", EssenceStatsInjector.class.getPackage());
TextFileReader reader = new TextFileReader(url, EncodingNames.UTF_8);
List<String> lines = TextUtils.readAsLines(reader);
for (String line : lines) {
char[] tierChars = line.toCharArray();
for (char tierChar : tierChars) {
if (tierChar == ' ') {
ret.add(null);
} else {
int tier = 0;
if ((tierChar >= '0') && (tierChar <= '9'))
tier = tierChar - '0';
else if ((tierChar >= 'A') && (tierChar <= 'F'))
tier = tierChar - 'A' + 10;
ret.add(Integer.valueOf(tier));
}
}
}
return ret;
}
use of delta.common.utils.files.TextFileReader in project lotro-tools by dmorcellet.
the class EssenceStatsInjector method handleTier.
private void handleTier(int tier, HashMap<Integer, Item> essences) {
URL url = URLTools.getFromClassPath("tier" + tier + ".txt", EssenceStatsInjector.class.getPackage());
if (url != null) {
TextFileReader reader = new TextFileReader(url, EncodingNames.UTF_8);
List<String> lines = TextUtils.readAsLines(reader);
boolean hasId = lines.get(0).startsWith("ID");
lines.remove(0);
HashSet<Integer> unmanaged = new HashSet<Integer>();
unmanaged.addAll(essences.keySet());
LotroPlanTable table = new LotroPlanTable(STATS);
for (String line : lines) {
String[] fields = StringSplitter.split(line, '\t');
if (fields.length > 2) {
List<Item> items = findEssences(fields, hasId, essences);
for (Item item : items) {
if (hasId) {
String[] newFields = new String[fields.length - 1];
for (int i = 1; i < fields.length; i++) {
newFields[i - 1] = fields[i];
if (newFields[i - 1].equals(CELLS[i])) {
newFields[i - 1] = "";
}
}
fields = newFields;
}
unmanaged.remove(Integer.valueOf(item.getIdentifier()));
// Item level
int itemLevel = NumericTools.parseInt(fields[ITEM_LEVEL_INDEX], -1);
if (itemLevel != -1) {
item.setItemLevel(Integer.valueOf(itemLevel));
}
// Notes
if (fields.length > NOTES_INDEX) {
String notes = fields[NOTES_INDEX].trim();
if (notes.length() > 0) {
item.getBonus().add(notes);
}
}
// Tier
item.setSubCategory("Essence:Tier" + tier);
// Stats
ItemStatsProvider provider = table.loadStats(fields);
BasicStatsSet stats = item.getStats();
stats.setStats(provider.getStats(itemLevel));
}
if (items.size() == 0) {
System.out.println("Essence not found: " + fields[0]);
}
} else {
if (!line.startsWith("#")) {
System.err.println("Bad fields count: " + line);
}
}
}
if (unmanaged.size() > 0) {
System.out.println(unmanaged + " unmanaged essences:");
for (Integer id : unmanaged) {
Item essence = essences.get(id);
System.out.println("\t" + essence);
}
}
}
}
Aggregations