SynergyCollection.get_objects()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
dl 0
loc 2
rs 10
1
from synergine.core.config.ConfigurationManager import ConfigurationManager
2
from synergine.core.Signals import Signals
3
from synergine.lib.eint import IncrementedNamedInt
4
5
6
class SynergyCollection:
7
    """
8
    Object containing list of SynergyObject and some logical actions listing what
9
    concern this collection.
10
    """
11
12
    SIGNAL_ADD_OBJECT = 'collection.add_object'
13
    SIGNAL_REMOVE_OBJECT = 'collection.remove_object'
14
15
    def __init__(self, configuration: ConfigurationManager):
16
        self._configuration = configuration
17
        self._objects = []
18
        self._actions = []
19
        self._id = IncrementedNamedInt.get(self)
20
21
    def get_id(self):
22
        return self._id
23
24
    def initialize_objects(self, context):
25
        self.set_objects(self._configuration.get_start_objects(self, context))
26
        for obj in self._objects:
27
            obj.initialize()
28
29
    def get_actions(self) -> list:
30
        return self._actions
31
32
    def get_objects(self) -> list:
33
        return self._objects
34
35
    def set_objects(self, objects: list):
36
        for obj in objects:
37
            try:
38
                self._objects.index(obj)
39
            except ValueError:
40
                Signals.signal(self.SIGNAL_ADD_OBJECT).send(collection=self, obj=obj)
41
                self._objects.append(obj)
42
43
    def remove_object(self, obj):
44
        Signals.signal(self.SIGNAL_REMOVE_OBJECT).send(collection=self, obj=obj)
45
        self._objects.remove(obj)
46
47
    def add_object(self, obj):
48
        self._objects.append(obj)
49
        Signals.signal(self.SIGNAL_ADD_OBJECT).send(collection=self, obj=obj)
50
51
    def get_computable_objects(self) -> list:
52
        """
53
        TODO: Implementer un processus generique pour que les SynergyObject
54
        puissent n'etre execute que tous les x cycles
55
        :return: object who are computable
56
        """
57
        return self._objects
58
59
    def get_objects_to_display(self) -> list:
60
        """
61
        :return: object to display by Display object
62
        """
63
        return self._objects
64