示例#1
0
文件: __init__.py 项目: megeek/unrpyc
    def print_menu(self, ast):
        self.indent()
        self.write("menu")
        if self.label_inside_menu is not None:
            self.write(" %s" % self.label_inside_menu.name)
            self.label_inside_menu = None

        if hasattr(ast, "arguments") and ast.arguments is not None:
            self.write(reconstruct_arginfo(ast.arguments))

        self.write(":")

        with self.increase_indent():
            if self.say_inside_menu is not None:
                self.print_say(self.say_inside_menu, inmenu=True)
                self.say_inside_menu = None

            if ast.with_ is not None:
                self.indent()
                self.write("with %s" % ast.with_)

            if ast.set is not None:
                self.indent()
                self.write("set %s" % ast.set)

            if hasattr(ast, "item_arguments"):
                item_arguments = ast.item_arguments
            else:
                item_arguments = [None] * len(ast.items)

            for (label, condition,
                 block), arguments in zip(ast.items, item_arguments):
                if self.translator:
                    label = self.translator.strings.get(label, label)

                if isinstance(condition, unicode):
                    self.advance_to_line(condition.linenumber)
                self.indent()
                self.write('"%s"' % string_escape(label))

                if arguments is not None:
                    self.write(reconstruct_arginfo(arguments))

                if block is not None:
                    if isinstance(condition, unicode):
                        self.write(" if %s" % condition)
                    self.write(":")
                    self.print_nodes(block, 1)
示例#2
0
    def print_call_location(self, ast):
        self.indent()
        self.write("call location %s" % ast.location)

        if self.label_inside_call_location is not None:
            self.write(" %s" % self.label_inside_call_location.name)
            self.label_inside_call_location = None

        self.write(":")

        with self.increase_indent():
            for zone, props, condition, show, block in ast.zones:
                self.indent()
                words = WordConcatenator(False)
                if isinstance(zone, tuple):
                    zone, image_name, zorder, behind = zone
                    words.append(zone)
                    words.append(*image_name)
                    if zorder is not None:
                        words.append("zorder %s" % zorder)
                    if behind:
                        words.append("behind %s" % ','.join(behind))
                else:
                    words.append(zone)
                if props is not None:
                    words.append("pass %s" % reconstruct_arginfo(props))
                if isinstance(show, renpy.ast.PyExpr):
                    words.append("showif %s" % show)
                if isinstance(condition, renpy.ast.PyExpr):
                    words.append("if %s" % condition)
                self.write("%s:" % words.join())
                self.print_nodes(block, 1)
示例#3
0
    def print_use(self, ast):
        # A use statement requires reconstructing the arguments it wants to pass
        self.indent()
        self.write("use %s%s" % (ast.target, reconstruct_arginfo(ast.args)))
        if hasattr(ast, 'id') and ast.id is not None:
            self.write(" id %s" % ast.id)

        if hasattr(ast, 'block') and ast.block:
            self.write(":")
            self.print_block(ast.block)
示例#4
0
    def print_use(self, ast):
        # A use statement requires reconstructing the arguments it wants to pass
        self.indent()
        self.write("use ")
        args = reconstruct_arginfo(ast.args)
        if isinstance(ast.target, PyExpr):
            self.write("expression %s" % ast.target)
            if args:
                self.write(" pass ")
        else:
            self.write("%s" % ast.target)

        self.write("%s" % reconstruct_arginfo(ast.args))
        if hasattr(ast, 'id') and ast.id is not None:
            self.write(" id %s" % ast.id)

        if hasattr(ast, 'block') and ast.block:
            self.write(":")
            self.print_block(ast.block)
示例#5
0
    def print_use(self, ast):
        # A use statement requires reconstructing the arguments it wants to pass
        self.indent()
        self.write("use %s%s" % (ast.target, reconstruct_arginfo(ast.args)))
        if hasattr(ast, 'id') and ast.id is not None:
            self.write(" id %s" % ast.id)

        if hasattr(ast, 'block') and ast.block:
            self.write(":")
            self.print_block(ast.block)
示例#6
0
    def print_menu_item(self, label, condition, block, arguments):
        self.indent()
        self.write('"%s"' % string_escape(label))

        if arguments is not None:
            self.write(reconstruct_arginfo(arguments))

        if block is not None:
            if isinstance(condition, unicode):
                self.write(" if %s" % condition)
            self.write(":")
            self.print_nodes(block, 1)
示例#7
0
    def print_call(self, ast):
        self.indent()
        self.write("call ")
        if ast.expression:
            self.write("expression %s" % ast.label)
        else:
            self.write(ast.label)

        if ast.arguments is not None:
            if ast.expression:
                self.write(" pass ")
            self.write(reconstruct_arginfo(ast.arguments))
示例#8
0
    def print_call(self, ast):
        self.indent()
        words = WordConcatenator(False)
        words.append("call")
        if ast.expression:
            words.append("expression")
        words.append(ast.label)

        if hasattr(ast, 'arguments') and ast.arguments is not None:
            if ast.expression:
                words.append("pass")
            words.append(reconstruct_arginfo(ast.arguments))

        # We don't have to check if there's enough elements here,
        # since a Label or a Pass is always emitted after a Call.
        next_block = self.block[self.index + 1]
        if isinstance(next_block, renpy.ast.Label):
            words.append("from %s" % next_block.name)

        self.write(words.join())
示例#9
0
    def print_call(self, ast):
        self.indent()
        words = WordConcatenator(False)
        words.append("call")
        if ast.expression:
            words.append("expression")
        words.append(ast.label)

        if ast.arguments is not None:
            if ast.expression:
                words.append("pass")
            words.append(reconstruct_arginfo(ast.arguments))

        # We don't have to check if there's enough elements here,
        # since a Label or a Pass is always emitted after a Call.
        next_block = self.block[self.index + 1]
        if isinstance(next_block, renpy.ast.Label):
            words.append("from %s" % next_block.name)

        self.write(words.join())
示例#10
0
    def print_menu(self, ast):
        self.indent()
        self.write("menu")
        if self.label_inside_menu is not None:
            self.write(" %s" % self.label_inside_menu.name)
            self.label_inside_menu = None

        if hasattr(ast, "arguments") and ast.arguments is not None:
            self.write(reconstruct_arginfo(ast.arguments))

        self.write(":")

        with self.increase_indent():
            if ast.with_ is not None:
                self.indent()
                self.write("with %s" % ast.with_)

            if ast.set is not None:
                self.indent()
                self.write("set %s" % ast.set)

            if hasattr(ast, "item_arguments"):
                item_arguments = ast.item_arguments
            else:
                item_arguments = [None] * len(ast.items)

            for (label, condition, block), arguments in zip(ast.items, item_arguments):
                if self.translator:
                    label = self.translator.strings.get(label, label)

                state = None

                # if the condition is a unicode subclass with a "linenumber" attribute it was script.
                # If it isn't ren'py used to insert a "True" string. This string used to be of type str
                # but nowadays it's of time unicode, just not of type PyExpr
                if isinstance(condition, unicode) and hasattr(condition, "linenumber"):
                    if self.say_inside_menu is not None and condition.linenumber > self.linenumber + 1:
                        # The easy case: we know the line number that the menu item is on, because the condition tells us
                        # So we put the say statement here if there's room for it, or don't if there's not
                        self.print_say_inside_menu()
                    self.advance_to_line(condition.linenumber)
                elif self.say_inside_menu is not None:
                    # The hard case: we don't know the line number that the menu item is on
                    # So try to put it in, but be prepared to back it out if that puts us behind on the line number
                    state = self.save_state()
                    self.most_lines_behind = self.last_lines_behind
                    self.print_say_inside_menu()

                self.print_menu_item(label, condition, block, arguments)

                if state is not None:
                    if self.most_lines_behind > state[7]: # state[7] is the saved value of self.last_lines_behind
                        # We tried to print the say statement that's inside the menu, but it didn't fit here
                        # Undo it and print this item again without it. We'll fit it in later
                        self.rollback_state(state)
                        self.print_menu_item(label, condition, block, arguments)
                    else:
                        self.most_lines_behind = max(state[6], self.most_lines_behind) # state[6] is the saved value of self.most_lines_behind
                        self.commit_state(state)

            if self.say_inside_menu is not None:
                # There was no room for this before any of the menu options, so it will just have to go after them all
                self.print_say_inside_menu()
示例#11
0
 def print_use(self, ast):
     # A use statement requires reconstructing the arguments it wants to pass
     self.indent()
     self.write("use %s%s" % (ast.target, reconstruct_arginfo(ast.args)))
示例#12
0
 def print_use(self, ast):
     # A use statement requires reconstructing the arguments it wants to pass
     self.indent()
     self.write("use %s%s" % (ast.target, reconstruct_arginfo(ast.args)))