コード例 #1
0
ファイル: shaders.py プロジェクト: DefaultUser/AssetGenerator
def get_texture_size(shadername):
    shader = find_shader(shadername)
    texpath = shader.texture_path
    # TODO: support custom textures
    if helper.is_git_build():
        return get_texture_size_git_build(texpath)
    return get_texture_size_mapping_support(texpath)
コード例 #2
0
ファイル: shaders.py プロジェクト: DefaultUser/AssetGenerator
def get_texture_size(shadername):
    shader = find_shader(shadername)
    texpath = shader.texture_path
    # TODO: support custom textures
    if helper.is_git_build():
        return get_texture_size_git_build(texpath)
    return get_texture_size_mapping_support(texpath)
コード例 #3
0
ファイル: shaders.py プロジェクト: DefaultUser/AssetGenerator
def parse_shader_file(filename):
    """
    Mini shader parser, only does minimal amount of parsing.
    """
    tokens = re.compile(
        r'''
        (?P<WS>       \s            ) |
        (?P<COMMENT>  //[^\n]*\n    ) |
        (?P<OPEN>     \{            ) |
        (?P<CLOSE>    \}            ) |
        (?P<NUMBER>   -?\d*\.?\d+   ) |
        (?P<VECTOR>   \(\s*(-?\d*\.?\d+)\s+(-?\d*\.?\d+)\s+(-?\d*\.?\d+)\s*\) ) |
        (?P<QUOTED>   (?P<q>"|')[^\r\n]*[^\\](?P=q) ) |
        (?P<STRING>   [^\s]+        )
        ''', re.VERBOSE | re.MULTILINE)

    # TODO: support custom shader files
    if helper.is_git_build():
        path = os.path.join(helper.find_maps_pk3dir(), "scripts", filename)
        with open(path, "r") as sf:
            data = sf.read()
    else:
        with zipfile.ZipFile(helper.find_maps_pk3(), "r") as zf:
            data = zf.read("scripts/" + filename).decode()
    scanner = tokens.scanner(data)
    shaders = []
    match = scanner.match()
    while match:
        if match.lastgroup in ['WS', 'COMMENT']:
            match = scanner.match()
            continue
        if match.lastgroup == 'STRING':
            name = "/".join(match.group().split("/")[1:])
            s = Shader(name, scanner)
            shaders.append(s)
        else:
            print("The given shader file seems to contain errors")
        match = scanner.match()
    return shaders
コード例 #4
0
ファイル: shaders.py プロジェクト: DefaultUser/AssetGenerator
def parse_shader_file(filename):
    """
    Mini shader parser, only does minimal amount of parsing.
    """
    tokens = re.compile(r'''
        (?P<WS>       \s            ) |
        (?P<COMMENT>  //[^\n]*\n    ) |
        (?P<OPEN>     \{            ) |
        (?P<CLOSE>    \}            ) |
        (?P<NUMBER>   -?\d*\.?\d+   ) |
        (?P<VECTOR>   \(\s*(-?\d*\.?\d+)\s+(-?\d*\.?\d+)\s+(-?\d*\.?\d+)\s*\) ) |
        (?P<QUOTED>   (?P<q>"|')[^\r\n]*[^\\](?P=q) ) |
        (?P<STRING>   [^\s]+        )
        ''', re.VERBOSE | re.MULTILINE)

    # TODO: support custom shader files
    if helper.is_git_build():
        path = os.path.join(helper.find_maps_pk3dir(), "scripts", filename)
        with open(path, "r") as sf:
            data = sf.read()
    else:
        with zipfile.ZipFile(helper.find_maps_pk3(), "r") as zf:
            data = zf.read("scripts/" + filename).decode()
    scanner = tokens.scanner(data)
    shaders = []
    match = scanner.match()
    while match:
        if match.lastgroup in ['WS', 'COMMENT']:
            match = scanner.match()
            continue
        if match.lastgroup == 'STRING':
            name = "/".join(match.group().split("/")[1:])
            s = Shader(name, scanner)
            shaders.append(s)
        else:
            print("The given shader file seems to contain errors")
        match = scanner.match()
    return shaders