47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
import importlib
|
|
import pkgutil
|
|
from enum import StrEnum
|
|
from typing import Optional, Self
|
|
|
|
import pygame
|
|
|
|
import src.objects
|
|
from src.camera import Camera
|
|
from src.vec import Vec
|
|
|
|
|
|
class TrackObjectType(StrEnum):
|
|
Road = "road"
|
|
|
|
Unknown = "unknown"
|
|
|
|
|
|
class TrackObject:
|
|
REGISTRY = {}
|
|
type: TrackObjectType = TrackObjectType.Unknown
|
|
|
|
@staticmethod
|
|
def init():
|
|
package = src.objects
|
|
for _, modname, _ in pkgutil.walk_packages(
|
|
package.__path__, package.__name__ + "."
|
|
):
|
|
importlib.import_module(modname)
|
|
|
|
def __init_subclass__(cls, **kwargs) -> None:
|
|
super().__init_subclass__(**kwargs)
|
|
TrackObject.REGISTRY[cls.type] = cls
|
|
|
|
@classmethod
|
|
def load(cls, data: dict) -> Self:
|
|
obj_type: Optional[TrackObjectType] = data.get("type")
|
|
if obj_type not in cls.REGISTRY:
|
|
raise ValueError(f"Unknown object tyoe: {obj_type}")
|
|
return cls.REGISTRY[obj_type].load(data)
|
|
|
|
def render(self, surf: pygame.Surface, camera: Camera):
|
|
pass
|
|
|
|
def get_collision_polygons(self) -> list[list[Vec]]:
|
|
return []
|