def play_stop_to_str(renpy_nodes, renpy_ast, node, acc):
    cmd = re.findall(WORD, node.line)

    next = real_next(renpy_nodes, renpy_ast, node.next)
    id_nexts = [str(id(next))] if next else []

    if  cmd[0] == 'play' and len(cmd) >= 3:
        channel = cmd[1]
        file = cmd[2][1:-1]
        snd_name = remove_invalid_chars(file)
        acc['sounds'][snd_name] = file
        acc['nodes'][id(node)] = {
            'class_name': 'Play',
            'arguments': [
                channel,
                snd_name,
                id_nexts
            ]
        }
        return [next]

    elif cmd[0] == 'voice' and len(cmd) >= 2:
        file = cmd[1][1:-1]
        snd_name = remove_invalid_chars(file)
        acc['sounds'][snd_name] = file
        acc['nodes'][id(node)] = {
            'class_name': 'Play',
            'arguments': [
                'voice',
                snd_name,
                id_nexts
            ]
        }
        return [next]

    elif cmd[0] == 'stop' and len(cmd) >= 2:
        channel = cmd[1]
        acc['nodes'][id(node)] = {
            'class_name': 'Stop',
            'arguments': [
                channel,
                id_nexts
            ]
        }
        return [next]

    else:
        print('[WARNING] unrecognized UserStatement: %s, didn\'t continue this branch.' % node.line)
예제 #2
0
def python_to_str(GAME_BASE_DIR, renpy, node, res):
    next = real_next(renpy, node.next)
    id_nexts = [str(id(next))] if next else []

    match = re.search(VIDEO, node.code.source)

    if match != None and len(match.groups()) == 1:  # it's a video
        file = match.group(1)[1:-1]
        vid_name = remove_invalid_chars(file)
        load_media(GAME_BASE_DIR, res, 'videos', vid_name, file)
        res['nodes'][id(node)] = {
            'class_name': 'Video',
            'arguments': [vid_name, [str(id(next))] if next else []]
        }
    else:
        match = re.search(PLAY, node.code.source)

        if match != None and len(match.groups()) == 1:  # it's a sound play
            args = [arg.strip() for arg in match.group(1).split(',')]
            loop = find_map(get_loop, args[1:])
            play_to_str(GAME_BASE_DIR, node, id_nexts, res, args[0][1:-1],
                        'sound', loop)

        else:
            res['nodes'][id(node)] = {
                'class_name': 'PyExpr',
                'arguments': [replace_bools(node.code.source), id_nexts]
            }

    return [next]
def python_to_str(renpy_nodes, renpy_ast, node, acc):
    next = real_next(renpy_nodes, renpy_ast, node.next)

    match = re.search(VIDEO, node.code.source)

    if match != None and len(match.groups()) == 1: # it's a video
        file = match.group(1)[1:-1]
        vid_name = remove_invalid_chars(file)
        acc['videos'][vid_name] = file
        acc['nodes'][id(node)] = {
            'class_name': 'Video',
            'arguments': [
                vid_name,
                [str(id(next))] if next else []
            ]
        }
    else:
        acc['nodes'][id(node)] = {
            'class_name': 'PyExpr',
            'arguments': [
                replace_bools(node.code.source),
                [str(id(next))] if next else []
            ]
        }
    return [next]
예제 #4
0
def play_to_str(GAME_BASE_DIR, node, id_nexts, res, file, channel, loop):
    snd_name = remove_invalid_chars(file)

    _, ext = path.splitext(file)
    media_type = 'videos' if ext in VIDEO_EXTENSION else 'sounds'
    load_media(GAME_BASE_DIR, res, media_type, snd_name, file)

    res['nodes'][id(node)] = {
        'class_name': 'Play',
        'arguments': [channel, snd_name, loop, id_nexts]
    }
예제 #5
0
    def res(usage, gui_attr, fonts):
        fpath = guiattr(gui, gui_attr, DEFAULT_FONT)
        full_fpath = find_font(GAME_BASE_DIR, RENPY_BASE_DIR, fpath)

        if full_fpath:
            fname = remove_invalid_chars(fpath).lower()
            if fname in fonts["definitions"]:
                # definition already exists
                fonts["usages"][usage] = fname
            else:
                fonts["definitions"][fname] = {
                    "src": full_fpath,
                    "bold": False
                }
                fonts["usages"][usage] = fname
        else:
            ("[WARNING] couldn't find font \"%s\", replacing with default font"
             % fpath)
            fonts["usages"][usage] = DEFAULT_FONT_NAME
예제 #6
0
    def res(usage, gui_attr, fonts):
        fpath = guiattr(gui, gui_attr, DEFAULT_FONT)
        full_fpath = find_font(GAME_BASE_DIR, RENPY_BASE_DIR, fpath)

        if full_fpath:
            fname = remove_invalid_chars(fpath).lower()
            if fname in fonts['definitions']:
                # definition already exists
                fonts['usages'][usage] = fname
            else:
                fonts['definitions'][fname] = {
                    'src': full_fpath,
                    'bold': False
                }
                fonts['usages'][usage] = fname
        else:
            ('[WARNING] couldn\'t find font \'%s\', replacing with default font'
             % fpath)
            fonts['usages'][usage] = DEFAULT_FONT_NAME
예제 #7
0
    def download(self, filename, url, outdir=None):
        if outdir is None:
            outdir = self.outdir

        if not os.path.exists(outdir):
            os.makedirs(outdir)

        filename = utils.remove_invalid_chars(filename)
        filename = os.path.join(outdir, filename)

        response = requests.get(url, stream=True)

        if os.path.exists(filename):
            return filename

        with open(filename, 'wb') as f:
            for chunk in response.iter_content(chunk_size=1024):
                if chunk:
                    f.write(chunk)

        return filename
예제 #8
0
from os import path

from utils import remove_invalid_chars, guiattr

DEFAULT_FONT = "DejaVuSans.ttf"
DEFAULT_FONT_NAME = remove_invalid_chars(DEFAULT_FONT).lower()


def parse(GAME_BASE_DIR, RENPY_BASE_DIR, gui):
    """
    Parse fonts.
    """
    res = {
        "definitions": {
            # "font_family": {
            #     "src": str,
            #     "bold": bool
            # },
            # ...
        },
        "usages": {
            # "dialog": "font_family"
            # ...
        }
    }

    # add default font definition
    file = find_font(GAME_BASE_DIR, RENPY_BASE_DIR, DEFAULT_FONT)
    if file:
        if not DEFAULT_FONT_NAME in res["definitions"]:
            res["definitions"][DEFAULT_FONT_NAME] = {"src": file, "bold": True}