def grab_comments(block): if block.comment: (x, y) = scriptable.scripts[-1].pos pos = (x, y + 29) array = self.save_comment(kurt.Comment(block.comment, pos)) array[5] = blocks_by_id.index(block) sd["scriptComments"].append(array) for arg in block.args: if isinstance(arg, kurt.Block): grab_comments(arg) elif isinstance(arg, list): map(grab_comments, arg)
def grab_comments(block): if block.comment: (x, y) = voct_scriptable.hiddenscripts[-1][0] pos = (x, y + 29) array = self.save_script(kurt.Comment(block.comment, pos), self.v14_project) for i in xrange(len(blocks_by_id)): if blocks_by_id[i] is block: array[1][0].append(i + 1) break voct_scriptable.hiddenbin.append(array) for arg in block.args: if isinstance(arg, kurt.Block): grab_comments(arg) elif isinstance(arg, list): map(grab_comments, arg)
def load_script(self, script_array): (pos, blocks) = script_array # comment? if len(blocks) == 1: block = blocks[0] if block: if (isinstance(block[0], Symbol) and block[0].value == 'scratchComment'): text = block[1].replace("\r", "\n") comment = kurt.Comment(text, pos) if len(block) > 4: comment._anchor = block[4] return comment # script return kurt.Script(map(self.load_block, blocks), pos)
def load_scriptable(self, sd, is_stage=False): if is_stage: scriptable = kurt.Stage(self.project) elif 'objName' in sd: scriptable = kurt.Sprite(self.project, sd["objName"]) else: return self.load_watcher(sd) # costumes for cd in sd.get("costumes", []): image = self.read_image(cd['baseLayerID']) rotation_center = (cd['rotationCenterX'], cd['rotationCenterY']) if cd['bitmapResolution'] != 1: (w, h) = image.size w /= cd['bitmapResolution'] h /= cd['bitmapResolution'] image = image.resize((w, h)) (x, y) = rotation_center x /= cd['bitmapResolution'] y /= cd['bitmapResolution'] rotation_center = (x, y) if 'text' in cd: text_layer = self.read_image(cd['textLayerID']) if text_layer: image = image.paste(text_layer) scriptable.costumes.append( kurt.Costume(cd['costumeName'], image, rotation_center)) # sounds for snd in sd.get("sounds", []): scriptable.sounds.append( kurt.Sound( snd['soundName'], self.read_waveform(snd['soundID'], snd['rate'], snd['sampleCount']))) # vars & lists target = self.project if is_stage else scriptable for vd in sd.get("variables", []): var = kurt.Variable(vd['value'], vd['isPersistent']) target.variables[vd['name']] = var for ld in sd.get("lists", []): name = ld['listName'] target.lists[name] = kurt.List(ld['contents'], ld['isPersistent']) self.list_watchers.append( kurt.Watcher(target, kurt.Block("contentsOfList:", name), is_visible=ld['visible'], pos=(ld['x'], ld['y']))) # custom blocks first for script_array in sd.get("scripts", []): if script_array[2]: block_array = script_array[2][0] if block_array[0] == 'procDef': (_, spec, input_names, defaults, is_atomic) = block_array cb = custom_block(spec, input_names, defaults) cb.is_atomic = is_atomic self.custom_blocks[spec] = cb # scripts for script_array in sd.get("scripts", []): scriptable.scripts.append(self.load_script(script_array)) # comments blocks_by_id = [] for script in scriptable.scripts: for block in list(get_blocks_by_id(script)): blocks_by_id.append(block) for comment_array in sd.get("scriptComments", []): (x, y, w, h, expanded, block_id, text) = comment_array if block_id > -1: blocks_by_id[block_id].comment = text else: scriptable.scripts.append(kurt.Comment(text, (x, y))) # sprite only if not is_stage: scriptable.position = (sd['scratchX'], sd['scratchY']) scriptable.direction = sd['direction'] scriptable.rotation_style = str(sd['rotationStyle']) scriptable.is_draggable = sd['isDraggable'] scriptable.is_visible = sd['visible'] scriptable.size = sd['scale'] * 100.0 return scriptable