"""Deep dive into Scratch level data - find tile positioning logic.""" import json d = json.load(open('extracted/project.json', encoding='utf-8')) stage = [t for t in d['targets'] if t['isStage']][0] level_sprite = [t for t in d['targets'] if t['name'] == 'Level'][0] # Get the Jump list - might be for autoplaying/recordings print("=== JUMP LIST (sample) ===") jump_list = None for k, v in stage.get('lists', {}).items(): if v[0] == 'Jump': jump_list = v[1] # Check if it's all "Jump" or has patterns unique = set(jump_list) print(f"Unique values: {unique}") break # Look more carefully at Level sprite blocks print("\n=== LEVEL SPRITE BLOCK ANALYSIS ===") blocks = level_sprite.get('blocks', {}) # Find the clone start block and follow the chain for block_id, block in blocks.items(): opcode = block.get('opcode', '') if opcode == 'control_start_as_clone': print(f"Found clone start: {block_id}") # Follow the chain next_id = block.get('next') chain = [] while next_id and next_id in blocks: next_block = blocks[next_id] chain.append(f"{next_block.get('opcode')}") next_id = next_block.get('next') print(f"Clone chain: {chain[:15]}...") # Look for motion blocks that set x position print("\n=== LOOKING FOR X POSITION LOGIC ===") for block_id, block in blocks.items(): opcode = block.get('opcode', '') if 'x' in opcode.lower() or 'goto' in opcode.lower() or 'glide' in opcode.lower(): inputs = block.get('inputs', {}) print(f" {opcode}: inputs={inputs}") # Look for costume switching logic print("\n=== COSTUME SWITCHING LOGIC ===") for block_id, block in blocks.items(): opcode = block.get('opcode', '') if 'costume' in opcode.lower(): inputs = block.get('inputs', {}) print(f" {opcode}: {inputs}") # Check if there's a pattern in how clones are created # The key is: each tile (costume) is probably created as a clone at a specific X position # X = tile_number * tile_width - scroll_x # Look for any math or variable references print("\n=== LOOKING FOR TILE POSITIONING FORMULA ===") for block_id, block in blocks.items(): opcode = block.get('opcode', '') if 'operator' in opcode or 'data' in opcode: if block.get('topLevel'): continue parent_id = block.get('parent') if parent_id and parent_id in blocks: parent_op = blocks[parent_id].get('opcode', '') if 'x' in parent_op.lower() or 'position' in parent_op.lower(): print(f" {opcode} -> {parent_op}") # The real insight: costumes contain the visual level data # Each costume is a tile, and the clone's X position is calculated based on: # - The tile/costume number # - The current scroll position # Let's figure out the tile width from the costume dimensions print("\n=== COSTUME DIMENSIONS ===") costumes = level_sprite['costumes'] for c in costumes[:3]: print(f" {c['name']}: rotationCenter=({c.get('rotationCenterX')}, {c.get('rotationCenterY')})") # The actual width should be about 2x the rotationCenterX width = c.get('rotationCenterX', 0) * 2 print(f" Estimated width: {width}")