# Path: sc2/paths.py
# class Paths(metaclass=_MetaPaths):
#     """Paths for SC2 folders, lazily loaded using the above metaclass."""


from .paths import Paths
import logging

logger = logging.getLogger(__name__)

def get(name=None):
    maps = []
    for mapdir in (p for p in Paths.MAPS.iterdir()):
        if mapdir.is_dir():
            for mapfile in (p for p in mapdir.iterdir() if p.is_file()):
                if mapfile.suffix == ".SC2Map":
                    maps.append(Map(mapfile))
        elif mapdir.is_file():
            if mapdir.suffix == ".SC2Map":
                maps.append(Map(mapdir))

    if name is None:
        return maps

    for m in maps:
        if m.matches(name):
            return m

    raise KeyError(f"Map '{name}' was not found. Please put the map file in \"/StarCraft II/Maps/\".")

class Map:
    def __init__(self, path):
        self.path = path

        if self.path.is_absolute():
            try:

# Path: sc2/paths.py
# class Paths(metaclass=_MetaPaths):
#     """Paths for SC2 folders, lazily loaded using the above metaclass."""


# Path: sc2/maps.py
from .paths import Paths
import logging


logger = logging.getLogger(__name__)

def get(name=None):
    maps = []
    for mapdir in (p for p in Paths.MAPS.iterdir()):
        if mapdir.is_dir():
            for mapfile in (p for p in mapdir.iterdir() if p.is_file()):
                if mapfile.suffix == ".SC2Map":
                    maps.append(Map(mapfile))
        elif mapdir.is_file():
            if mapdir.suffix == ".SC2Map":
                maps.append(Map(mapdir))

    if name is None:
        return maps

    for m in maps:
        if m.matches(name):
            return m

    raise KeyError(f"Map '{name}' was not found. Please put the map file in \"/StarCraft II/Maps/\".")

class Map:
    def __init__(self, path):
        self.path = path

        if self.path.is_absolute():
            try:

                self.relative_path = self.path.relative_to(Paths.MAPS)