Merge branch 'main' into refactor_rename

# Conflicts:
#	marl_factory_grid/environment/entity/entity.py
#	marl_factory_grid/modules/destinations/entitites.py
#	marl_factory_grid/modules/doors/entitites.py
#	marl_factory_grid/modules/items/groups.py
This commit is contained in:
Chanumask
2023-10-20 15:39:01 +02:00
41 changed files with 267 additions and 215 deletions

View File

@@ -1,8 +1,12 @@
import abc
from collections import defaultdict
import numpy as np
from .object import Object
from .. import constants as c
from .object import EnvObject
from ...utils.utility_classes import RenderEntity
from ...utils.render import RenderEntity
from ...utils.results import ActionResult
@@ -62,30 +66,33 @@ class Entity(Object, abc.ABC):
def pos(self):
return self._pos
# @property
# def last_tile(self):
# try:
# return self._last_tile
# except AttributeError:
# # noinspection PyAttributeOutsideInit
# self._last_tile = None
# return self._last_tile
@property
def last_pos(self):
try:
return self._last_pos
except AttributeError:
# noinspection PyAttributeOutsideInit
self._last_pos = c.VALUE_NO_POS
return self._last_pos
@property
def direction_of_view(self):
last_x, last_y = self._last_pos
curr_x, curr_y = self.pos
return last_x - curr_x, last_y - curr_y
if self._last_pos != c.VALUE_NO_POS:
return 0, 0
else:
return np.subtract(self._last_pos, self.pos)
def move(self, next_pos, state):
next_pos = next_pos
curr_pos = self._pos
if not_same_pos := curr_pos != next_pos:
if valid := state.check_move_validity(self, next_pos):
self._pos = next_pos
self._last_pos = curr_pos
for observer in self.observers:
observer.notify_change_pos(self)
observer.notify_del_entity(self)
self._view_directory = curr_pos[0]-next_pos[0], curr_pos[1]-next_pos[1]
self._pos = next_pos
for observer in self.observers:
observer.notify_add_entity(self)
return valid
return not_same_pos
@@ -93,6 +100,7 @@ class Entity(Object, abc.ABC):
super().__init__(**kwargs)
self._status = None
self._pos = pos
self._last_pos = pos
if bind_to:
try:
self.bind_to(bind_to)