Search in sources :

Example 6 with MapBundle

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();
}
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 7 with MapBundle

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

Example 8 with MapBundle

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;
}
Also used : ComboBoxController(delta.common.ui.swing.combobox.ComboBoxController) MapBundle(delta.games.lotro.maps.data.MapBundle)

Aggregations

MapBundle (delta.games.lotro.maps.data.MapBundle)8 Category (delta.games.lotro.maps.data.Category)3 Marker (delta.games.lotro.maps.data.Marker)3 CategoriesManager (delta.games.lotro.maps.data.CategoriesManager)2 MarkersManager (delta.games.lotro.maps.data.MarkersManager)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ComboBoxController (delta.common.ui.swing.combobox.ComboBoxController)1 Filter (delta.common.utils.collections.filters.Filter)1 IntegerHolder (delta.common.utils.misc.IntegerHolder)1 GeoPoint (delta.games.lotro.maps.data.GeoPoint)1 Labels (delta.games.lotro.maps.data.Labels)1 Map (delta.games.lotro.maps.data.Map)1 MapLink (delta.games.lotro.maps.data.MapLink)1 MapsManager (delta.games.lotro.maps.data.MapsManager)1 CategoriesXMLWriter (delta.games.lotro.maps.data.io.xml.CategoriesXMLWriter)1 MapXMLWriter (delta.games.lotro.maps.data.io.xml.MapXMLWriter)1 MapCanvas (delta.games.lotro.maps.ui.MapCanvas)1 NavigationListener (delta.games.lotro.maps.ui.NavigationListener)1 NavigationManager (delta.games.lotro.maps.ui.NavigationManager)1