Ejemplo n.º 1
0
    def test_active_and_inactive_updates_two_subentities(self):
        class TestEntity(crest.Entity):
            sub = TestSubEntity()
            sub2 = TestSubEntity()
            inf = crest.Influence(source=sub.out1, target=sub.in1)
            influence2 = crest.Influence(source=sub.out2, target=sub2.in1)

            active = current = crest.State()
            inactive = crest.State()

            up_active = crest.Update(state=active,
                                     target=sub.in2,
                                     function=(lambda self, dt: 0))
            up_inactive = crest.Update(state=inactive,
                                       target=sub.in2,
                                       function=(lambda self, dt: 0))

        ent = TestEntity()

        ent.sub._dependencies = [
            crest.Dependency(ent.sub.out1, ent.sub.in2),
            crest.Dependency(ent.sub.out2, ent.sub.in1)
        ]

        self.assertListEqual([
            ent.up_active, ent.sub, ent.inf, ent.sub, ent.influence2, ent.sub2
        ], ordered_modifiers(ent))
Ejemplo n.º 2
0
    def test_assert_dependency_spec_breaks_cycle2(self):
        class TestEntity(crest.Entity):
            sub = TestSubEntity()
            inf = crest.Influence(source=sub.out1, target=sub.in1)

        ent = TestEntity()
        ent.sub._dependencies = [
            crest.Dependency(ent.sub.out1, ent.sub.in1),
            crest.Dependency(ent.sub.out2, ent.sub.in2)
        ]

        self.assertRaises(AssertionError, ordered_modifiers, ent)
Ejemplo n.º 3
0
    def test_assert_dependency_spec_breaks_cycle_need_repetition(self):
        class TestEntity(crest.Entity):
            sub = TestSubEntity()
            inf = crest.Influence(source=sub.out1, target=sub.in1)

        ent = TestEntity()
        ent.sub._dependencies = [
            crest.Dependency(ent.sub.out1, ent.sub.in2),
            crest.Dependency(ent.sub.out2, ent.sub.in1)
        ]

        self.assertListEqual([ent.sub, ent.inf, ent.sub],
                             ordered_modifiers(ent))
Ejemplo n.º 4
0
def _add_dependency(source, target):

    if not isinstance(source, crest.Output):
        raise ValueError(
            f"Source object '{get_name(source)}' is not an Output port.")
    if not isinstance(target, crest.Input):
        raise ValueError(
            f"Target object '{get_name(target)}' is not an Input port.")

    source_parent = get_parent(source)
    target_parent = get_parent(target)
    if source_parent is None or target_parent is None:
        raise ValueError(
            "Either the source or the target port are not inside an entity")

    if source_parent is not target_parent:  # we connect inside the same entity
        raise ValueError(
            "The source and target need to belong to the same entity.")

    new_dependency = crest.Dependency(source=source, target=target)

    if hasattr(source_parent, meta.DEPENDENCY_IDENTIFIER):
        getattr(source_parent,
                meta.DEPENDENCY_IDENTIFIER).append(new_dependency)
    else:
        setattr(source_parent, meta.DEPENDENCY_IDENTIFIER, [new_dependency])