Skip to content

Commit

Permalink
Fix a bad decompile that occured with labelled menus that had a leadi…
Browse files Browse the repository at this point in the history
…ng say statement.
  • Loading branch information
CensoredUsername committed Feb 21, 2024
1 parent ab65d9f commit e1e6bf2
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions decompiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,28 @@ def print_label(self, ast):
# If a Call block preceded us, it printed us as "from"
if (self.index and isinstance(self.block[self.index - 1], renpy.ast.Call)):
return
remaining_blocks = len(self.block) - self.index
if remaining_blocks > 1:
next_ast = self.block[self.index + 1]
# See if we're the label for a menu, rather than a standalone label.
if (not ast.block and ast.parameters is None and
hasattr(next_ast, 'linenumber') and next_ast.linenumber == ast.linenumber and
(isinstance(next_ast, renpy.ast.Menu) or (remaining_blocks > 2 and
isinstance(next_ast, renpy.ast.Say) and
self.say_belongs_to_menu(next_ast, self.block[self.index + 2])))):
self.label_inside_menu = ast
return

# See if we're the label for a menu, rather than a standalone label.
if not ast.block and ast.parameters is None:
remaining_blocks = len(self.block) - self.index
if remaining_blocks > 1:
# Label followed by a menu
next_ast = self.block[self.index + 1]
if isinstance(next_ast, renpy.ast.Menu) and next_ast.linenumber == ast.linenumber:
self.label_inside_menu = ast
return

if remaining_blocks > 2:
# Label, followed by a say, followed by a menu
next_next_ast = self.block[self.index + 2]
if (isinstance(next_ast, renpy.ast.Say) and
isinstance(next_next_ast, renpy.ast.Menu) and
next_next_ast.linenumber == ast.linenumber and
self.say_belongs_to_menu(next_ast, next_next_ast)):

self.label_inside_menu = ast
return

self.advance_to_line(ast.linenumber)
self.indent()

Expand Down

0 comments on commit e1e6bf2

Please sign in to comment.