def load_watcher(self, v14_watcher): v14_sprite = v14_watcher.readout.target if v14_sprite == self.stage: kurt_target = self.project else: kurt_target = self.project.get_sprite(v14_sprite.name) command = v14_watcher.readout.getSelector.value command = 'readVariable' if command == 'getVar:' else command if v14_watcher.readout.parameter: kurt_block = kurt.Block(command, v14_watcher.readout.parameter) else: kurt_block = kurt.Block(command) kurt_watcher = kurt.Watcher(kurt_target, kurt_block) (x, y, right, bottom) = v14_watcher.bounds.value kurt_watcher.pos = (x, y) if v14_watcher.isLarge: kurt_watcher.style = "large" elif v14_watcher.scratchSlider: kurt_watcher.style = "slider" kurt_watcher.slider_min = v14_watcher.sliderMin kurt_watcher.slider_max = v14_watcher.sliderMax return kurt_watcher
def load_lists(self, v14_lists, kurt_target): for v14_list in v14_lists.values(): kurt_list = kurt.List(map(unicode, v14_list.list_items)) kurt_target.lists[v14_list.name] = kurt_list kurt_watcher = kurt.Watcher( kurt_target, kurt.Block("contentsOfList:", v14_list.name)) kurt_watcher.is_visible = bool(v14_list.owner) (x, y, w, h) = v14_list.bounds.value if not kurt_watcher.is_visible: x -= 534 y -= 71 kurt_watcher.pos = (x, y) self.project.actors.append(kurt_watcher)
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