rewrite to python: export to mapcrafter
This commit is contained in:
3
src/minecraft_kartverket/bluemap_exporter/__init__.py
Normal file
3
src/minecraft_kartverket/bluemap_exporter/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .exporter import generate_bluemap_output
|
||||
|
||||
__all__ = ["generate_bluemap_output"]
|
||||
15
src/minecraft_kartverket/bluemap_exporter/exporter.py
Normal file
15
src/minecraft_kartverket/bluemap_exporter/exporter.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from pathlib import Path
|
||||
|
||||
# from minecraft_kartverket.marker_sets import WORLDS
|
||||
# from minecraft_kartverket.lib_marker import Point
|
||||
|
||||
|
||||
def generate_bluemap_output(output_dir: Path):
|
||||
raise NotImplementedError("Bluemap export is not implemented yet")
|
||||
...
|
||||
|
||||
def convert_data_to_bluemap_structure() -> dict:
|
||||
...
|
||||
|
||||
def to_hocon():
|
||||
...
|
||||
@@ -1,6 +1,11 @@
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
from .print import print_worlds
|
||||
from .print import pretty_print_marker_data
|
||||
from .validate import validate_marker_data
|
||||
|
||||
from minecraft_kartverket.mapcrafter_exporter import generate_mapcrafter_output
|
||||
from minecraft_kartverket.bluemap_exporter import generate_bluemap_output
|
||||
|
||||
|
||||
def parse_args():
|
||||
@@ -9,15 +14,26 @@ def parse_args():
|
||||
subparsers = parser.add_subparsers(dest="command")
|
||||
|
||||
ebh_parser = subparsers.add_parser(
|
||||
"export-bluemap-hocon", help="Export map data to Bluemap hocon format"
|
||||
"export-bluemap", help="Export map data to Bluemap format"
|
||||
)
|
||||
ebh_parser.add_argument(
|
||||
"--output-dir",
|
||||
help="Output dir",
|
||||
type=Path,
|
||||
metavar="DIR",
|
||||
default=Path("bluemap"),
|
||||
)
|
||||
# TODO: dir?
|
||||
ebh_parser.add_argument("output", help="Output file", default="map.hocon")
|
||||
|
||||
emj_parser = subparsers.add_parser(
|
||||
"export-mapcrafter-json", help="Export map data to Mapcrafter json format"
|
||||
"export-mapcrafter", help="Export map data to Mapcrafter format"
|
||||
)
|
||||
emj_parser.add_argument(
|
||||
"--output-dir",
|
||||
help="Output dir",
|
||||
type=Path,
|
||||
metavar="DIR",
|
||||
default=Path("mapcrafter"),
|
||||
)
|
||||
emj_parser.add_argument("output", help="Output file", default="map.json")
|
||||
|
||||
subparsers.add_parser("validate", help="Validate the map data")
|
||||
subparsers.add_parser("print", help="Print the map data")
|
||||
@@ -29,18 +45,18 @@ def main():
|
||||
args = parse_args()
|
||||
|
||||
match args.command:
|
||||
case "export-bluemap-hocon":
|
||||
print("Exporting map data to Bluemap hocon format...")
|
||||
raise NotImplementedError()
|
||||
case "export-mapcrafter-json":
|
||||
print("Exporting map data to Mapcrafter json format...")
|
||||
raise NotImplementedError()
|
||||
case "export-bluemap":
|
||||
generate_bluemap_output(args.output_dir)
|
||||
|
||||
case "export-mapcrafter":
|
||||
generate_mapcrafter_output(args.output_dir)
|
||||
|
||||
case "validate":
|
||||
print("Validating the map data...")
|
||||
raise NotImplementedError()
|
||||
validate_marker_data()
|
||||
|
||||
case "print":
|
||||
print("Printing the map data...")
|
||||
print_worlds()
|
||||
pretty_print_marker_data()
|
||||
|
||||
case _:
|
||||
print("Unknown command")
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ from minecraft_kartverket.lib_marker import MarkerSet, Marker, Point, Track, Are
|
||||
from minecraft_kartverket.marker_sets import WORLDS
|
||||
|
||||
|
||||
def print_worlds() -> None:
|
||||
def pretty_print_marker_data() -> None:
|
||||
tree = format_tree(
|
||||
"Worlds", [format_world(name, world) for name, world in WORLDS.items()]
|
||||
)
|
||||
|
||||
@@ -1,8 +1,27 @@
|
||||
# Check for non-included files
|
||||
# read all python files, edit-distance out common mistakes.
|
||||
# Check for invalid y values
|
||||
# Check for duplicate points in tracks
|
||||
# Check for duplicate names in markers
|
||||
# Check for duplicate names in marker sets
|
||||
# Check for unused icons
|
||||
# Check for duplicate points
|
||||
def validate_marker_data() -> None:
|
||||
# TODO: print [V] checkmarks for each test
|
||||
...
|
||||
|
||||
|
||||
def validate_no_non_included_files() -> None: ...
|
||||
|
||||
|
||||
def validate_no_invalid_y_values() -> None: ...
|
||||
|
||||
|
||||
def validate_no_duplicate_points_in_tracks() -> None: ...
|
||||
|
||||
|
||||
def validate_no_duplicate_names_in_markers() -> None: ...
|
||||
|
||||
|
||||
def validate_no_duplicate_names_in_marker_sets() -> None: ...
|
||||
|
||||
|
||||
def validate_no_unused_icons() -> None: ...
|
||||
|
||||
|
||||
def validate_no_duplicate_points() -> None: ...
|
||||
|
||||
|
||||
def validate_all_tracks_have_at_least_two_points() -> None: ...
|
||||
|
||||
3
src/minecraft_kartverket/mapcrafter_exporter/__init__.py
Normal file
3
src/minecraft_kartverket/mapcrafter_exporter/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .exporter import generate_mapcrafter_output
|
||||
|
||||
__all__ = ["generate_mapcrafter_output"]
|
||||
55
src/minecraft_kartverket/mapcrafter_exporter/exporter.py
Normal file
55
src/minecraft_kartverket/mapcrafter_exporter/exporter.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from minecraft_kartverket.marker_sets import WORLDS
|
||||
from minecraft_kartverket.lib_marker import Point, Track, Area
|
||||
|
||||
|
||||
def generate_mapcrafter_output(output_dir: Path):
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with (Path(__file__).parent / "markers-template.js").open("r", encoding='utf-8') as f:
|
||||
template = f.read()
|
||||
|
||||
exported_markers_json = json.dumps(
|
||||
convert_data_to_mapcrafter_structure(),
|
||||
indent=2,
|
||||
ensure_ascii=False,
|
||||
)
|
||||
|
||||
template = template.replace("\"@EXPORTED_MARKERS@\"", exported_markers_json)
|
||||
|
||||
with (output_dir / "markers.js").open("w", encoding='utf-8') as f:
|
||||
f.write(template)
|
||||
|
||||
|
||||
def convert_data_to_mapcrafter_structure() -> dict:
|
||||
result = {}
|
||||
|
||||
for world_name, world_marker_sets in WORLDS.items():
|
||||
for marker_set in world_marker_sets:
|
||||
if marker_set.name not in result:
|
||||
result[marker_set.name] = {
|
||||
"id": marker_set.name.lower().replace(" ", "-"),
|
||||
"name": marker_set.name,
|
||||
"showDefault": marker_set.show_by_default,
|
||||
"markers": {},
|
||||
}
|
||||
|
||||
result[marker_set.name]["markers"][world_name] = []
|
||||
for marker in marker_set.markers:
|
||||
if isinstance(marker, Point):
|
||||
result[marker_set.name]["markers"][world_name].append(
|
||||
{"pos": [marker.x, marker.y, marker.z], "title": marker.name}
|
||||
)
|
||||
|
||||
elif isinstance(marker, Track):
|
||||
raise NotImplementedError("Track markers are not supported")
|
||||
|
||||
elif isinstance(marker, Area):
|
||||
raise NotImplementedError("Area markers are not supported")
|
||||
|
||||
else:
|
||||
raise ValueError(f"Unknown marker type: {marker}")
|
||||
|
||||
return result
|
||||
@@ -0,0 +1,60 @@
|
||||
const MAPCRAFTER_MARKERS = [
|
||||
"@EXPORTED_MARKERS@",
|
||||
{
|
||||
//
|
||||
// Tegner et rutenett som viser regiongrensene, og
|
||||
// koordinatene for hver region.
|
||||
//
|
||||
"id" : "regioner",
|
||||
"name" : "Regioner",
|
||||
"showDefault" : false,
|
||||
"createMarker" : function(ui, groupInfo, markerInfo) {
|
||||
var rmax = 15;
|
||||
var objekter = [];
|
||||
|
||||
var multilatlngs = [];
|
||||
|
||||
for (var rx = -rmax; rx < rmax; rx++) {
|
||||
var latlngs = [];
|
||||
var miny = -rmax*512;
|
||||
var maxy = rmax*512;
|
||||
var x = rx*512;
|
||||
// use the ui.mcToLatLng-function to convert Minecraft coords to LatLngs
|
||||
latlngs.push(ui.mcToLatLng(x, miny, 64));
|
||||
latlngs.push(ui.mcToLatLng(x, maxy, 64));
|
||||
multilatlngs.push(latlngs);
|
||||
}
|
||||
|
||||
for (var ry = -rmax; ry < rmax; ry++) {
|
||||
var latlngs = [];
|
||||
var minx = -rmax*512;
|
||||
var maxx = rmax*512;
|
||||
var y = ry*512;
|
||||
// use the ui.mcToLatLng-function to convert Minecraft coords to LatLngs
|
||||
latlngs.push(ui.mcToLatLng(minx, y, 64));
|
||||
latlngs.push(ui.mcToLatLng(maxx, y, 64));
|
||||
multilatlngs.push(latlngs);
|
||||
}
|
||||
|
||||
for (var rx = -rmax; rx < rmax; rx++) {
|
||||
for (var ry = -rmax; ry < rmax; ry++) {
|
||||
var x = rx*512 + 256;
|
||||
var y = ry*512 + 256;
|
||||
|
||||
var myIcon = L.divIcon({iconSize: L.point(55, 20), html: "<center>r." + String(rx) + "." + String(ry) + "</center>"});
|
||||
var myMarker = L.marker(ui.mcToLatLng(x, y, 64), {icon: myIcon});
|
||||
objekter.push(myMarker);
|
||||
}
|
||||
}
|
||||
|
||||
var linjer = [];
|
||||
if (L.version.startsWith("0.7.")) {
|
||||
linjer = L.multiPolyline(multilatlngs, {"color" : markerInfo.color});
|
||||
} else {
|
||||
linjer = L.polyline(multilatlngs, {"color" : markerInfo.color});
|
||||
}
|
||||
objekter.push(linjer);
|
||||
return L.layerGroup(objekter);
|
||||
},
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user