use of delta.games.lotro.maps.data.MapBundle in project lotro-tools by dmorcellet.
the class MainMapsCleaner method cleanEmptyCategories.
private void cleanEmptyCategories(MapsManager mapsManager) {
HashMap<Integer, IntegerHolder> markersByCategory = new HashMap<Integer, IntegerHolder>();
List<MapBundle> mapBundles = mapsManager.getMaps();
for (MapBundle mapBundle : mapBundles) {
MarkersManager markersManager = mapBundle.getData();
List<Marker> markers = markersManager.getAllMarkers();
for (Marker marker : markers) {
Category category = marker.getCategory();
if (category != null) {
Integer code = Integer.valueOf(category.getCode());
IntegerHolder counter = markersByCategory.get(code);
if (counter == null) {
counter = new IntegerHolder();
markersByCategory.put(code, counter);
}
counter.increment();
}
}
}
CategoriesManager categoriesManager = mapsManager.getCategories();
List<Integer> sortedCodes = new ArrayList<Integer>(markersByCategory.keySet());
Collections.sort(sortedCodes);
int total = 0;
for (Integer code : sortedCodes) {
IntegerHolder counter = markersByCategory.get(code);
Category category = categoriesManager.getByCode(code.intValue());
System.out.println(category.getLabel() + ": " + counter);
total += counter.getInt();
}
System.out.println("Total: " + total);
// Prepare cleanup
HashSet<Integer> codes2Remove = new HashSet<Integer>();
List<Category> categories = categoriesManager.getAllSortedByCode();
for (Category category : categories) {
Integer key = Integer.valueOf(category.getCode());
if (!sortedCodes.contains(key)) {
codes2Remove.add(key);
}
}
// Perform cleanup
for (Integer code : codes2Remove) {
System.out.println("Removing category: " + categoriesManager.getByCode(code.intValue()).getLabel());
categoriesManager.removeCategory(code.intValue());
}
mapsManager.saveCategories();
}
use of delta.games.lotro.maps.data.MapBundle in project lotro-tools by dmorcellet.
the class MapsPageParser method parse.
/**
* Parse maps index data.
* @param lines Lines to read.
* @param categories Categories to use.
* @return A list of map data bundles.
*/
public List<MapBundle> parse(List<String> lines, CategoriesManager categories) {
List<MapBundle> ret = new ArrayList<MapBundle>();
if (lines == null) {
return ret;
}
for (String line : lines) {
// Looking for lines like:
// obj.push(new Map("angmar", { en: "Angmar", de: "Angmar", fr: "Angmar" }));
int index = line.indexOf(MAP_MARKER);
if (index != -1) {
String data = line.substring(index + MAP_MARKER.length());
MapBundle map = parseMapLine(data);
if (map != null) {
ret.add(map);
}
}
index = line.indexOf(CATEGORY_LINE);
if (index != -1) {
String caseStr = line.substring(0, index).trim();
Integer categoryCode = NumericTools.parseInteger(TextTools.findAfter(caseStr, " "));
if (categoryCode != null) {
String valueStr = line.substring(index + CATEGORY_LINE.length()).trim();
String categoryKey = TextTools.findBetween(valueStr, "\"", "\"");
Category category = categories.getByCode(categoryCode.intValue());
if (category != null) {
category.setIcon(categoryKey);
}
}
}
}
return ret;
}
use of delta.games.lotro.maps.data.MapBundle in project lotro-tools by dmorcellet.
the class MapChooserDialogController method buildMapCombo.
private ComboBoxController<MapBundle> buildMapCombo() {
ComboBoxController<MapBundle> controller = new ComboBoxController<MapBundle>();
List<MapBundle> bundles = _manager.getMaps();
for (MapBundle bundle : bundles) {
controller.addItem(bundle, bundle.getLabel());
}
return controller;
}
Aggregations