Exemplo n.º 1
0
 def chat_command(self, username, parameters):
     if parameters:
         return self.specific_help(retrieve_plugins(IChatCommand,
             parameters=self.pp),
             "".join(parameters))
     else:
         return self.general_help(retrieve_plugins(IChatCommand,
             parameters=self.pp))
Exemplo n.º 2
0
 def console_command(self, parameters):
     if parameters:
         return self.specific_help(retrieve_plugins(IConsoleCommand,
             parameters=self.pp),
             "".join(parameters))
     else:
         return self.general_help(retrieve_plugins(IConsoleCommand,
             parameters=self.pp))
Exemplo n.º 3
0
 def console_command(self, parameters):
     if parameters:
         return self.specific_help(retrieve_plugins(IConsoleCommand,
             parameters=self.pp),
             "".join(parameters))
     else:
         return self.general_help(retrieve_plugins(IConsoleCommand,
             parameters=self.pp))
Exemplo n.º 4
0
 def chat_command(self, username, parameters):
     if parameters:
         return self.specific_help(retrieve_plugins(IChatCommand,
             parameters=self.pp),
             "".join(parameters))
     else:
         return self.general_help(retrieve_plugins(IChatCommand,
             parameters=self.pp))
Exemplo n.º 5
0
    def check_recipes(self):
        """
        See if the crafting table matches any recipes.

        :returns: the recipe and offset, or None if no matches could be made
        """

        # This isn't perfect, unfortunately, but correctness trumps algorithmic
        # perfection. (For now.)
        for name, recipe in sorted(retrieve_plugins(IRecipe).iteritems()):
            dims = recipe.dimensions

            # Skip recipes that don't fit our crafting table.
            if (dims[0] > self.crafting_stride or
                dims[1] > len(self.crafting) // self.crafting_stride):
                continue

            padded = pad_to_stride(recipe.recipe, dims[0],
                self.crafting_stride)

            for offset in range(len(self.crafting) - len(padded) + 1):
                nones = self.crafting[:offset]
                nones += self.crafting[len(padded) + offset:]
                if not all(i is None for i in nones):
                    continue

                matches_needed = len(padded)

                for i, j in zip(padded,
                    self.crafting[offset:len(padded) + offset]):
                    if i is None and j is None:
                        matches_needed -= 1
                    elif i is not None and j is not None:
                        skey, scount = i
                        if j.holds(skey) and j.quantity >= scount:
                            matches_needed -= 1

                    if matches_needed == 0:
                        # Jackpot!
                        self.recipe = recipe
                        self.recipe_offset = offset
                        return

        # Try to check free-form recipes. Sort the table's occupied slots and
        # compare to the recipe's slots.
        # XXX can fail if the recipe's ingredients aren't sorted
        crafting = sorted(
            (i.primary, i.secondary) for i in self.crafting if i)
        # XXX is there any reason to sort these here? Do they overlap?
        for name, recipe in sorted(retrieve_plugins(IStraightRecipe).iteritems()):
            if (crafting == recipe.ingredients):
                # Jackpot!
                self.recipe = recipe
                # XXX :T
                self.recipe_offset = -128 # indicates the recipe if straight recipe
                return

        self.recipe = None
Exemplo n.º 6
0
    def __init__(self, factories):
        self.factories = factories

        # XXX hax
        self.commands = retrieve_plugins(IConsoleCommand)
        # And chat commands, too.
        chat = retrieve_plugins(IChatCommand)
        for name, plugin in chat.iteritems():
            self.commands[name] = IConsoleCommand(plugin)
        # Register aliases.
        for plugin in self.commands.values():
            for alias in plugin.aliases:
                self.commands[alias] = plugin
Exemplo n.º 7
0
    def __init__(self, factories):
        self.factories = factories

        # XXX hax
        self.commands = retrieve_plugins(IConsoleCommand)
        # And chat commands, too.
        chat = retrieve_plugins(IChatCommand)
        for name, plugin in chat.iteritems():
            self.commands[name] = IConsoleCommand(plugin)
        # Register aliases.
        for plugin in self.commands.values():
            for alias in plugin.aliases:
                self.commands[alias] = plugin
Exemplo n.º 8
0
Arquivo: web.py Projeto: tazjel/bravo
def bravo_site(services):
    # extract worlds and non-world services only once at startup
    worlds = {}
    other_services = {}
    for name, service in services.iteritems():
        factory = service.args[1]
        if isinstance(factory, BravoFactory):
            worlds[factory.name] = factory
        else:
            # XXX: do we really need those ?
            other_services[name] = factory
    # add site root
    root = Resource()
    root.putChild('', BravoResource(BravoRootElement(worlds, other_services)))
    # add world sub pages and related plugins
    for world, factory in worlds.iteritems():
        # Discover parameterized plugins.
        plugins = retrieve_plugins(IWorldResource,
                                   parameters={"factory": factory})
        # add sub page
        child = BravoResource(BravoWorldElement(factory, plugins), False)
        root.putChild(world, child)
        # add plugins
        for name, resource in plugins.iteritems():
            # add plugin page
            child.putChild(name, resource)
    # create site
    site = Site(root)
    return site
Exemplo n.º 9
0
    def chat(self, container):
        # data = json.loads(container.data)
        log.msg("Chat! %r" % container.data)
        if container.message.startswith("/"):
            commands = retrieve_plugins(IChatCommand, factory=self.factory)
            # Register aliases.
            for plugin in commands.values():
                for alias in plugin.aliases:
                    commands[alias] = plugin

            params = container.message[1:].split(" ")
            command = params.pop(0).lower()

            if command and command in commands:
                def cb(iterable):
                    for line in iterable:
                        self.send_chat(line)

                def eb(error):
                    self.send_chat("Error: %s" % error.getErrorMessage())

                d = maybeDeferred(commands[command].chat_command,
                                  self.username, params)
                d.addCallback(cb)
                d.addErrback(eb)
            else:
                self.send_chat("Unknown command: %s" % command)
        else:
            # Send the message up to the factory to be chatified.
            message = "<%s> %s" % (self.username, container.message)
            self.factory.chat(message)
Exemplo n.º 10
0
    def setUp(self):
        # Set up world.
        self.name = "unittest"
        self.d = tempfile.mkdtemp()

        bravo.config.configuration.add_section("world unittest")
        bravo.config.configuration.set("world unittest", "url",
            "file://%s" % self.d)
        bravo.config.configuration.set("world unittest", "serializer",
            "alpha")

        self.w = World(self.name)
        self.w.pipeline = []
        self.w.start()

        # And finally the mock factory.
        self.f = RedstoneMockFactory()
        self.f.world = self.w

        pp = {"factory": self.f}
        self.p = retrieve_plugins(IDigHook, parameters=pp)

        if "redstone" not in self.p:
            raise unittest.SkipTest("Plugin not present")

        self.hook = self.p["redstone"]
Exemplo n.º 11
0
Arquivo: beta.py Projeto: mkaay/bravo
    def chat(self, container):
        if container.message.startswith("/"):
            pp = {"factory": self.factory}

            commands = retrieve_plugins(IChatCommand, parameters=pp)
            # Register aliases.
            for plugin in commands.values():
                for alias in plugin.aliases:
                    commands[alias] = plugin

            params = container.message[1:].split(" ")
            command = params.pop(0).lower()

            if command and command in commands:

                def cb(iterable):
                    for line in iterable:
                        self.transport.write(make_packet("chat", message=line))

                def eb(error):
                    self.transport.write(make_packet("chat", message="Error: %s" % error.getErrorMessage()))

                d = maybeDeferred(commands[command].chat_command, self.username, params)
                d.addCallback(cb)
                d.addErrback(eb)
            else:
                self.transport.write(make_packet("chat", message="Unknown command: %s" % command))
        else:
            # Send the message up to the factory to be chatified.
            message = "<%s> %s" % (self.username, container.message)
            self.factory.chat(message)
Exemplo n.º 12
0
    def chat(self, container):
        # data = json.loads(container.data)
        log.msg("Chat! %r" % container.data)
        if container.message.startswith("/"):
            commands = retrieve_plugins(IChatCommand, factory=self.factory)
            # Register aliases.
            for plugin in commands.values():
                for alias in plugin.aliases:
                    commands[alias] = plugin

            params = container.message[1:].split(" ")
            command = params.pop(0).lower()

            if command and command in commands:
                def cb(iterable):
                    for line in iterable:
                        self.send_chat(line)

                def eb(error):
                    self.send_chat("Error: %s" % error.getErrorMessage())

                d = maybeDeferred(commands[command].chat_command,
                                  self.username, params)
                d.addCallback(cb)
                d.addErrback(eb)
            else:
                self.send_chat("Unknown command: %s" % command)
        else:
            # Send the message up to the factory to be chatified.
            message = "<%s> %s" % (self.username, container.message)
            self.factory.chat(message)
Exemplo n.º 13
0
    def chat(self, container):
        if container.message.startswith("/"):

            commands = retrieve_plugins(IChatCommand)
            # Register aliases.
            for plugin in commands.values():
                for alias in plugin.aliases:
                    commands[alias] = plugin

            params = container.message[1:].split(" ")
            command = params.pop(0).lower()

            if command and command in commands:
                try:
                    for line in commands[command].chat_command(self.factory,
                        self.username, params):
                        self.transport.write(
                            make_packet("chat", message=line)
                        )
                except Exception, e:
                    self.transport.write(
                        make_packet("chat", message="Error: %s" % e)
                    )
            else:
                self.transport.write(
                    make_packet("chat",
                        message="Unknown command: %s" % command)
                )
Exemplo n.º 14
0
    def setUp(self):
        # Set up world.
        self.name = "unittest"
        self.d = tempfile.mkdtemp()
        self.bcp = BravoConfigParser()

        self.bcp.add_section("world unittest")
        self.bcp.set("world unittest", "url", "file://%s" % self.d)
        self.bcp.set("world unittest", "serializer", "alpha")

        self.w = World(self.bcp, self.name)
        self.w.pipeline = []
        self.w.start()

        # And finally the mock factory.
        self.f = RedstoneMockFactory()
        self.f.world = self.w

        pp = {"factory": self.f}
        self.p = retrieve_plugins(IDigHook, parameters=pp)

        if "redstone" not in self.p:
            raise unittest.SkipTest("Plugin not present")

        self.hook = self.p["redstone"]
Exemplo n.º 15
0
    def chat(self, container):
        if container.message.startswith("/"):
            pp = {"factory": self.factory}

            commands = retrieve_plugins(IChatCommand, parameters=pp)
            # Register aliases.
            for plugin in commands.values():
                for alias in plugin.aliases:
                    commands[alias] = plugin

            params = container.message[1:].split(" ")
            command = params.pop(0).lower()

            if command and command in commands:

                def cb(iterable):
                    for line in iterable:
                        self.write_packet("chat", message=line)

                def eb(error):
                    self.write_packet("chat",
                                      message="Error: %s" %
                                      error.getErrorMessage())

                d = maybeDeferred(commands[command].chat_command,
                                  self.username, params)
                d.addCallback(cb)
                d.addErrback(eb)
            else:
                self.write_packet("chat",
                                  message="Unknown command: %s" % command)
        else:
            # Send the message up to the factory to be chatified.
            message = "<%s> %s" % (self.username, container.message)
            self.factory.chat(message)
Exemplo n.º 16
0
    def chat(self, container):
        if container.message.startswith("/"):

            commands = retrieve_plugins(IChatCommand)
            # Register aliases.
            for plugin in commands.values():
                for alias in plugin.aliases:
                    commands[alias] = plugin

            params = container.message[1:].split(" ")
            command = params.pop(0).lower()

            if command and command in commands:
                try:
                    for line in commands[command].chat_command(self.factory,
                        self.username, params):
                        self.transport.write(
                            make_packet("chat", message=line)
                        )
                except Exception, e:
                    self.transport.write(
                        make_packet("chat", message="Error: %s" % e)
                    )
            else:
                self.transport.write(
                    make_packet("chat",
                        message="Unknown command: %s" % command)
                )
Exemplo n.º 17
0
    def __init__(self, factory):
        self.factory = factory

        self.commands = retrieve_plugins(IConsoleCommand)
        # Register aliases.
        for plugin in self.commands.values():
            for alias in plugin.aliases:
                self.commands[alias] = plugin
Exemplo n.º 18
0
    def update_season(self):
        """
        Update the world's season.
        """

        for plugin in retrieve_plugins(ISeason).itervalues():
            if plugin.day == self.day:
                self.world.season = plugin
Exemplo n.º 19
0
 def __init__(self, worlds):
     self.factories = dict((factory.name, factory) for factory in worlds)
     # XXX hax
     self.commands = retrieve_plugins(IConsoleCommand)
     # Register aliases.
     for plugin in self.commands.values():
         for alias in plugin.aliases:
             self.commands[alias] = plugin
Exemplo n.º 20
0
    def __init__(self, factories):
        self.factories = factories

        # XXX hax
        self.commands = retrieve_plugins(IConsoleCommand)
        # Register aliases.
        for plugin in self.commands.values():
            for alias in plugin.aliases:
                self.commands[alias] = plugin
Exemplo n.º 21
0
    def setUp(self):
        self.f = TrackMockFactory()
        self.p = retrieve_plugins(IPostBuildHook,
            parameters={"factory": self.f})

        if "tracks" not in self.p:
            raise SkipTest("Plugin not present")

        self.hook = self.p["tracks"]
Exemplo n.º 22
0
    def setUp(self):
        self.f = FallablesMockFactory()
        self.p = retrieve_plugins(IDigHook, parameters={"factory": self.f})

        if "alpha_sand_gravel" not in self.p:
            raise unittest.SkipTest("Plugin not present")

        self.hook = self.p["alpha_sand_gravel"]
        self.c = Chunk(0, 0)
Exemplo n.º 23
0
    def setUp(self):
        self.d = tempfile.mkdtemp()
        self.folder = FilePath(self.d)

        plugins = retrieve_plugins(ISerializer)
        if "alpha" not in plugins:
            raise unittest.SkipTest("Plugin not present")

        self.s = plugins["alpha"]
        self.s.connect("file://" + self.folder.path)
Exemplo n.º 24
0
    def setUp(self):
        self.d = tempfile.mkdtemp()
        self.folder = FilePath(self.d)

        plugins = retrieve_plugins(ISerializer)
        if "anvil" not in plugins:
            raise unittest.SkipTest("Plugin not present")

        self.s = plugins["anvil"]
        self.s.connect("file://" + self.folder.path)
Exemplo n.º 25
0
    def check_recipes(self):
        """
        See if the crafting table matches any recipes.

        :returns: None
        """

        self.recipe = None

        for name, recipe in retrieve_plugins(IRecipe).iteritems():
            if recipe.matches(self.crafting, self.crafting_stride):
                self.recipe = recipe
Exemplo n.º 26
0
    def check_recipes(self):
        """
        See if the crafting table matches any recipes.

        :returns: None
        """

        self.recipe = None

        for name, recipe in retrieve_plugins(IRecipe).iteritems():
            if recipe.matches(self.crafting, self.crafting_stride):
                self.recipe = recipe
Exemplo n.º 27
0
    def dispatch(self, factory):
        hours, minutes = split_time(factory.time)

        # Check if the world has seasons enabled
        seasons = retrieve_plugins(ISeason).values()
        if seasons:
            season = factory.world.season
            day_of_season = factory.day - season.day
            while day_of_season < 0:
                day_of_season += 360
            date = "{0} ({1} {2})".format(factory.day, day_of_season, season.name)
        else:
            date = "%d" % factory.day
        yield "%02d:%02d, %s" % (hours, minutes, date)
Exemplo n.º 28
0
    def check_recipes(self):
        """
        See if the crafting table matches any recipes.

        :returns: the recipe and offset, or None if no matches could be made
        """

        # This isn't perfect, unfortunately, but correctness trumps algorithmic
        # perfection. (For now.)
        for name, recipe in sorted(retrieve_plugins(IRecipe).iteritems()):
            dims = recipe.dimensions

            # Skip recipes that don't fit our crafting table.
            if (dims[0] > self.crafting_stride
                    or dims[1] > len(self.crafting) // self.crafting_stride):
                continue

            padded = pad_to_stride(recipe.recipe, dims[0],
                                   self.crafting_stride)

            for offset in range(len(self.crafting) - len(padded) + 1):
                nones = self.crafting[:offset]
                nones += self.crafting[len(padded) + offset:]
                if not all(i is None for i in nones):
                    continue

                matches_needed = len(padded)

                for i, j in zip(padded,
                                self.crafting[offset:len(padded) + offset]):
                    if i is None and j is None:
                        matches_needed -= 1
                    elif i is not None and j is not None:
                        cprimary, csecondary, ccount = j
                        skey, scount = i
                        if ((cprimary, csecondary) == skey
                                and ccount >= scount):
                            matches_needed -= 1

                    if matches_needed == 0:
                        # Jackpot!
                        self.recipe = recipe
                        self.recipe_offset = offset
                        return

        self.recipe = None
Exemplo n.º 29
0
    def setUp(self):
        self.bcp = BravoConfigParser()

        self.bcp.add_section("world unittest")
        self.bcp.set("world unittest", "url", "")
        self.bcp.set("world unittest", "serializer", "memory")

        self.w = World(self.bcp, "unittest")
        self.w.pipeline = []
        self.w.start()

        self.f = GrassMockFactory()
        self.f.world = self.w
        self.w.factory = self.f

        plugins = retrieve_plugins(IAutomaton, factory=self.f)
        self.hook = plugins["grass"]
Exemplo n.º 30
0
    def check_recipes(self):
        """
        See if the crafting table matches any recipes.

        :returns: the recipe and offset, or None if no matches could be made
        """

        # This isn't perfect, unfortunately, but correctness trumps algorithmic
        # perfection. (For now.)
        for name, recipe in sorted(retrieve_plugins(IRecipe).iteritems()):
            dims = recipe.dimensions

            # Skip recipes that don't fit our crafting table.
            if (dims[0] > self.crafting_stride or
                dims[1] > len(self.crafting) // self.crafting_stride):
                continue

            padded = pad_to_stride(recipe.recipe, dims[0],
                self.crafting_stride)

            for offset in range(len(self.crafting) - len(padded) + 1):
                nones = self.crafting[:offset]
                nones += self.crafting[len(padded) + offset:]
                if not all(i is None for i in nones):
                    continue

                matches_needed = len(padded)

                for i, j in zip(padded,
                    self.crafting[offset:len(padded) + offset]):
                    if i is None and j is None:
                        matches_needed -= 1
                    elif i is not None and j is not None:
                        cprimary, csecondary, ccount = j
                        skey, scount = i
                        if ((cprimary, csecondary) == skey
                            and ccount >= scount):
                            matches_needed -= 1

                    if matches_needed == 0:
                        # Jackpot!
                        self.recipe = recipe
                        self.recipe_offset = offset
                        return

        self.recipe = None
Exemplo n.º 31
0
    def setUp(self):
        plugins = retrieve_plugins(IAutomaton)

        if "grass" not in plugins:
            raise unittest.SkipTest("Plugin not present")

        self.hook = plugins["grass"]

        self.d = tempfile.mkdtemp()

        configuration.add_section("world unittest")
        configuration.set("world unittest", "url", "file://%s" % self.d)
        configuration.set("world unittest", "serializer", "alpha")

        self.w = World("unittest")
        self.w.pipeline = []

        self.f = GrassMockFactory()
        self.f.world = self.w
Exemplo n.º 32
0
    def setUp(self):
        # Set up world.
        self.name = "unittest"
        self.bcp = BravoConfigParser()

        self.bcp.add_section("world unittest")
        self.bcp.set("world unittest", "url", "")
        self.bcp.set("world unittest", "serializer", "memory")

        self.w = World(self.bcp, self.name)
        self.w.pipeline = []
        self.w.start()

        # And finally the mock factory.
        self.f = RedstoneMockFactory()
        self.f.world = self.w

        self.p = retrieve_plugins(IDigHook, factory=self.f)
        self.hook = self.p["redstone"]
Exemplo n.º 33
0
    def setUp(self):
        # Set up world.
        self.name = "unittest"
        self.bcp = BravoConfigParser()

        self.bcp.add_section("world unittest")
        self.bcp.set("world unittest", "url", "")
        self.bcp.set("world unittest", "serializer", "memory")

        self.w = World(self.bcp, self.name)
        self.w.pipeline = []
        self.w.start()

        # And finally the mock factory.
        self.f = RedstoneMockFactory()
        self.f.world = self.w

        self.p = retrieve_plugins(IDigHook, factory=self.f)
        self.hook = self.p["redstone"]
Exemplo n.º 34
0
    def dispatch(self, factory):
        hours, minutes = split_time(factory.time)

        # Find seasons, and figure out which season we're in.
        seasons = retrieve_plugins(ISeason).values()
        seasons.sort(reverse=True, key=lambda season: season.day)
        if seasons:
            if all(s.day > factory.day for s in seasons):
                # We are too close to the beginning of the year; grab the last
                # season of "last" year.
                date = "%d (%d %s)" % (factory.day,
                    factory.day + 360 - seasons[0].day, seasons[0].name)
            else:
                # Grab the closest season, Price-is-Right-style.
                season = (s for s in seasons if s.day <= factory.day).next()
                date = "%d (%d %s)" % (factory.day, factory.day - season.day,
                    season.name)
        else:
            date = "%d" % factory.day
        yield "%02d:%02d, %s" % (hours, minutes, date)
Exemplo n.º 35
0
    def make_chunk(self, x, z, seed, generators):
        """
        Create a chunk using the given parameters.
        """

        plugins = retrieve_plugins(ITerrainGenerator)
        stages = [plugins[g] for g in generators.split(",")]

        chunk = Chunk(x, z)

        for stage in stages:
            stage.populate(chunk, seed)

        return {
            "blocks": "".join(chr(i) for i in chunk.blocks.ravel()),
            "metadata": "".join(chr(i) for i in chunk.metadata.ravel()),
            "skylight": "".join(chr(i) for i in chunk.skylight.ravel()),
            "blocklight": "".join(chr(i) for i in chunk.blocklight.ravel()),
            "heightmap": "".join(chr(i) for i in chunk.heightmap.ravel()),
        }
Exemplo n.º 36
0
    def make_chunk(self, x, z, seed, generators):
        """
        Create a chunk using the given parameters.
        """

        plugins = retrieve_plugins(ITerrainGenerator)
        stages = [plugins[g] for g in generators]

        chunk = Chunk(x, z)

        for stage in stages:
            stage.populate(chunk, seed)

        return {
            "blocks": chunk.blocks.tostring(),
            "metadata": chunk.metadata.tostring(),
            "skylight": chunk.skylight.tostring(),
            "blocklight": chunk.blocklight.tostring(),
            "heightmap": chunk.heightmap.tostring(),
        }
Exemplo n.º 37
0
    def dispatch(self, factory):
        hours, minutes = split_time(factory.time)

        # Find seasons, and figure out which season we're in.
        seasons = retrieve_plugins(ISeason).values()
        seasons.sort(reverse=True, key=lambda season: season.day)
        if seasons:
            if all(s.day > factory.day for s in seasons):
                # We are too close to the beginning of the year; grab the last
                # season of "last" year.
                date = "%d (%d %s)" % (factory.day, factory.day + 360 -
                                       seasons[0].day, seasons[0].name)
            else:
                # Grab the closest season, Price-is-Right-style.
                season = (s for s in seasons if s.day <= factory.day).next()
                date = "%d (%d %s)" % (factory.day, factory.day - season.day,
                                       season.name)
        else:
            date = "%d" % factory.day
        yield "%02d:%02d, %s" % (hours, minutes, date)
Exemplo n.º 38
0
    def check_recipes(self):
        """
        See if the crafting table matches any recipes.

        :returns: the recipe and offset, or None if no matches could be made
        """

        # This isn't perfect, unfortunately, but correctness trumps algorithmic
        # perfection. (For now.)
        crafting = self.crafting_table
        for recipe in retrieve_plugins(IRecipe).itervalues():
            dims = recipe.dimensions

            for x, y in crafting.iterkeys():
                if (x + dims[1] > self.crafting_stride or
                    y + dims[0] > self.crafting_stride):
                    continue

                indices = product(xrange(x, x + dims[1]),
                    xrange(y, y + dims[0]))

                matches_needed = dims[0] * dims[1]

                for index, slot in zip(indices, recipe.recipe):

                    if crafting[index] is None and slot is None:
                        matches_needed -= 1
                    elif crafting[index] is not None and slot is not None:
                        cprimary, csecondary, ccount = crafting[index]
                        skey, scount = slot
                        if ((cprimary, csecondary) == skey
                            and ccount >= scount):
                            matches_needed -= 1

                    if matches_needed == 0:
                        # Jackpot!
                        self.recipe = recipe
                        self.recipe_offset = (x, y)
                        return

        self.recipe = None
Exemplo n.º 39
0
 def dispatch(self, factory):
     # 24000 ticks to the day
     hours, minutes = divmod(factory.time, 1000)
     # 0000 is noon, not midnight
     hours = hours + 12 % 24
     minutes = minutes * 6 / 100
     # Find seasons, and figure out which season we're in.
     seasons = retrieve_plugins(ISeason).values()
     seasons.sort(reverse=True, key=lambda season: season.day)
     if seasons:
         if all(s.day > factory.day for s in seasons):
             # We are too close to the beginning of the year; grab the last
             # season of "last" year.
             date = "%d (%d %s)" % (factory.day,
                 factory.day + 360 - seasons[0].day, seasons[0].name)
         else:
             # Grab the closest season, Price-is-Right-style.
             season = next(s for s in seasons if s.day <= factory.day)
             date = "%d (%d %s)" % (factory.day, factory.day - season.day,
                 season.name)
     else:
         date = "%d" % factory.day
     yield "%02d:%02d, %s" % (hours, minutes, date)
Exemplo n.º 40
0
    def setUp(self):
        self.d = tempfile.mkdtemp()
        self.bcp = BravoConfigParser()

        self.bcp.add_section("world unittest")
        self.bcp.set("world unittest", "url", "file://%s" % self.d)
        self.bcp.set("world unittest", "serializer", "alpha")

        self.w = World(self.bcp, "unittest")
        self.w.pipeline = []
        self.w.start()

        self.f = GrassMockFactory()
        self.f.world = self.w
        self.w.factory = self.f

        pp = {"factory": self.f}

        plugins = retrieve_plugins(IAutomaton, parameters=pp)

        if "grass" not in plugins:
            raise unittest.SkipTest("Plugin not present")

        self.hook = plugins["grass"]
Exemplo n.º 41
0
    def setUp(self):
        self.d = tempfile.mkdtemp()
        self.bcp = BravoConfigParser()

        self.bcp.add_section("world unittest")
        self.bcp.set("world unittest", "url", "file://%s" % self.d)
        self.bcp.set("world unittest", "serializer", "alpha")

        self.w = World(self.bcp, "unittest")
        self.w.pipeline = []
        self.w.start()

        self.f = GrassMockFactory()
        self.f.world = self.w
        self.w.factory = self.f

        pp = {"factory": self.f}

        plugins = retrieve_plugins(IAutomaton, parameters=pp)

        if "grass" not in plugins:
            raise unittest.SkipTest("Plugin not present")

        self.hook = plugins["grass"]
Exemplo n.º 42
0
 def console_command(self, parameters):
     plugins = retrieve_plugins(IConsoleCommand, factory=self.factory)
     if parameters:
         return self.specific_help(plugins, "".join(parameters))
     else:
         return self.general_help(plugins)
Exemplo n.º 43
0
 def console_command(self, factory, parameters):
     for i in self.dispatch(retrieve_plugins(IConsoleCommand)):
         yield i
Exemplo n.º 44
0
 def chat_command(self, factory, username, parameters):
     for i in self.dispatch(retrieve_plugins(IChatCommand)):
         yield i
Exemplo n.º 45
0
 def chat_command(self, username, parameters):
     plugins = retrieve_plugins(IChatCommand, factory=self.factory)
     if parameters:
         return self.specific_help(plugins, "".join(parameters))
     else:
         return self.general_help(plugins)
Exemplo n.º 46
0
    generators = configuration.getlist("bravo", "generators")
    generators = retrieve_named_plugins(ITerrainGenerator, generators)

    before = time.time()

    for i in range(10):
        chunk = Chunk(i, i)
        for generator in generators:
            generator.populate(chunk, 0)

    after = time.time()

    return after - before

plugins = retrieve_plugins(ITerrainGenerator)

if len(sys.argv) > 1:
    plugins = {sys.argv[1]: plugins[sys.argv[1]]}

t = empty_chunk()
print "Baseline: %f seconds" % t

for name, plugin in plugins.iteritems():
    t = sequential_seeded(plugin)
    print "Sequential %s: %f seconds" % (name, t)
    t = repeated_seeds(plugin)
    print "Repeated %s: %f seconds" % (name, t)

t = pipeline()
print "Total pipeline: %f seconds" % t
Exemplo n.º 47
0
 def setUp(self):
     self.f = FallablesMockFactory()
     self.p = retrieve_plugins(IDigHook, factory=self.f)
     self.hook = self.p["alpha_sand_gravel"]
     self.c = Chunk(0, 0)
Exemplo n.º 48
0
 def chat_command(self, factory, username, parameters):
     for i in self.dispatch(retrieve_plugins(IChatCommand)):
         yield i
Exemplo n.º 49
0
 def setUp(self):
     self.f = TrackMockFactory()
     self.p = retrieve_plugins(IPostBuildHook, factory=self.f)
     self.hook = self.p["tracks"]
Exemplo n.º 50
0
    def setUp(self):
        recipes = retrieve_plugins(IRecipe)
        if "furnace" not in recipes:
            raise unittest.SkipTest("Plugin not present")

        self.i = Workbench()
Exemplo n.º 51
0
    def setUp(self):
        recipes = retrieve_plugins(IRecipe)
        if "wood" not in recipes:
            raise unittest.SkipTest("Plugin not present")

        self.i = Crafting()
Exemplo n.º 52
0
 def setUp(self):
     self.p = retrieve_plugins(IRecipe)
Exemplo n.º 53
0
    def setUp(self):
        plugins = retrieve_plugins(ISerializer)
        if "alpha" not in plugins:
            raise unittest.SkipTest("Plugin not present")

        self.serializer = plugins["alpha"]
Exemplo n.º 54
0
from __future__ import division

from itertools import product
import sys
import time

from bravo.config import BravoConfigParser
from bravo.ibravo import ITerrainGenerator
from bravo.plugin import retrieve_plugins
from bravo.world import World

if len(sys.argv) <= 3:
    print "Not enough arguments."
    sys.exit()

d = retrieve_plugins(ITerrainGenerator)

size = int(sys.argv[1])
pipeline = [d[name] for name in sys.argv[2].split(",")]
target = sys.argv[3]

print "Making map of %dx%d chunks in %s" % (size, size, target)
print "Using pipeline: %s" % ", ".join(plugin.name for plugin in pipeline)

config = BravoConfigParser()
config.add_section("world mapgen")
config.set("world mapgen", "url", target)
config.set("world mapgen", "serializer", "beta")

world = World(config, "mapgen")
world.connect()
Exemplo n.º 55
0
 def console_command(self, factory, parameters):
     for i in self.dispatch(retrieve_plugins(IConsoleCommand)):
         yield i
Exemplo n.º 56
0
#!/usr/bin/env python

from bravo.ibravo import (IDigHook, IPostBuildHook, IPreBuildHook, IRecipe,
                          ISeason, ISerializer, ITerrainGenerator, IUseHook)
from bravo.plugin import retrieve_plugins

for interface in (IDigHook, IPostBuildHook, IPreBuildHook, IRecipe, ISeason,
                  ISerializer, ITerrainGenerator, IUseHook):
    print "Interface: %s" % interface
    print "Number of plugins: %d" % len(retrieve_plugins(interface))
    print "Available plugins:"
    for name, plugin in sorted(retrieve_plugins(interface).items()):
        print " ~ %s" % name