Search in sources :

Example 1 with Category

use of delta.games.lotro.maps.data.Category 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;
}
Also used : Category(delta.games.lotro.maps.data.Category) CategoriesManager(delta.games.lotro.maps.data.CategoriesManager) Labels(delta.games.lotro.maps.data.Labels)

Example 2 with Category

use of delta.games.lotro.maps.data.Category 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);
    }
}
Also used : Category(delta.games.lotro.maps.data.Category) CategoriesXMLWriter(delta.games.lotro.maps.data.io.xml.CategoriesXMLWriter) Marker(delta.games.lotro.maps.data.Marker) MapXMLWriter(delta.games.lotro.maps.data.io.xml.MapXMLWriter) CategoriesManager(delta.games.lotro.maps.data.CategoriesManager) MapBundle(delta.games.lotro.maps.data.MapBundle) File(java.io.File) MarkersManager(delta.games.lotro.maps.data.MarkersManager)

Example 3 with Category

use of delta.games.lotro.maps.data.Category 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();
}
Also used : Category(delta.games.lotro.maps.data.Category) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Marker(delta.games.lotro.maps.data.Marker) IntegerHolder(delta.common.utils.misc.IntegerHolder) CategoriesManager(delta.games.lotro.maps.data.CategoriesManager) MapBundle(delta.games.lotro.maps.data.MapBundle) MarkersManager(delta.games.lotro.maps.data.MarkersManager) HashSet(java.util.HashSet)

Example 4 with Category

use of delta.games.lotro.maps.data.Category in project lotro-tools by dmorcellet.

the class MapPageParser method parseItemLine.

private Marker parseItemLine(String line) {
    // [-77.4,-24.6,{en:"Auctioneer",de:"TBD",fr:"TBD"},13,"Auctioneer"],
    line = line.trim();
    if (line.endsWith(","))
        line = line.substring(0, line.length() - 1);
    line = TextTools.findBetween(line, "[", "]");
    Marker marker = new Marker();
    String part1 = findBefore(line, "{");
    String labels = TextTools.findBetween(line, "{", "}");
    String part3 = TextTools.findAfter(line, "}");
    ParsingUtils.parseLabels(marker.getLabels(), "{" + labels + "}");
    Float latitude = null;
    Float longitude = null;
    String[] posItems = part1.split(",");
    if (posItems.length == 2) {
        latitude = NumericTools.parseFloat(posItems[0]);
        longitude = NumericTools.parseFloat(posItems[1]);
    }
    Integer categoryCode = null;
    String[] categoryItems = part3.split(",");
    if (categoryItems.length >= 3) {
        categoryCode = NumericTools.parseInteger(categoryItems[1]);
    }
    String comment = null;
    if (categoryItems.length >= 4) {
        comment = TextTools.findBetween(categoryItems[3], "\"", "\"");
    }
    marker.setComment(comment);
    if ((latitude != null) && (longitude != null) && (categoryCode != null)) {
        GeoPoint position = new GeoPoint(longitude.floatValue(), latitude.floatValue());
        marker.setPosition(position);
        Category category = _categories.getByCode(categoryCode.intValue());
        if (category == null) {
            _logger.warn("Category not found: " + categoryCode);
        }
        marker.setCategory(category);
    } else {
        _logger.warn("Bad line: " + line);
    }
    return marker;
}
Also used : GeoPoint(delta.games.lotro.maps.data.GeoPoint) Category(delta.games.lotro.maps.data.Category) Marker(delta.games.lotro.maps.data.Marker)

Example 5 with Category

use of delta.games.lotro.maps.data.Category 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;
}
Also used : Category(delta.games.lotro.maps.data.Category) ArrayList(java.util.ArrayList) MapBundle(delta.games.lotro.maps.data.MapBundle)

Aggregations

Category (delta.games.lotro.maps.data.Category)5 CategoriesManager (delta.games.lotro.maps.data.CategoriesManager)3 MapBundle (delta.games.lotro.maps.data.MapBundle)3 Marker (delta.games.lotro.maps.data.Marker)3 MarkersManager (delta.games.lotro.maps.data.MarkersManager)2 ArrayList (java.util.ArrayList)2 IntegerHolder (delta.common.utils.misc.IntegerHolder)1 GeoPoint (delta.games.lotro.maps.data.GeoPoint)1 Labels (delta.games.lotro.maps.data.Labels)1 CategoriesXMLWriter (delta.games.lotro.maps.data.io.xml.CategoriesXMLWriter)1 MapXMLWriter (delta.games.lotro.maps.data.io.xml.MapXMLWriter)1 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1