Search in sources :

Example 1 with Marker

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

Example 2 with Marker

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

the class MainLinkEditor method main.

/**
 * Main method for this test.
 * @param args Not used.
 */
public static void main(String[] args) {
    File rootDir = new File("../lotro-maps-db");
    final MapsManager mapsManager = new MapsManager(rootDir);
    mapsManager.load();
    Filter<Marker> filter = new Filter<Marker>() {

        public boolean accept(Marker item) {
            return false;
        }
    };
    MapBundle bundle = mapsManager.getMapByKey("breeland");
    MapCanvas canvas = new MapCanvas(mapsManager);
    final NavigationManager navigationManager = new NavigationManager(canvas);
    NavigationListener listener = new NavigationListener() {

        public void mapChangeRequest(String key) {
            navigationManager.setMap(mapsManager.getMapByKey(key).getMap());
        }
    };
    navigationManager.setNavigationListener(listener);
    /*LinkCreationInterator interactor=*/
    new LinkCreationInterator(mapsManager, canvas);
    canvas.setFilter(filter);
    String key = bundle.getKey();
    canvas.setMap(key);
    navigationManager.setMap(bundle.getMap());
    JFrame f = new JFrame();
    String title = bundle.getLabel();
    f.setTitle(title);
    f.getContentPane().add(canvas);
    f.pack();
    f.setVisible(true);
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
Also used : MapsManager(delta.games.lotro.maps.data.MapsManager) NavigationManager(delta.games.lotro.maps.ui.NavigationManager) MapCanvas(delta.games.lotro.maps.ui.MapCanvas) Filter(delta.common.utils.collections.filters.Filter) JFrame(javax.swing.JFrame) NavigationListener(delta.games.lotro.maps.ui.NavigationListener) Marker(delta.games.lotro.maps.data.Marker) MapBundle(delta.games.lotro.maps.data.MapBundle) File(java.io.File)

Example 3 with Marker

use of delta.games.lotro.maps.data.Marker 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 4 with Marker

use of delta.games.lotro.maps.data.Marker 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 5 with Marker

use of delta.games.lotro.maps.data.Marker 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);
}
Also used : GeoPoint(delta.games.lotro.maps.data.GeoPoint) Marker(delta.games.lotro.maps.data.Marker) MarkersManager(delta.games.lotro.maps.data.MarkersManager) Map(delta.games.lotro.maps.data.Map) Date(java.util.Date) GeoPoint(delta.games.lotro.maps.data.GeoPoint) GeoReference(delta.games.lotro.maps.data.GeoReference)

Aggregations

Marker (delta.games.lotro.maps.data.Marker)6 MarkersManager (delta.games.lotro.maps.data.MarkersManager)4 Category (delta.games.lotro.maps.data.Category)3 GeoPoint (delta.games.lotro.maps.data.GeoPoint)3 MapBundle (delta.games.lotro.maps.data.MapBundle)3 CategoriesManager (delta.games.lotro.maps.data.CategoriesManager)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Filter (delta.common.utils.collections.filters.Filter)1 IntegerHolder (delta.common.utils.misc.IntegerHolder)1 GeoReference (delta.games.lotro.maps.data.GeoReference)1 Map (delta.games.lotro.maps.data.Map)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 Date (java.util.Date)1 HashMap (java.util.HashMap)1