Skip to content

Commit

Permalink
Fix code indentation in get_code method
Browse files Browse the repository at this point in the history
  • Loading branch information
cnfatal committed Nov 18, 2023
1 parent 0d0f278 commit 2b80d9e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
6 changes: 2 additions & 4 deletions renpy/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,9 @@ def __new__(cls, *args, **kwargs):

def get_code(self, **kwargs) -> str:
start = self.line
if self.block:
start += ":\n"
rv = [start]
for item in self.block:
raise NotImplementedError
if self.block:
rv.append(util.indent(util.get_block_code(self.block, **kwargs)))
return "\n".join(rv)


Expand Down
16 changes: 16 additions & 0 deletions renpy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,19 @@ def get_code(node, **kwargs) -> str:
if modifier:
modifier(node, **kwargs)
return node.get_code(**kwargs)


def get_block_code(node, **kwargs) -> str:
"""
https://www.renpy.org/doc/html/layeredimage.html#layeredimage
"""
if isinstance(node, list):
return "\n".join(map(lambda x: get_block_code(x, **kwargs), node))
lines = []
if isinstance(node, tuple) and len(node) >= 4:
_, _, code, block = node
lines.append(code)
lines.append(indent(get_block_code(block, **kwargs)))
else:
raise NotImplementedError
return "\n".join(lines)
6 changes: 5 additions & 1 deletion rpycdec.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,11 @@ def load_file(filename, disasm: bool = False) -> renpy.ast.Node:
disasm_file = filename + ".disasm"
with open(disasm_file, "w", encoding="utf-8") as disasm_f:
pickletools.dis(bindata, out=disasm_f)
_, stmts = pickle.loads(bindata)
try:
_, stmts = pickle.loads(bindata)
except Exception as e:
logger.error("load %s failed: %s", filename, e)
raise e
return stmts
file.seek(0)
return None
Expand Down
1 change: 1 addition & 0 deletions store/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

22 changes: 22 additions & 0 deletions store/layeredimage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class RawLayeredImage:
pass


class RawAlways:
pass


class RawAttributeGroup:
pass


class RawAttribute:
pass


class RawConditionGroup:
pass


class RawCondition:
pass

0 comments on commit 2b80d9e

Please sign in to comment.