diff --git a/README.md b/README.md index 9c702cc..b5f5a8d 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,35 @@ See the other marker sets for inspiration. 4. Add the marker set with a description to this README file. +## Making exceptions for the validation tool + +Sometimes, you might want to add a marker that doesn't pass validation. +You can do this by setting the `skip_validation` parameter to `True` when creating the marker. + +```python +from lib_marker import Point, Track + +MARKERS = [ + ..., + Point( + name="My Invalid Marker", + x=100, + y=200, + z=300, + skip_validation=True, + ), + Track( + name="My Invalid Track", + points=[ + (0, 64, 0), + (10000, 64, 10000), + ], + skip_validation=True, + ), + ..., +] +``` + ## See also - [BlueMap documentation for markers](https://bluemap.bluecolored.de/wiki/customization/Markers.html) diff --git a/src/cli/validate.py b/src/cli/validate.py index 2bb3d6a..3f533ad 100644 --- a/src/cli/validate.py +++ b/src/cli/validate.py @@ -8,8 +8,11 @@ from marker_sets import WORLDS def main() -> None: result_is_ok = True + + worlds_to_be_validated = remove_markers_not_to_be_validated(WORLDS) + for test_name, test_f in _tests.items(): - results = test_f(WORLDS) + results = test_f(worlds_to_be_validated) if len(results) > 0: result_is_ok = False print(f"[X] {test_name}") @@ -87,6 +90,28 @@ class ValidationErrorPoint: return f"({self.x}, {self.y}, {self.z})" +def remove_markers_not_to_be_validated( + worlds: dict[str, list[MarkerSet]], +) -> dict[str, list[MarkerSet]]: + result = {} + + for world_name, marker_sets in worlds.items(): + result[world_name] = [] + for marker_set in marker_sets: + new_marker_set = MarkerSet( + name=marker_set.name, + show_by_default=marker_set.show_by_default, + markers=[ + marker + for marker in marker_set.markers + if not marker.skip_validation + ], + ) + result[world_name].append(new_marker_set) + + return result + + def validate_no_non_included_files( worlds: dict[str, list[MarkerSet]], ) -> list[ValidationError]: diff --git a/src/lib_marker/area.py b/src/lib_marker/area.py index 74fc682..1296040 100644 --- a/src/lib_marker/area.py +++ b/src/lib_marker/area.py @@ -1,9 +1,17 @@ -from dataclasses import dataclass - from .marker import Marker -@dataclass class Area(Marker): points: list[tuple[int, int, int]] icon: str | None = None + + def __init__( + self, + name: str, + points: list[tuple[int, int, int]], + icon: str | None = None, + skip_validation: bool = False, + ) -> None: + super().__init__(name, skip_validation) + self.points = points + self.icon = icon diff --git a/src/lib_marker/marker.py b/src/lib_marker/marker.py index 32902bd..3de670f 100644 --- a/src/lib_marker/marker.py +++ b/src/lib_marker/marker.py @@ -1,8 +1,10 @@ from abc import ABC -from dataclasses import dataclass - -@dataclass class Marker(ABC): name: str + skip_validation: bool = False # icon: str | None = None + + def __init__(self, name: str, skip_validation: bool = False) -> None: + self.name = name + self.skip_validation = skip_validation diff --git a/src/lib_marker/point.py b/src/lib_marker/point.py index 6289da2..ff695ab 100644 --- a/src/lib_marker/point.py +++ b/src/lib_marker/point.py @@ -1,11 +1,23 @@ -from dataclasses import dataclass - from .marker import Marker - -@dataclass class Point(Marker): x: int y: int z: int icon: str | None = None + skip_validation: bool = False + + def __init__( + self, + name: str, + x: int, + y: int, + z: int, + icon: str | None = None, + skip_validation: bool = False, + ) -> None: + super().__init__(name, skip_validation) + self.x = x + self.y = y + self.z = z + self.icon = icon diff --git a/src/lib_marker/track.py b/src/lib_marker/track.py index 9fd965d..35ce08a 100644 --- a/src/lib_marker/track.py +++ b/src/lib_marker/track.py @@ -1,9 +1,16 @@ -from dataclasses import dataclass - from .marker import Marker - -@dataclass class Track(Marker): points: list[tuple[int, int, int]] icon: str | None = None + + def __init__( + self, + name: str, + points: list[tuple[int, int, int]], + icon: str | None = None, + skip_validation: bool = False, + ) -> None: + super().__init__(name, skip_validation) + self.points = points + self.icon = icon