mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-06-23 12:01:36 +02:00
fix mismatching signatures of spawn
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
from typing import List, Tuple
|
||||
from typing import List, Tuple, Union
|
||||
|
||||
from marl_factory_grid.environment.entity.entity import Entity
|
||||
from marl_factory_grid.environment.groups.objects import _Objects
|
||||
from marl_factory_grid.environment.entity.object import _Object
|
||||
import marl_factory_grid.environment.constants as c
|
||||
|
||||
|
||||
class Collection(_Objects):
|
||||
@ -40,6 +41,18 @@ class Collection(_Objects):
|
||||
super(Collection, self).__init__(*args, **kwargs)
|
||||
self.size = size
|
||||
|
||||
def spawn(self, coords_or_quantity: Union[int, List[Tuple[(int, int)]]], *entity_args): # woihn mit den args
|
||||
if isinstance(coords_or_quantity, int):
|
||||
self.add_items([self._entity() for _ in range(coords_or_quantity)])
|
||||
else:
|
||||
self.add_items([self._entity(pos) for pos in coords_or_quantity])
|
||||
return c.VALID
|
||||
|
||||
def despawn(self, items: List[_Object]):
|
||||
items = [items] if isinstance(items, _Object) else items
|
||||
for item in items:
|
||||
del self[item]
|
||||
|
||||
def add_item(self, item: Entity):
|
||||
assert self.var_has_position or (len(self) <= self.size)
|
||||
super(Collection, self).add_item(item)
|
||||
@ -67,9 +80,6 @@ class Collection(_Objects):
|
||||
except (StopIteration, AttributeError):
|
||||
return None
|
||||
|
||||
def spawn(self, coords: List[Tuple[(int, int)]]):
|
||||
self.add_items([self._entity(pos) for pos in coords])
|
||||
|
||||
def render(self):
|
||||
return [y for y in [x.render() for x in self] if y is not None]
|
||||
|
||||
|
@ -125,26 +125,6 @@ class _Objects:
|
||||
repr_dict = {key: val for key, val in self._data.items() if key not in [c.WALLS]}
|
||||
return f'{self.__class__.__name__}[{repr_dict}]'
|
||||
|
||||
def spawn(self, n: int):
|
||||
self.add_items([self._entity() for _ in range(n)])
|
||||
return c.VALID
|
||||
|
||||
def despawn(self, items: List[_Object]):
|
||||
items = [items] if isinstance(items, _Object) else items
|
||||
for item in items:
|
||||
del self[item]
|
||||
|
||||
# def notify_change_pos(self, entity: object):
|
||||
# try:
|
||||
# self.pos_dict[entity.last_pos].remove(entity)
|
||||
# except (ValueError, AttributeError):
|
||||
# pass
|
||||
# if entity.var_has_position:
|
||||
# try:
|
||||
# self.pos_dict[entity.pos].append(entity)
|
||||
# except (ValueError, AttributeError):
|
||||
# pass
|
||||
|
||||
def notify_del_entity(self, entity: _Object):
|
||||
try:
|
||||
entity.del_observer(self)
|
||||
|
@ -15,14 +15,6 @@ class Walls(Collection):
|
||||
super(Walls, self).__init__(*args, **kwargs)
|
||||
self._value = c.VALUE_OCCUPIED_CELL
|
||||
|
||||
#ToDo: Do we need this? Move to spawn methode?
|
||||
# @classmethod
|
||||
# def from_coordinates(cls, argwhere_coordinates, *args, **kwargs):
|
||||
# tiles = cls(*args, **kwargs)
|
||||
# # noinspection PyTypeChecker
|
||||
# tiles.add_items([cls._entity(pos) for pos in argwhere_coordinates])
|
||||
# return tiles
|
||||
|
||||
def by_pos(self, pos: (int, int)):
|
||||
try:
|
||||
return super().by_pos(pos)[0]
|
||||
|
Reference in New Issue
Block a user