use of delta.games.lotro.maps.data.MarkersManager in project lotro-tools by dmorcellet.
the class MarkersMerge method handleMap.
private void handleMap(MapBundle mapBundle) {
MarkersManager markersMgr = mapBundle.getData();
List<Marker> markers = markersMgr.getAllMarkers();
List<Marker> markersToAdd = new ArrayList<Marker>();
for (Marker marker : markers) {
String footPrint = buildMarkerFootPrint(marker);
Marker match = _foundMarkers.get(footPrint);
if (match != null) {
// System.out.println("Found match: 1="+marker+", 2="+match);
marker.setId(match.getId());
} else {
int id = _currentId;
_currentId++;
marker.setId(id);
markersToAdd.add(marker);
}
}
for (Marker markerToAdd : markersToAdd) {
String footPrint = buildMarkerFootPrint(markerToAdd);
_foundMarkers.put(footPrint, markerToAdd);
}
}
use of delta.games.lotro.maps.data.MarkersManager 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.MarkersManager 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.MarkersManager in project lotro-tools by dmorcellet.
the class MapPageParser method parse.
/**
* Parse map data.
* @param mapBundle Storage for extracted data.
* @param js Input file.
*/
public void parse(MapBundle mapBundle, File js) {
List<String> lines = TextUtils.readAsLines(js);
Float startX = null;
Float startY = null;
Float scale = null;
Date date = null;
MarkersManager markers = mapBundle.getData();
int markerId = 1;
for (String line : lines) {
if (line.startsWith(STARTX_SEED)) {
// map.StartX = -42.8;
startX = getValue(STARTX_SEED, line);
} else if (line.startsWith(STARTY_SEED)) {
// map.StartY = 14.7;
startY = getValue(STARTY_SEED, line);
} else if (line.startsWith(SCALE2MAP_SEED)) {
// map.ScaleToMap = 3.498879;
scale = getValue(SCALE2MAP_SEED, line);
} else // map.ScaleToIg = 0.285807;
if (line.startsWith(MODIFIED_SEED)) {
// map.Modified = "07/12/2015";
date = getDate(MODIFIED_SEED, line);
} else if (line.startsWith("[")) {
Marker marker = parseItemLine(line);
if (marker != null) {
marker.setId(markerId);
markerId++;
markers.addMarker(marker);
}
}
}
Map map = mapBundle.getMap();
if ((startX != null) && (startY != null) && (scale != null)) {
GeoPoint start = new GeoPoint(startX.floatValue(), startY.floatValue());
GeoReference reference = new GeoReference(start, scale.floatValue());
map.setGeoReference(reference);
}
map.setLastUpdate(date);
}
Aggregations