Ejemplo n.º 1
0
    def __init__(self, world):
        super(ContainerSystem,
              self).__init__(world=world,
                             aspect=Aspect(all_of=set([Container])))

        for entity in self.world.entities_with_aspect(
                Aspect(all_of=set([Moveable]))):
            entity.location.inventory.add(entity)

        self.update()
Ejemplo n.º 2
0
    def test_aspect_is_interested_in_exclude(self):
        aspect = Aspect(exclude=set([Container]))

        self.assertFalse(aspect.is_interested_in(self.cat))
        self.assertTrue(aspect.is_interested_in(self.plant))
        self.assertFalse(aspect.is_interested_in(self.bathtub))
        self.assertTrue(aspect.is_interested_in(self.brains))
        self.assertFalse(aspect.is_interested_in(self.zombie))

        self.assertEqual(aspect.select_entities(self.entities),
                         set([self.plant, self.brains]))
Ejemplo n.º 3
0
    def test_aspect_is_interested_in_all_of(self):
        aspect = Aspect(all_of=set([Alive, Portable]))

        self.assertTrue(aspect.is_interested_in(self.cat))
        self.assertFalse(aspect.is_interested_in(self.plant))
        self.assertFalse(aspect.is_interested_in(self.bathtub))
        self.assertFalse(aspect.is_interested_in(self.brains))
        self.assertFalse(aspect.is_interested_in(self.zombie))

        self.assertEqual(aspect.select_entities(self.entities),
                         set([self.cat]))
Ejemplo n.º 4
0
    def test_aspect_is_interested_in_some_of(self):
        aspect = Aspect(some_of=set([Location, Container]))

        self.assertTrue(aspect.is_interested_in(self.cat))
        self.assertFalse(aspect.is_interested_in(self.plant))
        self.assertTrue(aspect.is_interested_in(self.bathtub))
        self.assertTrue(aspect.is_interested_in(self.brains))
        self.assertTrue(aspect.is_interested_in(self.zombie))

        self.assertEqual(
            aspect.select_entities(self.entities),
            set([self.cat, self.bathtub, self.brains, self.zombie]))
Ejemplo n.º 5
0
    def test_aspect_is_interested_in_different_categories(self):
        aspect = Aspect(all_of=set([Container]),
                        exclude=set([Moveable]),
                        some_of=set([Location, Portable, Alive]))

        self.assertTrue(aspect.is_interested_in(self.cat))
        self.assertFalse(aspect.is_interested_in(self.plant))
        self.assertFalse(aspect.is_interested_in(self.bathtub))
        self.assertFalse(aspect.is_interested_in(self.brains))
        self.assertFalse(aspect.is_interested_in(self.zombie))

        self.assertEqual(aspect.select_entities(self.entities),
                         set([self.cat]))
Ejemplo n.º 6
0
 def update(self):
     """Updates the `inventory` attribute on all Containers in the World"""
     for entity in self.world.entities_with_aspect(
             Aspect(all_of=set([Moveable]))):
         entity.location.inventory.add(entity)
Ejemplo n.º 7
0
 def __init__(self, world):
     super(ViewSystem, self).__init__(world=world,
                                      aspect=Aspect(all_of=set([View])))
Ejemplo n.º 8
0
 def __init__(self, world):
     super(DescriptionSystem,
           self).__init__(world=world,
                          aspect=Aspect(all_of=set([Description])))
     self.description_values = defaultdict(lambda: dict)
     self.update()
Ejemplo n.º 9
0
 def __init__(self, world):
     super(NameSystem, self).__init__(world=world,
                                      aspect=Aspect(all_of=set([Name])))
     self.names = defaultdict(lambda: None)
     self.update()
Ejemplo n.º 10
0
 def __init__(self, world):
     super(ContextSystem, self).__init__(world=world, aspect=Aspect(all_of=set([components.Contexts])))