def print_screen(self, ast): # Here we do the processing of the screen statement, and we # switch over to parsing of the python string representation # Print the screen statement and create the block self.indent() self.write("screen %s" % ast.name) # If we have parameters, print them. if hasattr(ast, "parameters") and ast.parameters: self.write(reconstruct_paraminfo(ast.parameters)) if ast.tag: self.write(" tag %s" % ast.tag) keywords = {ast.code.location[1]: WordConcatenator(False)} for key in ('modal', 'zorder', 'variant', 'predict'): value = getattr(ast, key) # Non-Unicode strings are default values rather than user-supplied # values, so we don't need to write them out. if isinstance(value, unicode): if value.linenumber not in keywords: keywords[value.linenumber] = WordConcatenator(False) keywords[value.linenumber].append(key) keywords[value.linenumber].append(value) keywords = sorted([(k, v.join()) for k, v in keywords.items()], key=itemgetter(0)) # so the first one is right if self.decompile_python: self.print_keywords_and_nodes(keywords, None, True) self.indent_level += 1 self.indent() self.write("python:") self.indent_level += 1 # The first line is always "_1 = (_name, 0)", which gets included # even if the python: block is the only thing in the screen. Don't # include ours, since if we do, it'll be included twice when # recompiled. for line in self.to_source(ast.code.source).splitlines()[1:]: self.indent() self.write(line) self.indent_level -= 2 else: self.print_keywords_and_nodes(keywords, ast.code.source.body, False)
def print_style(self, ast): keywords = {ast.linenumber: WordConcatenator(False)} # These don't store a line number, so just put them on the first line if ast.parent is not None: keywords[ast.linenumber].append("is %s" % ast.parent) if ast.clear: keywords[ast.linenumber].append("clear") if ast.take is not None: keywords[ast.linenumber].append("take %s" % ast.take) for delname in ast.delattr: keywords[ast.linenumber].append("del %s" % delname) # These do store a line number if ast.variant is not None: if ast.variant.linenumber not in keywords: keywords[ast.variant.linenumber] = WordConcatenator(False) keywords[ast.variant.linenumber].append("variant") keywords[ast.variant.linenumber].append(ast.variant) for key, value in ast.properties.iteritems(): if value.linenumber not in keywords: keywords[value.linenumber] = WordConcatenator(False) keywords[value.linenumber].append(key) keywords[value.linenumber].append(value) keywords = sorted([(k, v.join()) for k, v in keywords.items()], key=itemgetter(0)) self.indent() self.write("style %s" % ast.style_name) if keywords[0][1]: self.write(" %s" % keywords[0][1]) if len(keywords) > 1: self.write(":") self.indent_level += 1 for i in keywords[1:]: self.advance_to_line(i[0]) self.indent() self.write(i[1]) self.indent_level -= 1
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())
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)
def print_imspec(self, imspec): if imspec[1] is not None: begin = "expression %s" % imspec[1] else: begin = " ".join(imspec[0]) words = WordConcatenator(begin and begin[-1] != ' ', True) if imspec[2] is not None: words.append("as %s" % imspec[2]) if len(imspec[6]) > 0: words.append("behind %s" % ', '.join(imspec[6])) if isinstance(imspec[4], unicode): words.append("onlayer %s" % imspec[4]) if imspec[5] is not None: words.append("zorder %s" % imspec[5]) if len(imspec[3]) > 0: words.append("at %s" % ', '.join(imspec[3])) self.write(begin + words.join()) return words.needs_space
def print_atl_rawmulti(self, ast): warp_words = WordConcatenator(False) # warpers if ast.warp_function: warp_words.append("warp", ast.warp_function, ast.duration) elif ast.warper: warp_words.append(ast.warper, ast.duration) elif ast.duration != "0": warp_words.append("pause", ast.duration) warp = warp_words.join() words = WordConcatenator(warp and warp[-1] != ' ', True) # revolution if ast.revolution: words.append(ast.revolution) # circles if ast.circles != "0": words.append("circles %s" % ast.circles) # splines spline_words = WordConcatenator(False) for name, expressions in ast.splines: spline_words.append(name, expressions[-1]) for expression in expressions[:-1]: spline_words.append("knot", expression) words.append(spline_words.join()) # properties property_words = WordConcatenator(False) for key, value in ast.properties: property_words.append(key, value) words.append(property_words.join()) # with expression_words = WordConcatenator(False) # TODO There's a lot of cases where pass isn't needed, since we could # reorder stuff so there's never 2 expressions in a row. (And it's never # necessary for the last one, but we don't know what the last one is # since it could get reordered.) needs_pass = len(ast.expressions) > 1 for (expression, with_expression) in ast.expressions: expression_words.append(expression) if with_expression: expression_words.append("with", with_expression) if needs_pass: expression_words.append("pass") words.append(expression_words.join()) to_write = warp + words.join() if to_write: self.indent() self.write(to_write) else: # A trailing comma results in an empty RawMultipurpose being # generated on the same line as the last real one. self.write(",")
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())
def print_imspec(self, imspec): if imspec[1] is not None: begin = "expression %s" % imspec[1] else: begin = " ".join(imspec[0]) words = WordConcatenator(begin and begin[-1] != " ", True) if imspec[2] is not None: words.append("as %s" % imspec[2]) if len(imspec[6]) > 0: words.append("behind %s" % ", ".join(imspec[6])) if imspec[4] != "master": words.append("onlayer %s" % imspec[4]) if imspec[5] is not None: words.append("zorder %s" % imspec[5]) if len(imspec[3]) > 0: words.append("at %s" % ", ".join(imspec[3])) self.write(begin + words.join()) return words.needs_space
def print_atl_rawmulti(self, ast): self.indent() words = WordConcatenator(False) # TODO: Make this allow reordering too # warpers if ast.warp_function: words.append("warp", ast.warp_function, ast.duration) elif ast.warper: words.append(ast.warper, ast.duration) elif ast.duration != "0": words.append("pause", ast.duration) # revolution if ast.revolution: words.append(ast.revolution) # circles if ast.circles != "0": words.append("circles", ast.circles) # splines for name, expressions in ast.splines: words.append(name) for expression in expressions: words.append("knot", expression) # properties for key, value in ast.properties: words.append(key, value) # with for (expression, with_expression) in ast.expressions: words.append(expression) if with_expression: words.append("with", with_expression) self.write(words.join())
def print_atl_rawmulti(self, ast): self.indent() warp_words = WordConcatenator(False) # warpers if ast.warp_function: warp_words.append("warp", ast.warp_function, ast.duration) elif ast.warper: warp_words.append(ast.warper, ast.duration) elif ast.duration != "0": warp_words.append("pause", ast.duration) warp = warp_words.join() words = WordConcatenator(warp and warp[-1] != ' ', True) # revolution if ast.revolution: words.append(ast.revolution) # circles if ast.circles != "0": words.append("circles %s" % ast.circles) # splines spline_words = WordConcatenator(False) for name, expressions in ast.splines: spline_words.append(name) for expression in expressions: spline_words.append("knot", expression) words.append(spline_words.join()) # properties property_words = WordConcatenator(False) for key, value in ast.properties: property_words.append(key, value) words.append(property_words.join()) # with expression_words = WordConcatenator(False) # TODO There's a lot of cases where pass isn't needed, since we could # reorder stuff so there's never 2 expressions in a row. (And it's never # necessary for the last one, but we don't know what the last one is # since it could get reordered.) needs_pass = len(ast.expressions) > 1 for (expression, with_expression) in ast.expressions: expression_words.append(expression) if with_expression: expression_words.append("with", with_expression) if needs_pass: expression_words.append("pass") words.append(expression_words.join()) self.write(warp + words.join())
def print_imspec(self, imspec): words = WordConcatenator(False) if imspec[1] is not None: words.append("expression %s" % imspec[1]) else: words.append(" ".join(imspec[0])) if imspec[2] is not None: words.append("as %s" % imspec[2]) if len(imspec[6]) > 0: words.append("behind %s" % ', '.join(imspec[6])) if imspec[4] != "master": words.append("onlayer %s" % imspec[4]) if imspec[5] is not None: words.append("zorder %s" % imspec[5]) if len(imspec[3]) > 0: words.append("at %s" % ', '.join(imspec[3])) self.write(words.join()) return words.needs_space
def print_atl_rawmulti(self, ast): self.indent() words = WordConcatenator(False) # warpers if ast.warp_function: words.append("warp", ast.warp_function, ast.duration) elif ast.warper: words.append(ast.warper, ast.duration) elif ast.duration != "0": words.append("pause", ast.duration) # revolution if ast.revolution: words.append(ast.revolution) # circles if ast.circles != "0": words.append("circles", ast.circles) # splines for name, expressions in ast.splines: words.append(name) for expression in expressions: words.append("knot", expression) # properties for key, value in ast.properties: words.append(key, value) # with for (expression, with_expression) in ast.expressions: words.append(expression) if with_expression: words.append("with", with_expression) self.write(words.join())