Пример #1
0
    def remove_entity(self, _ent: Entity):
        # ENTITY deletion flag
        _ent.deleted = True
        # Check for entity existence and delete it from any of the following containers
        if _ent in self._entities.values():
            self._entities.pop(_ent.name, None)

        _ordered_list: List[Entity] = self._entities_ordered[_ent.get_layer()]
        if _ent in _ordered_list:
            self._entities_ordered[_ent.get_layer()].remove(_ent)

        if _ent.get_component(
                Rigidbody
        ) is not None and _ent in self._dynamic_entities.values():
            self._dynamic_entities.pop(_ent.name, None)
Пример #2
0
    def add_entity(self, _ent: Entity):
        if _ent is None:
            return

        # Add static collider if no rigidbody is present
        ColliderManager_2D.get_singleton().add(_ent)

        # Add to list of all entities
        self._entities[_ent.name] = _ent

        # Add to list of ordered entities
        _depth: int = _ent.get_layer()

        if _depth not in self._entities_ordered:
            # Create empty slot
            self._entities_ordered[_depth] = []
            # Add entity to sorted list
            self._entities_ordered[_depth].append(_ent)
            # Sort Dictionary
            self._entities_ordered = OrderedDict(
                sorted(self._entities_ordered.items(), key=lambda t: t[0]))
        else:
            # Add entity to sorted list
            self._entities_ordered[_depth].append(_ent)

        # Add to dynamic entities
        if _ent.get_component(Rigidbody) is not None:
            self._dynamic_entities[_ent.name] = _ent