"""Find the clone creation and positioning logic in the Level sprite.""" import json d = json.load(open('extracted/project.json', encoding='utf-8')) level_sprite = [t for t in d['targets'] if t['name'] == 'Level'][0] blocks = level_sprite.get('blocks', {}) # Let's trace the full block chains to understand the level rendering print("=== ALL TOPLEVEL BLOCKS ===") for block_id, block in blocks.items(): if block.get('topLevel'): opcode = block.get('opcode', '') print(f"\n{opcode} ({block_id[:10]}...):") # Follow the chain next_id = block.get('next') depth = 0 while next_id and next_id in blocks and depth < 30: next_block = blocks[next_id] op = next_block.get('opcode', '') inputs = next_block.get('inputs', {}) # Get input values input_str = "" for k, v in inputs.items(): if isinstance(v, list) and len(v) > 1: if isinstance(v[1], list): input_str += f" {k}={v[1]}" elif isinstance(v[1], str) and v[1] in blocks: sub_block = blocks[v[1]] input_str += f" {k}=[{sub_block.get('opcode')}]" print(f" {' '*depth}{op}{input_str}") # Check for substacks (loops, ifs) if 'SUBSTACK' in inputs: substack = inputs['SUBSTACK'] if isinstance(substack, list) and len(substack) > 1: sub_id = substack[1] if sub_id in blocks: sub_block = blocks[sub_id] print(f" {' '*depth} SUBSTACK: {sub_block.get('opcode')}") next_id = next_block.get('next') depth += 1 # Look for create_clone blocks print("\n\n=== CLONE CREATION BLOCKS ===") for block_id, block in blocks.items(): opcode = block.get('opcode', '') if 'clone' in opcode.lower(): print(f"{opcode}: {block}")