robolib.traits

traits.py - Generic traits. Should be methods only (no data), so kinda opposite of components. Import level: 1.

 1"""
 2traits.py - Generic traits. Should be methods only (no data), so kinda opposite of components.
 3Import level: 1.
 4"""
 5from __future__ import annotations
 6from abc import ABC, abstractmethod
 7
 8from microecs import World, EntityId
 9
10class Drawable(ABC):
11    """generic drawable object"""
12    @abstractmethod
13    def draw(self, world: World, entity_id: EntityId | None = None):
14        """draws the object"""
15
16class Serializable(ABC):
17    """serializable object"""
18    @abstractmethod
19    def to_dict(self) -> dict:
20        """the dict representation of this object for serialization purposes"""
21
22    @staticmethod
23    @abstractmethod
24    def from_dict(state: dict) -> Serializable:
25        """loads this object from a serialized dict representation"""
26
27class Restorable(ABC):
28    """restorable (inplace) object. Used by Scene and ScenePlugins where recreation (serializable) is not prefered"""
29    @abstractmethod
30    def to_dict(self) -> dict:
31        """the dict representation of this object for serialization purposes"""
32
33    @abstractmethod
34    def load_state_dict(self, state: dict):
35        """Loads in place this object from a serialized dict representation"""
class Drawable(abc.ABC):
11class Drawable(ABC):
12    """generic drawable object"""
13    @abstractmethod
14    def draw(self, world: World, entity_id: EntityId | None = None):
15        """draws the object"""

generic drawable object

@abstractmethod
def draw(self, world: microecs.world.World, entity_id: int | None = None):
13    @abstractmethod
14    def draw(self, world: World, entity_id: EntityId | None = None):
15        """draws the object"""

draws the object

class Serializable(abc.ABC):
17class Serializable(ABC):
18    """serializable object"""
19    @abstractmethod
20    def to_dict(self) -> dict:
21        """the dict representation of this object for serialization purposes"""
22
23    @staticmethod
24    @abstractmethod
25    def from_dict(state: dict) -> Serializable:
26        """loads this object from a serialized dict representation"""

serializable object

@abstractmethod
def to_dict(self) -> dict:
19    @abstractmethod
20    def to_dict(self) -> dict:
21        """the dict representation of this object for serialization purposes"""

the dict representation of this object for serialization purposes

@staticmethod
@abstractmethod
def from_dict(state: dict) -> Serializable:
23    @staticmethod
24    @abstractmethod
25    def from_dict(state: dict) -> Serializable:
26        """loads this object from a serialized dict representation"""

loads this object from a serialized dict representation

class Restorable(abc.ABC):
28class Restorable(ABC):
29    """restorable (inplace) object. Used by Scene and ScenePlugins where recreation (serializable) is not prefered"""
30    @abstractmethod
31    def to_dict(self) -> dict:
32        """the dict representation of this object for serialization purposes"""
33
34    @abstractmethod
35    def load_state_dict(self, state: dict):
36        """Loads in place this object from a serialized dict representation"""

restorable (inplace) object. Used by Scene and ScenePlugins where recreation (serializable) is not prefered

@abstractmethod
def to_dict(self) -> dict:
30    @abstractmethod
31    def to_dict(self) -> dict:
32        """the dict representation of this object for serialization purposes"""

the dict representation of this object for serialization purposes

@abstractmethod
def load_state_dict(self, state: dict):
34    @abstractmethod
35    def load_state_dict(self, state: dict):
36        """Loads in place this object from a serialized dict representation"""

Loads in place this object from a serialized dict representation