use of delta.games.lotro.maps.data.CategoriesManager in project lotro-tools by dmorcellet.
the class CategoriesParser method parse.
/**
* Parse categories definitions from the localization page.
* @param lines Lines to read.
* @return A categories manager.
*/
public CategoriesManager parse(List<String> lines) {
CategoriesManager manager = new CategoriesManager();
if (lines == null) {
return manager;
}
boolean enabled = false;
for (String line : lines) {
if (enabled) {
// 2: { en: "Point of interest", de: "Sehenswertes", fr: "Point d'interet" },
int index = line.indexOf(':');
if (index != -1) {
String categoryCodeStr = line.substring(0, index).trim();
Integer categoryCode = NumericTools.parseInteger(categoryCodeStr);
if (categoryCode != null) {
Category category = new Category(categoryCode.intValue());
Labels labelsManager = category.getLabels();
String labels = line.substring(index + 1).trim();
if (labels.endsWith(","))
labels = labels.substring(0, labels.length() - 1);
ParsingUtils.parseLabels(labelsManager, labels);
manager.addCategory(category);
}
}
}
if (line.contains(TYPES_LINE)) {
enabled = true;
}
}
return manager;
}
use of delta.games.lotro.maps.data.CategoriesManager in project lotro-tools by dmorcellet.
the class MainDynMapLoader method doIt.
private void doIt() {
DynMapSiteInterface dynMap = new DynMapSiteInterface();
// Categories
File localizationFile = dynMap.download(DynMapConstants.LOCALIZATION_PAGE, "localization.js");
List<String> localizationPage = TextUtils.readAsLines(localizationFile);
CategoriesParser categoriesParser = new CategoriesParser();
CategoriesManager categories = categoriesParser.parse(localizationPage);
// Maps
File mapsFile = dynMap.download(DynMapConstants.MAP_PAGE, "map.js");
List<String> mapsPage = TextUtils.readAsLines(mapsFile);
MapsPageParser mapsParser = new MapsPageParser();
List<MapBundle> maps = mapsParser.parse(mapsPage, categories);
// Load all map data
for (MapBundle map : maps) {
String key = map.getKey();
File mapDir = new File(new File(_outDir, "maps"), key);
// JS
String jsUrl = DynMapConstants.BASE_URL + "/data/" + key + ".js";
File js = dynMap.download(jsUrl, key + ".js");
loadMapData(map, js, categories);
// Inspect
MarkersManager markers = map.getData();
for (Category category : categories.getAllSortedByCode()) {
List<Marker> markersList = markers.getByCategory(category);
System.out.println(category);
for (Marker marker : markersList) {
System.out.println("\t" + marker);
}
}
// Map images
String[] locales = { "en", "de", "fr" };
for (String locale : locales) {
String mapUrl = DynMapConstants.BASE_URL + "/images/maps/" + locale + '/' + key + ".jpg";
File mapImageFile = new File(mapDir, "map_" + locale + ".jpg");
dynMap.download(mapUrl, mapImageFile);
}
System.out.println(map.getMap());
// Write file
MapXMLWriter writer = new MapXMLWriter();
File toFile = new File(mapDir, "markers.xml");
writer.writeMarkersFile(toFile, map, EncodingNames.UTF_8);
}
// Write categories file
{
CategoriesXMLWriter writer = new CategoriesXMLWriter();
File toFile = new File(_outDir, "categories.xml");
writer.write(toFile, categories, EncodingNames.UTF_8);
}
File imagesDir = new File(_outDir, "images");
for (Category category : categories.getAllSortedByCode()) {
String key = category.getIcon();
String iconUrl = DynMapConstants.BASE_URL + "/images/" + key + ".gif";
File toFile = new File(imagesDir, key + ".gif");
dynMap.download(iconUrl, toFile);
System.out.println(category);
}
}
use of delta.games.lotro.maps.data.CategoriesManager 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();
}
Aggregations