Example #1
0
def load_shader(manager, fp, cwd):
    """Loader for shader files.

    The shader file is just a desriptive wrapper around the vert/frag/geom files

    :param manager: The resource manager
    :type manager: :class:`loaders.ResourceManager`

    :param fp: The file pointer
    :type fp: File

    :param cwd: The current working directory
    :type cwd: str

    :returns: The resulting shader program object
    :rtype: :class:`surrender.Shader`
    """
    from surrender import Shader

    shader_data = json.loads(as_utf8(fp.read()))
    shaders = []
    for r in shader_data.get('shaders', []):
        res = manager.get(os.path.join(cwd, r))
        shaders.append(res.data)

    return Shader(*shaders)
Example #2
0
    def handle_joined(self, msg):
        """Handles player joins.

        Instantiates player entities and adds them to the game.

        :param msg: the message to be processed
        :type msg: :class:`message.Message`
        """
        character_name = as_utf8(msg.data[MF.name])
        srv_id = msg.data[MF.id]
        if srv_id != self.context.player_id:
            self.context.players_name_map[srv_id] = character_name
            send_event(CharacterJoin(srv_id, character_name))
Example #3
0
    def handle_joined(self, msg):
        """Handles player joins.

        Instantiates player entities and adds them to the game.

        :param msg: the message to be processed
        :type msg: :class:`message.Message`
        """
        character_name = as_utf8(msg.data[MF.name])
        srv_id = msg.data[MF.id]
        if srv_id != self.context.player_id:
            self.context.players_name_map[srv_id] = character_name
            send_event(CharacterJoin(srv_id, character_name))
def load_data(manager, fp, cwd):
    """Loader for json files.

    :param manager: The resource manager
    :type manager: :class:`loaders.ResourceManager`

    :param fp: The file pointer
    :type fp: File

    :param cwd: The current working directory
    :type cwd: str

    :returns: A dictionary containing the loaded data
    :rtype: dict
    """
    return json.loads(as_utf8(fp.read()))
Example #5
0
def load_data(manager, fp, cwd):
    """Loader for json files.

    :param manager: The resource manager
    :type manager: :class:`loaders.ResourceManager`

    :param fp: The file pointer
    :type fp: File

    :param cwd: The current working directory
    :type cwd: str

    :returns: A dictionary containing the loaded data
    :rtype: dict
    """
    return json.loads(as_utf8(fp.read()))
def load_obj_mesh(manager, fp, cwd):
    """Loader for obj meshes.

    :param manager: The resource manager
    :type manager: :class:`loaders.ResourceManager`

    :param fp: The file pointer
    :type fp: File

    :param cwd: The current working directory
    :type cwd: str

    :returns: The resulting mesh object
    :rtype: :class:`renderer.Mesh`
    """
    from renderlib.mesh import Mesh
    v, n, u, i = load_obj(as_utf8(fp.read()))
    return Mesh(v, i, n, u)
Example #7
0
def load_obj_mesh(manager, fp, cwd):
    """Loader for obj meshes.

    :param manager: The resource manager
    :type manager: :class:`loaders.ResourceManager`

    :param fp: The file pointer
    :type fp: File

    :param cwd: The current working directory
    :type cwd: str

    :returns: The resulting mesh object
    :rtype: :class:`renderer.Mesh`
    """
    from renderlib.mesh import Mesh
    v, n, u, i = load_obj(as_utf8(fp.read()))
    return Mesh(v, i, n, u)
Example #8
0
    def handle_stay(self, msg):
        """Handles stay response from server.

        Assigns the client a server provided id, which uniquely identifies the
        controlled player entity.

        :param msg: the message to be processed
        :type msg: :class:`message.Message`
        """
        srv_id = msg.data[MF.id]
        self.context.player_id = srv_id
        self.context.players_name_map[srv_id] = msg.data[MF.id]
        LOG.info('Joined the party with name "{}" and  ID {}'.format(
            self.context.character_name, self.context.player_id))

        # Send the proper events for the joined local player
        send_event(
            PlayerJoin(self.context.player_id, self.context.character_name))

        for srv_id, name in msg.data[MF.players].items():
            if srv_id != self.context.player_id:
                self.context.players_name_map[srv_id] = name
                send_event(CharacterJoin(srv_id, as_utf8(name)))
Example #9
0
    def handle_stay(self, msg):
        """Handles stay response from server.

        Assigns the client a server provided id, which uniquely identifies the
        controlled player entity.

        :param msg: the message to be processed
        :type msg: :class:`message.Message`
        """
        srv_id = msg.data[MF.id]
        self.context.player_id = srv_id
        self.context.players_name_map[srv_id] = msg.data[MF.id]
        LOG.info('Joined the party with name "{}" and  ID {}'.format(
            self.context.character_name, self.context.player_id))

        # Send the proper events for the joined local player
        send_event(PlayerJoin(
            self.context.player_id, self.context.character_name))

        for srv_id, name in msg.data[MF.players].items():
            if srv_id != self.context.player_id:
                self.context.players_name_map[srv_id] = name
                send_event(CharacterJoin(srv_id, as_utf8(name)))