Skip to content

Commit

Permalink
Support alternate define operators |= and +=. Split Default and Defin…
Browse files Browse the repository at this point in the history
…e handling as both statements have diverged in behaviour.
  • Loading branch information
CensoredUsername committed Feb 12, 2024
1 parent 68c3d02 commit d96455c
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions decompiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,28 +757,46 @@ def print_earlypython(self, ast):
self.print_python(ast, early=True)

@dispatch(renpy.ast.Define)
@dispatch(renpy.ast.Default)
def print_define(self, ast):
self.require_init()
self.indent()
if isinstance(ast, renpy.ast.Default):
name = "default"
else:
name = "define"

# If we have an implicit init block with a non-default priority, we need to store the priority here.
priority = ""
if isinstance(self.parent, renpy.ast.Init):
init = self.parent
if init.priority != self.init_offset and len(init.block) == 1 and not self.should_come_before(init, ast):
priority = " %d" % (init.priority - self.init_offset)

index = ""
if hasattr(ast, "index") and ast.index is not None:
index = "[%s]" % ast.index.source

operator = "="
if hasattr(ast, "operator"):
operator = ast.operator

if not hasattr(ast, "store") or ast.store == "store":
self.write("define%s %s%s %s %s" % (priority, ast.varname, index, operator, ast.code.source))
else:
self.write("define%s %s.%s%s %s %s" % (priority, ast.store[6:], ast.varname, index, operator, ast.code.source))

@dispatch(renpy.ast.Default)
def print_define(self, ast):
self.require_init()
self.indent()

# If we have an implicit init block with a non-default priority, we need to store the priority here.
priority = ""
if isinstance(self.parent, renpy.ast.Init):
init = self.parent
if init.priority != self.init_offset and len(init.block) == 1 and not self.should_come_before(init, ast):
priority = " %d" % (init.priority - self.init_offset)

if not hasattr(ast, "store") or ast.store == "store":
self.write("%s%s %s%s = %s" % (name, priority, ast.varname, index, ast.code.source))
self.write("default%s %s = %s" % (priority, ast.varname, ast.code.source))
else:
self.write("%s%s %s.%s%s = %s" % (name, priority, ast.store[6:], ast.varname, index, ast.code.source))
self.write("default%s %s.%s = %s" % (priority, ast.store[6:], ast.varname, ast.code.source))

# Specials

Expand Down

0 comments on commit d96455c

Please # to comment.