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()
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]))
def test_make_aspect_from_assemblage(self): factory = Assemblage(components=[Portable]) aspect = Aspect.make_from(factory) 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.assertTrue(aspect.is_interested_in(self.brains)) self.assertFalse(aspect.is_interested_in(self.zombie)) self.assertEqual(aspect.select_entities(self.entities), set([self.cat, self.brains]))
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]))
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]))
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]))
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]))
def __init__(self, world): super(NameSystem, self).__init__(world=world, aspect=Aspect(all_of=set([Name]))) self.names = defaultdict(lambda: None) self.update()
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)
def __init__(self, world): super(ViewSystem, self).__init__(world=world, aspect=Aspect(all_of=set([View])))
def __init__(self, world): super(DescriptionSystem, self).__init__(world=world, aspect=Aspect(all_of=set([Description]))) self.description_values = defaultdict(lambda: dict) self.update()
import random import re from braga import Aspect from braga.examples import duel from hogwarts.engine.Command import Command, ChangefulCommand from hogwarts.engine.exceptions import LogicError player_aspect = Aspect.make_from(duel.player_factory) # Command Responses def _look(world, player): return player.location.description def _inventory(world, player): return '/n'.join([thing.name for thing in player.inventory]) def _red_sparks(world, player): return "A stream of red sparks shoots out the end of your wand!\n\nJustin's wand spins out of his hand and flies to you.\nYour casting skill for the expelliarmus spell has increased." def _get_skill(world, player): return "\n".join([ str(player.skill), "Your chance of success is {}/20.".format( _get_expelliarmus_skill(player)) ])
def __init__(self, world): super(ContextSystem, self).__init__(world=world, aspect=Aspect(all_of=set([components.Contexts])))