def analyze(self, scratch): if not getattr(scratch, 'kelp_prepared', False): KelpPlugin.tag_reachable_scripts(scratch) # check rocket: if there's not a rocket sprite, return false rocket = False for sprite in scratch.sprites: if sprite.name == 'Rocket': rocket = sprite if rocket: blocks = self.checkRocket(rocket) else: blocks = {'left': False, 'right': False, 'down': False} planets = {'Mercury': False, 'Venus': False, 'Earth': False, 'Mars': False, 'Jupiter': False, 'Saturn': False, 'Uranus': False, 'Neptune': False} for sprite in scratch.sprites: name = sprite.costumes[0].name.encode('ascii','ignore') if name != 'Rocket' and name != 'Sun': # check the name and say bubble for script in sprite.scripts: # check scripts that start with 'when sprite clicked' if not isinstance(script, kurt.Comment): if KelpPlugin.script_start_type(script) == self.HAT_MOUSE: for blockname, _, block in self.iter_blocks(script): # find the say blocks if 'say' in blockname or 'think' in blockname: # check to see if it says the sprite's name planets[name] = self.checkApprox(name.lower(), block.args[0].lower().encode('ascii','ignore')) return {'rocket': blocks, 'planets': planets}
def checkArrow(self, scripts, message): hide1 = False init = False show = False broadcast = False hide2 = False for script in scripts: if KelpPlugin.script_start_type(script) == self.HAT_GREEN_FLAG: for block in script.blocks: if block.type.text == 'hide': hide1 = True elif block.type.text == 'go to x:%s y:%s': init = True elif script[0].type.text == 'when I receive %s': for block in script.blocks: if block.type.text == 'show': show = True elif KelpPlugin.script_start_type(script) == self.HAT_MOUSE: for block in script.blocks: name = block.type.text if 'broadcast' in name: self.messages[message] = block.args[0] broadcast = True elif broadcast and name == 'hide': hide2 = True return hide1 and init and show and broadcast and hide2
def analyze(self, scratch): if not getattr(scratch, 'kelp_prepared', False): KelpPlugin.tag_reachable_scripts(scratch) self.Events = Events() self.Events.analyze(scratch) self.ScriptsStart() self.BroadcastDisplay(self.help, self.Events.thumbnails)
def analyze(self, scratch): if not getattr(scratch, 'kelp_prepared', False): KelpPlugin.tag_reachable_scripts(scratch) seq = dict() # store the screen seq['screen'] = KelpPlugin.save_png(scratch.name, scratch.thumbnail, 'screen') #store the values for the variables level and points, if they exist level = False points = False for name, var in scratch.variables.items(): if name == 'level' or name == 'Level': level = True seq[name] = var.value elif name == 'points' or name == 'Points': points = True seq[name] = var.value # If they don't exist, store them with the value of -1 if level == False: seq['level'] = '-1' if points == False: seq['points'] = '-1' # show the display self.SequenceDisplay(seq)
def analyze(self, scratch): if not getattr(scratch, 'kelp_prepared', False): KelpPlugin.tag_reachable_scripts(scratch) # check rocket: if there's not a rocket sprite, return false rocket = False for sprite in scratch.sprites: if sprite.name == 'Rocket': rocket = sprite # there should be scripts for right, left and down blocks = {'left': False, 'right': False, 'down': False} if rocket: for script in rocket.scripts: key = '' direction = '' move = False if not isinstance(script, kurt.Comment): for name, _, block in self.iter_blocks(script): if name == 'when %s key pressed': key = block.args[0] if name == 'point in direction %s': direction = block.args[0] if 'steps' in name and block.args[0] > 0: move = True if move and key == 'left arrow' and direction == -90: blocks["left"] = True if move and key == 'right arrow' and direction == 90: blocks["right"] = True if move and key == 'down arrow' and direction == 180: blocks["down"] = True return blocks
def analyze(self, scratch): if not getattr(scratch, 'kelp_prepared', False): KelpPlugin.tag_reachable_scripts(scratch) seq = dict() # store the screen seq['screen'] = KelpPlugin.save_png(scratch.name, scratch.thumbnail, 'screen'); #store the values for the variables level and points, if they exist level = False points = False for name, var in scratch.variables.items(): if name == 'level' or name == 'Level': level = True seq[name] = var.value elif name == 'points' or name == 'Points': points = True seq[name] = var.value # If they don't exist, store them with the value of -1 if level == False: seq['level'] = '-1' if points == False: seq['points'] = '-1' # show the display self.SequenceDisplay(seq)
def analyze(self, scratch): if not getattr(scratch, 'kelp_prepared', False): KelpPlugin.tag_reachable_scripts(scratch) self.changes = dict() for sprite in scratch.sprites + [scratch.stage]: self.changes[sprite.name] = dict() for attr in self.BLOCKMAPPING.keys(): self.changes[sprite.name][attr] = [] self.attribute_state(sprite.name, sprite.scripts, attr) return {'changes': self.changes, 'thumbnails': self.thumbnails(scratch)}
def checkStage(self, scripts): # make sure there's 6 distinct backgrounds costumes = set() initialized = False scene1 = False scene2 = False scene3 = False message1 = '' message2 = '' for script in scripts: background1 = False background2 = False background3 = False time1 = False time2 = False if not isinstance(script, kurt.Comment): #greenflag: check for initialization of background if KelpPlugin.script_start_type(script) == self.HAT_GREEN_FLAG: for block in script.blocks: if block.type.text == 'switch backdrop to %s': costumes.add(block.args[0]) initialized = True elif KelpPlugin.script_start_type( script) == self.HAT_WHEN_I_RECEIVE: if message2 == '': message1 = script[0].args[0] for name, _, block in self.iter_blocks(script.blocks): if 'backdrop' in name: if time2: background3 = True elif time1: background2 = True else: background1 = True if name == 'wait %s secs': if background2: time2 = True elif background1: time1 = True if name == 'when I receive %s': message2 = block.args[0] # scene 1 and 3 only have a costume change if background1 and not (background2 and background3 and time1 and time2): if scene1: scene3 = True else: scene1 = True elif message2 != '': scene2 = True self.messages['scene2'] = message1 self.messages['nextbutton2'] = message2 return initialized and scene1 and scene2 and scene3
def checkStage(self, scripts): # make sure there's 6 distinct backgrounds costumes = set() initialized = False scene1 = False scene2 = False scene3 = False message1 = '' message2 = '' for script in scripts: background1 = False background2 = False background3 = False time1 = False time2 = False if not isinstance(script, kurt.Comment): #greenflag: check for initialization of background if KelpPlugin.script_start_type(script) == self.HAT_GREEN_FLAG: for block in script.blocks: if block.type.text == 'switch backdrop to %s': costumes.add(block.args[0]) initialized = True elif KelpPlugin.script_start_type(script) == self.HAT_WHEN_I_RECEIVE: if message2 == '': message1 = script[0].args[0] for name, _, block in self.iter_blocks(script.blocks): if 'backdrop' in name: if time2: background3 = True elif time1: background2 = True else: background1 = True if name == 'wait %s secs': if background2: time2 = True elif background1: time1 = True if name == 'when I receive %s': message2 = block.args[0] # scene 1 and 3 only have a costume change if background1 and not (background2 and background3 and time1 and time2): if scene1: scene3 = True else: scene1 = True elif message2 != '': scene2 = True self.messages['scene2'] = message1 self.messages['nextbutton2'] = message2 return initialized and scene1 and scene2 and scene3
def analyze(self, scratch): if not getattr(scratch, 'kelp_prepared', False): KelpPlugin.tag_reachable_scripts(scratch) self.broadcasts = dict() self.receives = dict() self.events = dict() self.events[self.HAT_GREEN_FLAG] = [] self.events[self.HAT_MOUSE] = [] self.events[self.HAT_KEY] = [] self.help = dict() self.help[self.HAT_GREEN_FLAG] = [] self.help[self.HAT_MOUSE] = [] self.help[self.HAT_KEY] = [] addon = [] """go through the scripts in each category. If we encounter a broadcast block, check for a corresponding when I receive. If there is, continue looking through that script for broadcast blocks. Add all connected scripts to a set in the dictionary as (sprite, list of scripts) sets?""" self.Events = Events() self.Events.analyze(scratch) for e in self.events.keys(): for sprite, types in self.Events.types[e].items(): for script in types['visible'] | types['hidden']: self.events[e].append((sprite,script)) self.BroadcastIter(script, e, sprite) # Reorders the list for each tree for printing extra = [] if not len(self.events[e]) == 1: for sprite, script in self.events[e]: for name, _, block in self.iter_blocks(script): if 'broadcast %s' in name: if not (sprite, script) in extra: extra.append((sprite, script)) addon = [] br = False for sprite2, script2 in self.events[e]: if self.script_start_type(script2) == self.HAT_WHEN_I_RECEIVE: if block.args[0].lower() == script2[0].args[0].lower(): for name3, _, _ in self.iter_blocks(script2): if 'broadcast %s' in name3: extra.append((sprite2,script2)) br = True if not br: if (sprite2,script2) not in extra: addon.append((sprite2,script2)) extra.extend(addon) self.help[e] = extra return {'broadcast': self.help, 'thumbnails': self.thumbnails(scratch)}
def analyze(self, scratch): if not getattr(scratch, 'kelp_prepared', False): KelpPlugin.tag_reachable_scripts(scratch) #initialize self.types = dict() self.types[self.NO_HAT] = dict() self.types[self.HAT_GREEN_FLAG] = dict() self.types[self.HAT_WHEN_I_RECEIVE] = dict() self.types[self.HAT_KEY] = dict() self.types[self.HAT_MOUSE] = dict() for event in self.types.keys(): for morph in scratch.sprites + [scratch.stage]: self.types[event][morph.name] = {"hidden": set(), "visible": set()} ### The below loop may be adding duplicate scripts ### #go through the visible scripts for sprite, script in KelpPlugin.iter_sprite_visible_scripts(scratch): if not script.reachable: #also adds un-broadcasted when I receive scripts self.types[KelpPlugin.NO_HAT][sprite]["visible"].add(script) elif KelpPlugin.script_start_type(script) in self.types.keys(): self.types[KelpPlugin.script_start_type(script)][sprite]["visible"].add(script) #go through the hidden scripts for sprite, script in KelpPlugin.iter_sprite_hidden_scripts(scratch): if not script.reachable: self.types[self.NO_HAT][sprite]["hidden"].add(script) elif KelpPlugin.script_start_type(script) in self.types.keys(): self.types[KelpPlugin.script_start_type(script)][sprite]["hidden"].add(script) return {'events': self.types, 'thumbnails': self.thumbnails(scratch)}
def costumes(self, scratch): projectName = scratch.name costumes = dict() costumes['Stage'] = set() index = 0 for background in scratch.stage.backgrounds: costumes['Stage'].add(KelpPlugin.save_png(projectName, background, index, 'Stage')) index += 1 for sprite in scratch.sprites: index = 0 costumes[sprite.name] = set() for costume in sprite.costumes: costumes[sprite.name].add(KelpPlugin.save_png(projectName, costume, index, sprite.name)) index += 1 self.costumes = costumes
def analyze(self, scratch): if not getattr(scratch, 'kelp_prepared', False): KelpPlugin.tag_reachable_scripts(scratch) seq = dict() #store the values for the variables level, points, and health if they exist name = ['Level', 'Points', 'Health'] for var in name: if var in scratch.variables.keys(): seq[var] = scratch.variables[var] else: seq[var] = '-1' return seq
def htmlview(self, sprites, event, fil): for sprite in sprites: fil.write(' <td>') visible = "" hidden = "" if event[sprite]['hidden']: for script in event[sprite]['hidden']: hidden += KelpPlugin.to_scratch_blocks(sprite, script) fil.write('<pre class="hidden"><p>{0}</p></pre>'.format(hidden)) if event[sprite]['visible']: for script in event[sprite]['visible']: visible += KelpPlugin.to_scratch_blocks(sprite, script) fil.write('<pre class="blocks"><p>{0}</p></pre>'.format(visible)) fil.write(' </td>') fil.write(' </tr>')
def broadcast_display(results): broadcast = results['broadcast'] thumbnails = results['thumbnails'] html = [] html.append('\n<h2 style="text-align:center;">Broadcast / Receive</h2>') message = "" for blocktype, lists in broadcast.items(): for (sprite, script) in lists: if KelpPlugin.script_start_type( script) == KelpPlugin.HAT_WHEN_I_RECEIVE: # check if the message is the same as the last one # if it is, print this script next to the last # otherwise, print it below the last if message != script[0].args[0].lower(): html.append('\n <tr>') message = script[0].args[0].lower() script_images = KelpPlugin.to_scratch_blocks(sprite, script) html.append('\n<td>') html.append('\n<p> {0}</p>'.format(sprite)) html.append( '\n <p><img src="{0}" height="100" width="100"></p>'. format(thumbnails[sprite])) html.append('\n<pre class="blocks">') html.append('\n<p>{0}</p>'.format(script_images)) html.append('\n</pre>') html.append('\n</td>') elif KelpPlugin.script_start_type != KelpPlugin.NO_HAT: html.append('\n</table>') html.append('\n<hr>') html.append('\n<h2>{0}</h2>'.format( KelpPlugin.SCRIPT_TITLES[blocktype])) html.append('\n<table>') if message == "": html.append('\n </tr>') html.append('\n <tr>') script_images = KelpPlugin.to_scratch_blocks(sprite, script) html.append('\n<td>') html.append('\n<p>{0}</p>'.format(sprite)) html.append( '\n <p><img src="{0}" height="100" width="100"></p>'. format(thumbnails[sprite])) html.append('\n<pre class="blocks">') html.append('\n<p>{0}</p>'.format(script_images)) html.append('\n</pre>') html.append('\n</td>') html.append('\n </tr>') html.append('\n</table>') return ''.join(html)
def event_display(results): thumbnails = results['thumbnails'] events = results['events'] html = [] sprites = [] html.append('<h2> Starting Scripts Table </h2>') html.append('<table>') # start the first row html.append('<tr>') # headings html.append('<th>Script Type</th>') for sprite in thumbnails.keys(): if sprite != 'screen': sprites.append(sprite) # sprite name html.append('<th>{0}</th>'.format(sprite)) # sprite thumbnail? # end the first row html.append('</tr>') # make a row for each event type for event_type, event in events.items(): html.append('<tr>') # new row html.append('<td>{0}</td>'.format( SCRIPT_TITLES[event_type])) # row header for sprite in sprites: html.append('<td><pre class="blocks"><p>') if event[sprite]['visible']: for script in event[sprite]['visible']: html.append(KelpPlugin.to_scratch_blocks(sprite, script)) html.append('</p></pre></td>') html.append('</tr>') # end row html.append('</table>') return ''.join(html)
def checkDance(self, sprite): # names of timing blocks timing = set([ 'wait %s secs', 'glide %s secs to x:%s y:%s', 'say %s for %s secs', 'think %s for %s secs' ]) costume1 = False timing1 = False costume2 = False timing2 = False costume3 = False for script in sprite.scripts: if not isinstance(script, kurt.Comment): if KelpPlugin.script_start_type(script) == self.HAT_MOUSE: for name, _, block in self.iter_blocks(script): # check for a costume change if 'costume' in name: if timing2: costume3 = True elif timing1: costume2 = True elif not costume1: costume1 = True # check for a timing block if name in timing: if costume2: timing2 = True elif costume1: timing1 = True return costume1 and timing1 and costume2 and timing2 and costume3
def analyze(self, scratch): if not getattr(scratch, 'kelp_prepared', False): KelpPlugin.tag_reachable_scripts(scratch) # events self.Events = Events() self.Events.analyze(scratch) #initialization self.changes = dict() for sprite in scratch.sprites + [scratch.stage]: self.changes[sprite.name] = dict() for attr in self.BLOCKMAPPING.keys(): self.changes[sprite.name][attr] = [] self.attribute_state(sprite.name, sprite.scripts, attr) self.initializationDisplay(self.changes, self.Events)
def InitScriptsDisplay(self, thumbnails, changes, file): sprite_names = [] for name in thumbnails.keys(): if name != 'screen': sprite_names.append(name) # Displays sprite names and pictures file.write('<h2> Uninitialized Scripts</h2>') file.write('<table border="1">') file.write(' <tr>') for sprite in sprite_names: file.write(' <th>{0}</th>'.format(sprite)) file.write(' </tr> <tr>') for sprite in sprite_names: file.write(' <td><img src="{0}" ></td>'.format( thumbnails[sprite])) file.write(' </tr>') # Displays uninitialized scripts file.write(' <tr>') for sprite in sprite_names: file.write(' <td>') for type, list in changes[sprite].items(): if list: for block, script in list: #This will display the problem block file.write( '<pre class="error"><p>{0}\n</p></pre>'.format( block.stringify(True))) #This will display the script that the block is in file.write( '<pre class="blocks"><p>{0}</p></pre>'.format( KelpPlugin.to_scratch_blocks(sprite, script))) file.write(' </td>') file.write(' </tr></table>') return 0
def checkDance(self, sprite): # names of timing blocks timing = set(['wait %s secs', 'glide %s secs to x:%s y:%s', 'say %s for %s secs', 'think %s for %s secs']) costume1 = False timing1 = False costume2 = False timing2 = False costume3 = False for script in sprite.scripts: if not isinstance(script, kurt.Comment): if KelpPlugin.script_start_type(script) == self.HAT_MOUSE: for name, _, block in self.iter_blocks(script): # check for a costume change if 'costume' in name: if timing2: costume3 = True elif timing1: costume2 = True elif not costume1: costume1 = True # check for a timing block if name in timing: if costume2: timing2 = True elif costume1: timing1 = True return costume1 and timing1 and costume2 and timing2 and costume3
def checkPan(self, scripts): costume = False say = False shake = False time1 = False time2 = False move1 = False move2 = False move = set() for (name, _) in KelpPlugin.BLOCKMAPPING['position']: move.add(name) for script in scripts: if KelpPlugin.script_start_type(script) == self.HAT_MOUSE: for name, _, block in self.iter_blocks(script.blocks): # check for movement and time? if name in move: if time1: move2 = True else: move1 = True if 'wait' in name: if move2: time2 = True elif move1: time1 = True # check for costume change if 'costume' in name: costume = True # check for say block if costume: if 'say' in name or 'think' in name: say = True shake = time1 and time2 and move1 and move2 return costume and say and shake
def analyze(self, scratch, **kwargs): planets = { 'Mercury': False, 'Venus': False, 'Earth': False, 'Mars': False, 'Jupiter': False, 'Saturn': False, 'Uranus': False, 'Neptune': False } for sprite in scratch.sprites: name = sprite.costumes[0].name.encode('ascii', 'ignore') if name != 'Rocket' and name != 'Sun': # check the name and say bubble for script in sprite.scripts: # check scripts that start with 'when sprite clicked' if not isinstance(script, kurt.Comment): if KelpPlugin.script_start_type( script) == self.HAT_MOUSE: for blockname, _, block in self.iter_blocks( script): # find the say blocks if 'say' in blockname or 'think' in blockname: # check to see if it says the sprite's name planets[name] = self.checkApprox( name.lower(), block.args[0].lower().encode( 'ascii', 'ignore')) return planets
def analyze(self, scratch): if not getattr(scratch, 'kelp_prepared', False): KelpPlugin.tag_reachable_scripts(scratch) #call broadcast self.Broadcast = Broadcast() self.Broadcast.analyze(scratch) #call initialization self.Init = Initialization() self.Init.analyze(scratch) #costumes self.costumes(scratch) self.CostumeDisplay(self.costumes)
def EventsDisplay(self, thumbnails, events): file = KelpPlugin.html_view("event", "Events") self.ScriptEventsDisplay(thumbnails, events, file) self.ThumbnailDisplay(thumbnails['screen'], file) file.write('</body>') file.write('</html>') file.close()
def event_display(results): thumbnails = results['thumbnails'] events = results['events'] html = [] sprites = [] html.append('<h2> Starting Scripts Table </h2>') html.append('<table>') # start the first row html.append('<tr>') # headings html.append('<th>Script Type</th>') for sprite in thumbnails.keys(): if sprite != 'screen': sprites.append(sprite) # sprite name html.append('<th>{0}</th>'.format(sprite)) # sprite thumbnail? # end the first row html.append('</tr>') # make a row for each event type for event_type, event in events.items(): html.append('<tr>') # new row html.append('<td>{0}</td>'.format(KelpPlugin.SCRIPT_TITLES[event_type])) # row header for sprite in sprites: html.append('<td><pre class="blocks"><p>') if event[sprite]['visible']: for script in event[sprite]['visible']: html.append(KelpPlugin.to_scratch_blocks(sprite, script)) html.append('</p></pre></td>') html.append('</tr>') # end row html.append('</table>') return ''.join(html)
def analyze(self, scratch): if not getattr(scratch, 'kelp_prepared', False): KelpPlugin.tag_reachable_scripts(scratch) projectName = scratch.name self.costumes = dict() self.costumes['Stage'] = set() index = 0 for background in scratch.stage.backgrounds: self.costumes['Stage'].add(self.save_png(projectName, background, index, 'Stage')) index += 1 for sprite in scratch.sprites: index = 0 self.costumes[sprite.name] = set() for costume in sprite.costumes: self.costumes[sprite.name].add(self.save_png(projectName, costume, index, sprite.name)) index += 1 return self.costumes
def htmlview(self, sprites, event, fil): for sprite in sprites: fil.write(' <td>') visible = "" hidden = "" if event[sprite]['hidden']: for script in event[sprite]['hidden']: hidden += KelpPlugin.to_scratch_blocks(sprite, script) fil.write( '<pre class="hidden"><p>{0}</p></pre>'.format(hidden)) if event[sprite]['visible']: for script in event[sprite]['visible']: visible += KelpPlugin.to_scratch_blocks(sprite, script) fil.write( '<pre class="blocks"><p>{0}</p></pre>'.format(visible)) fil.write(' </td>') fil.write(' </tr>')
def analyze(self, scratch): if not getattr(scratch, 'kelp_prepared', False): KelpPlugin.tag_reachable_scripts(scratch) self.messages = {'scene1': '', 'scene2': '', 'scene3': '', 'nextButton': '', 'nextButton2': ''} # check that everything's initialized init = initializationViewer.Initialization() init = init.analyze(scratch) scenes = dict() required = set(['Button', 'Gold Finder', 'BlueArrow', 'Gold Pan', 'PurpleArrow']) # they need at least five sprites if len(scratch.sprites) < 5: scenes['incomplete'] = 'You have less than five sprites' return {'scenes': scenes, 'changes': init['changes']} # they can't change the sprite names given = set() for sprite in scratch.sprites: given.add(sprite.name) scenes['missing'] = required - given if len(scenes['missing']) > 0: return {'scenes': scenes, 'changes': init['changes']} else: del scenes['missing'] # check the stage scenes['Stage'] = self.checkStage(scratch.stage.scripts) for sprite in scratch.sprites: if sprite.name == 'Button': scenes['Button'] = self.checkButton(sprite.scripts) elif sprite.name == 'BlueArrow': scenes[sprite.name] = self.checkArrow(sprite.scripts, 'Scene2') elif sprite.name =='PurpleArrow': scenes[sprite.name] = self.checkArrow(sprite.scripts, 'Scene3') elif sprite.name == 'Gold Finder': scenes[sprite.name] = self.check49er(sprite.scripts) elif sprite.name == 'Gold Pan': scenes[sprite.name] = self.checkPan(sprite.scripts) return {'scenes': scenes, 'changes': init['changes']}
def BroadcastDisplay(self, brod, thumbnails): file = KelpPlugin.html_view("broadcast", "Broadcast Receive") file.write('<body>') file.write('<h2 style="text-align:center;">Broadcast / Receive</h2>') #call to create HTML table self.broadcastHTML(brod, thumbnails, file) file.close() return 0 '''HTML '''
def broadcastHTML(self, brod, thumbnails, file): message = "" for type, lists in brod.items(): for list in lists: file.write('<hr>') file.write('<h2>{0}<h2>'.format(type)) #heading file.write('<table border = "1">') for sprite, script in list: if self.script_start_type( script) == self.HAT_WHEN_I_RECEIVE: # check if the message is the same as the last one # if it is, print this script next to the last # otherwise, print it below the last if message != script[0].args[0].lower(): file.write(' </tr>') file.write(' <tr>') message = script[0].args[0].lower() script_images = KelpPlugin.to_scratch_blocks( sprite, script) file.write('<td>') file.write('<p> {0}</p>'.format(sprite)) file.write( ' <p><img src="{0}" height="100" width="100"></p>' .format(thumbnails[sprite])) file.write('<pre class="blocks">') file.write('<p>{0}</p>'.format(script_images)) file.write('</pre>') file.write('</td>') elif self.script_start_type != self.NO_HAT: if message == "": file.write(' </tr>') file.write(' <tr>') script_images = KelpPlugin.to_scratch_blocks( sprite, script) file.write('<p>{0}</p>'.format(sprite)) file.write( ' <p><img src="{0}" height="100" width="100"></p>' .format(thumbnails[sprite])) file.write('<pre class="blocks">') file.write('<p>{0}</p>'.format(script_images)) file.write('</pre>') file.write(' </tr>') file.write('</table>')
def broadcast_display(results): broadcast = results['broadcast'] thumbnails = results['thumbnails'] html = [] html.append('\n<h2 style="text-align:center;">Broadcast / Receive</h2>') message = "" for blocktype, lists in broadcast.items(): for (sprite, script) in lists: if KelpPlugin.script_start_type(script) == KelpPlugin.HAT_WHEN_I_RECEIVE: # check if the message is the same as the last one # if it is, print this script next to the last # otherwise, print it below the last if message != script[0].args[0].lower(): html.append('\n <tr>') message = script[0].args[0].lower() script_images = KelpPlugin.to_scratch_blocks(sprite, script) html.append('\n<td>') html.append('\n<p> {0}</p>'.format(sprite)) html.append('\n <p><img src="{0}" height="100" width="100"></p>'.format(thumbnails[sprite])) html.append('\n<pre class="blocks">') html.append('\n<p>{0}</p>'.format(script_images)) html.append('\n</pre>') html.append('\n</td>') elif KelpPlugin.script_start_type != KelpPlugin.NO_HAT: html.append('\n</table>') html.append('\n<hr>') html.append('\n<h2>{0}</h2>'.format(KelpPlugin.SCRIPT_TITLES[blocktype])) html.append('\n<table>') if message == "": html.append('\n </tr>') html.append('\n <tr>') script_images = KelpPlugin.to_scratch_blocks(sprite, script) html.append('\n<td>') html.append('\n<p>{0}</p>'.format(sprite)) html.append('\n <p><img src="{0}" height="100" width="100"></p>'.format(thumbnails[sprite])) html.append('\n<pre class="blocks">') html.append('\n<p>{0}</p>'.format(script_images)) html.append('\n</pre>') html.append('\n</td>') html.append('\n </tr>') html.append('\n</table>') return ''.join(html)
def checkButton(self, scripts): init = False show = False broadcast = False hide = False for script in scripts: if KelpPlugin.script_start_type(script) == self.HAT_GREEN_FLAG: #check for placement and show for block in script.blocks: if block.type.text == 'show': show = True if block.type.text == 'go to x:%s y:%s': init = True elif KelpPlugin.script_start_type(script) == self.HAT_MOUSE: for block in script.blocks: if 'broadcast' in block.type.text: broadcast = True self.messages['scene1'] = block.args[0] elif broadcast and block.type.text == 'hide': hide = True return init and show and broadcast and hide
def ScriptsType(self, scratch): """Returns a dictionary of the scripts. Keys: start events Values: another dictionary Keys: sprite names Values: that sprite's scripts for this start event .""" #initialize self.types = dict() self.types["dead"] = dict() self.types[self.HAT_GREEN_FLAG] = dict() self.types[self.HAT_WHEN_I_RECEIVE] = dict() self.types[self.HAT_KEY] = dict() self.types[self.HAT_MOUSE] = dict() for event in self.types.keys(): for morph in scratch.sprites + [scratch.stage]: self.types[event][morph.name] = {"hidden": set(), "visible": set()} #go through the visible scripts for sprite, script in KelpPlugin.iter_sprite_visible_scripts(scratch): if not script.reachable: self.types["dead"][sprite]["visible"].add(script) elif KelpPlugin.script_start_type(script) in self.types.keys(): self.types[KelpPlugin.script_start_type(script)][sprite]["visible"].add(script) #go through the hidden scripts for sprite, script in KelpPlugin.iter_sprite_hidden_scripts(scratch): if not script.reachable: self.types["dead"][sprite]["hidden"].add(script) elif KelpPlugin.script_start_type(script) in self.types.keys(): self.types[KelpPlugin.script_start_type(script)][sprite]["hidden"].add(script)
def ScriptsType(self, scratch): """Returns a dictionary of the scripts. Keys: start events Values: another dictionary Keys: sprite names Values: that sprite's scripts for this start event .""" #initialize self.types = dict() self.types["dead"] = dict() self.types[self.HAT_GREEN_FLAG] = dict() self.types[self.HAT_WHEN_I_RECEIVE] = dict() self.types[self.HAT_KEY] = dict() self.types[self.HAT_MOUSE] = dict() for event in self.types.keys(): for morph in scratch.sprites + [scratch.stage]: self.types[event][morph.name] = { "hidden": set(), "visible": set() } #go through the visible scripts for sprite, script in KelpPlugin.iter_sprite_visible_scripts(scratch): if not script.reachable: self.types["dead"][sprite]["visible"].add(script) elif KelpPlugin.script_start_type(script) in self.types.keys(): self.types[KelpPlugin.script_start_type( script)][sprite]["visible"].add(script) #go through the hidden scripts for sprite, script in KelpPlugin.iter_sprite_hidden_scripts(scratch): if not script.reachable: self.types["dead"][sprite]["hidden"].add(script) elif KelpPlugin.script_start_type(script) in self.types.keys(): self.types[KelpPlugin.script_start_type( script)][sprite]["hidden"].add(script)
def analyze(self, scratch, **kwargs): #initialize self.types = dict() self.types[self.NO_HAT] = dict() self.types[self.HAT_GREEN_FLAG] = dict() self.types[self.HAT_WHEN_I_RECEIVE] = dict() self.types[self.HAT_KEY] = dict() self.types[self.HAT_MOUSE] = dict() for event in self.types.keys(): for morph in scratch.sprites + [scratch.stage]: self.types[event][morph.name] = { "hidden": set(), "visible": set() } ### The below loop may be adding duplicate scripts ### #go through the visible scripts for sprite, script in KelpPlugin.iter_sprite_visible_scripts(scratch): if not script.reachable: #also adds un-broadcasted when I receive scripts self.types[KelpPlugin.NO_HAT][sprite]["visible"].add(script) elif KelpPlugin.script_start_type(script) in self.types.keys(): self.types[KelpPlugin.script_start_type( script)][sprite]["visible"].add(script) #go through the hidden scripts for sprite, script in KelpPlugin.iter_sprite_hidden_scripts(scratch): if not script.reachable: self.types[self.NO_HAT][sprite]["hidden"].add(script) elif KelpPlugin.script_start_type(script) in self.types.keys(): self.types[KelpPlugin.script_start_type( script)][sprite]["hidden"].add(script) return {'events': self.types, 'thumbnails': self.thumbnails(scratch)}
def analyze(self, scratch): if not getattr(scratch, 'kelp_prepared', False): KelpPlugin.tag_reachable_scripts(scratch) # record the car's When I Receive scripts # and the cities' When Clicked scripts sprite_scripts = dict() sprite_scripts['Car'] = set() for sprite in scratch.sprites: sprite_scripts[sprite.name] = set() for script in sprite.scripts: if not isinstance(script, kurt.Comment): if sprite.name == 'Car': if KelpPlugin.script_start_type(script) == self.HAT_WHEN_I_RECEIVE: sprite_scripts[sprite.name].add(script) else: if KelpPlugin.script_start_type(script) == self.HAT_MOUSE: sprite_scripts[sprite.name].add(script) # record the messages broadcasted by the cities messages = dict() for sprite, scripts in sprite_scripts.items(): if sprite != 'Car': for script in scripts: for name, _, block in self.iter_blocks(script.blocks): if 'broadcast' in name: messages[block.args[0]] = sprite # record the coordinates of the city sprites coordinates = dict() for sprite in scratch.sprites: if sprite.name != 'Car': coordinates[sprite.name] = sprite.position # check the car test = sprite_scripts['Car'] drive, say = self.car(sprite_scripts['Car'], messages, coordinates) return {'drive': drive, 'say': say}
def analyze(self, scratch, **kwargs): # record the car's When I Receive scripts # and the cities' When Clicked scripts sprite_scripts = dict() sprite_scripts['Car'] = set() for sprite in scratch.sprites: sprite_scripts[sprite.name] = set() for script in sprite.scripts: if not isinstance(script, kurt.Comment): if sprite.name == 'Car': if KelpPlugin.script_start_type( script) == self.HAT_WHEN_I_RECEIVE: sprite_scripts[sprite.name].add(script) else: if KelpPlugin.script_start_type( script) == self.HAT_MOUSE: sprite_scripts[sprite.name].add(script) # record the messages broadcasted by the cities messages = dict() for sprite, scripts in sprite_scripts.items(): if sprite != 'Car': for script in scripts: for name, _, block in self.iter_blocks(script.blocks): if 'broadcast' in name: messages[block.args[0]] = sprite # record the coordinates of the city sprites coordinates = dict() for sprite in scratch.sprites: if sprite.name != 'Car': coordinates[sprite.name] = sprite.position # check the car test = sprite_scripts['Car'] drive, say = self.car(sprite_scripts['Car'], messages, coordinates) return {'drive': drive, 'say': say}
def partition_scripts(scripts, start_type): """Return two lists of scripts out of the original `scripts` list. Scripts that begin with a `start_type` block are returned first. All other scripts are returned second. """ match, other = [], [] for script in scripts: if KelpPlugin.script_start_type(script) == start_type: match.append(script) else: other.append(script) return match, other
def analyze(self, scratch): if not getattr(scratch, 'kelp_prepared', False): KelpPlugin.tag_reachable_scripts(scratch) # check initialization changes = dict() init = initializationViewer.Initialization() init = init.analyze(scratch) for sprite, attrdict in init['changes'].items(): initialized = True if sprite != 'Ballerina' and sprite != 'Stage': for attribute in attrdict.values(): if len(attribute) > 0: initialized = False changes[sprite] = initialized # check the sprites' dances dance = dict() for sprite in scratch.sprites: if sprite.name != 'Ballerina': dance[sprite.name] = self.checkDance(sprite) return {'dance': dance, 'changes': changes}
def initializationDisplay(self, changes, events): file = KelpPlugin.html_view("Initialization", "Initialization") file.write('<body>') events.ScriptEventsDisplay(events.thumbnails, events.types, fil) isEmpty = True for sprite in changes.keys(): for attr in changes[sprite].keys(): if changes[sprite][attr]: isEmpty = False break if not isEmpty: self.InitScriptsDisplay(events.thumbnails, changes, file) file.write('</body>') file.write('</html>') file.close()
def analyze(self, scratch, **kwargs): planets = {'Mercury': False, 'Venus': False, 'Earth': False, 'Mars': False, 'Jupiter': False, 'Saturn': False, 'Uranus': False, 'Neptune': False} for sprite in scratch.sprites: name = sprite.costumes[0].name.encode('ascii','ignore') if name != 'Rocket' and name != 'Sun': # check the name and say bubble for script in sprite.scripts: # check scripts that start with 'when sprite clicked' if not isinstance(script, kurt.Comment): if KelpPlugin.script_start_type(script) == self.HAT_MOUSE: for blockname, _, block in self.iter_blocks(script): # find the say blocks if 'say' in blockname or 'think' in blockname: # check to see if it says the sprite's name planets[name] = self.checkApprox(name.lower(), block.args[0].lower().encode('ascii','ignore')) return planets
def initialization_display(results): changes = results['changes'] thumbnails = results['thumbnails'] html = [] empty = True for sprite in changes.keys(): for attr in changes[sprite].keys(): if changes[sprite][attr]: empty = False break if empty: return ''.join(html) sprite_names = [] for name in thumbnails.keys(): if name != 'screen': sprite_names.append(name) # Displays sprite names and pictures html.append('<h2> Uninitialized Scripts</h2>') html.append('<table border="20">') html.append(' <tr>') for sprite in sprite_names: html.append(' <th>{0}</th>'.format(sprite)) html.append(' </tr> <tr>') for sprite in sprite_names: html.append(' <td><img src="{0}" height="100" width="100"></td>'.format(thumbnails[sprite])) html.append(' </tr>') # Displays uninitialized scripts html.append(' <tr>') for sprite in sprite_names: html.append(' <td>') for type, list in changes[sprite].items(): if list: for block, script in list: #This will display the problem block html.append('<pre class="error"><p>{0}\n</p></pre>'.format(block.stringify(True))) #This will display the script that the block is in html.append('<pre class="blocks"><p>{0}</p></pre>'.format(KelpPlugin.to_scratch_blocks(sprite, script))) html.append(' </td>') html.append(' </tr></table>') return ''.join(html)
def CostumeDisplay(self, cost): file = KelpPlugin.html_view("costume", "Costumes") file.write('<body>') # Displays sprite names and costumes file.write('<p>COSTUMES</p>') file.write('<table>') file.write(' <tr>') for sprite, value in cost.items(): #if sprite != 'Stage': file.write(' <th>{0}</th>'.format(sprite)) file.write(' </tr>') file.write(' <tr>') for sprite, values in cost.items(): file.write('<td>') for value in values: #if sprite != 'Stage': file.write(' <p><img src="{0}" height="100" width="100"></p>'.format(value)) #file.write('<p><img src="{0}"></p>'.format(value)) file.write('</td>') file.write(' </tr>') file.write('</table>') self.Broadcast.broadcastHTML(self.Broadcast.help, KelpPlugin.thumbnails, file) isEmpty = True for sprite in self.Init.changes.keys(): for attr in self.Init.changes[sprite].keys(): if self.Init.changes[sprite][attr]: isEmpty = False break self.Init.InitScriptsDisplay(KelpPlugin.thumbnails, self.Init.changes, file) file.write('</body>') file.write('</html>') file.close() return 0
def analyze(self, scratch): if not getattr(scratch, 'kelp_prepared', False): KelpPlugin.tag_reachable_scripts(scratch) KelpPlugin.get_thumbnails(scratch) self.ScriptsType(scratch) self.EventsDisplay(self.thumbnails, self.types)
def analyze(self, scratch, **kwargs): # initializaton - we only need to look at Green Flag scripts for Race Initialization # look at when clicked to see if they initialize after clicking scripts = {'Cat': set(), 'Rooster': set()} scriptsClicked = {'Cat': set(), 'Rooster': set()} for sprite in scratch.sprites: if sprite.name == 'Cat' or sprite.name == 'Rooster': for script in sprite.scripts: if not isinstance(script, kurt.Comment): if KelpPlugin.script_start_type( script) == self.HAT_GREEN_FLAG: scripts[sprite.name].add(script) elif "when this sprite clicked" in script.blocks[ 0].stringify(): scriptsClicked[sprite.name].add(script) #initialize boolean initialization variables to False catPos = False catSize = False roosterPos = False roosterOrien = False roosterSet = False catSet = False #for clicked catPos2 = False catSize2 = False roosterPos2 = False roosterOrien2 = False roosterSet2 = False catSet2 = False #access the Cat's blocks for script in scripts['Cat']: for block in script: if block.type.text == 'set size to %s%%': if block.args[0] == 100: catSize = True elif block.type.text == 'go to x:%s y:%s': if block.args[0] >= 145: catPos = True elif block.type.text == 'set x to %s': if block.args[0] >= 145: if catSet: # already set y catPos = True else: catSet = True elif block.type.text == 'set y to %s': if catSet: # already set x catPos = True else: catSet = True #access to cat clicked for script in scriptsClicked['Cat']: for block in script: if block.type.text == 'set size to %s%%': if block.args[0] == 100: catSize2 = True elif block.type.text == 'go to x:%s y:%s': if block.args[0] >= 145: catPos2 = True elif block.type.text == 'set x to %s': if block.args[0] >= 145: if catSet: # already set y catPos2 = True else: catSet2 = True elif block.type.text == 'set y to %s': if catSet: # already set x catPos2 = True else: catSet2 = True #access the Rooster's blocks for script in scripts['Rooster']: for block in script: if block.type.text == 'point towards %s': if block.args[0] == 'finish line': roosterOrien = True elif block.type.text == 'point in direction %s': if block.args[0] == -90: roosterOrien = True elif block.type.text == 'go to x:%s y:%s': if block.args[0] >= 145: roosterPos = True elif block.type.text == 'set x to %s': if block.args[0] >= 145: if roosterSet: # already set y roosterPos = True else: roosterSet = True elif block.type.text == 'set y to %s': if roosterSet: # already set x roosterPos = True else: roosterSet = True #access the Rooster clicked for script in scriptsClicked['Rooster']: for block in script: if block.type.text == 'point towards %s': if block.args[0] == 'finish line': roosterOrien2 = True elif block.type.text == 'point in direction %s': if block.args[0] == -90: roosterOrien2 = True elif block.type.text == 'go to x:%s y:%s': if block.args[0] >= 145: roosterPos2 = True elif block.type.text == 'set x to %s': if block.args[0] >= 145: if roosterSet: # already set y roosterPos2 = True else: roosterSet2 = True elif block.type.text == 'set y to %s': if roosterSet: # already set x roosterPos = True else: roosterSet = True return { 'Cat': catPos and catSize, 'Rooster': roosterPos and roosterOrien, 'CatClicked': catPos2 and catSize2, 'RoosterClicked': roosterPos2 and roosterOrien2 }
def analyze(self, scratch, **kwargs): scenes = {'renamed':False, 'initialized': {'Sun':False, 'Button':False}, 'raining': {'show': False, 'background': False}, 'sunny': {'show': False, 'hide': False, 'background': False}, 'clicked': False} sprites = {'green flag':dict(), 'receive':dict(), 'clicked':dict()} for sprite in scratch.sprites + [scratch.stage]: if sprite.name not in ['Sun', 'Stage', 'Button', 'Cloud']: return {'renamed': True} for category in sprites.keys(): sprites[category][sprite.name] = set() for script in sprite.scripts: if not isinstance(script, kurt.Comment): if KelpPlugin.script_start_type(script) == self.HAT_MOUSE: sprites['clicked'][sprite.name].add(script) elif KelpPlugin.script_start_type(script) == self.HAT_GREEN_FLAG: sprites['green flag'][sprite.name].add(script) elif KelpPlugin.script_start_type(script) == self.HAT_WHEN_I_RECEIVE: sprites['receive'][sprite.name].add(script) #check green flag for the sun and the button # the sun should start with ClickMeCostume costume for script in sprites['green flag']['Sun']: for name, _, block in self.iter_blocks(script): if name == 'switch costume to %s' and block.args[0] == 'ClickMeCostume': scenes['initialized']['Sun'] = True # the button should hide for script in sprites['green flag']['Button']: for name, _, block in self.iter_blocks(script): if name == 'hide': scenes['initialized']['Button'] = True # check cloud clicked costume = False broadcast = False for script in sprites['clicked']['Cloud']: for name, _, block in self.iter_blocks(script): if name == 'switch costume to %s' and block.args[0] == 'Raining': costume = True if costume and name == 'broadcast %s': broadcast = block.args[0] break #check raining if broadcast: # the button should show for script in sprites['receive']['Button']: if script[0].args[0] == broadcast: for name, _, block in self.iter_blocks(script): if name == 'show': scenes['raining']['show'] = True # the stage should switch to background Sapling for script in sprites['receive']['Stage']: if script[0].args[0] == broadcast: for name, _, block in self.iter_blocks(script): if name == 'switch backdrop to %s' and block.args[0] == 'Sapling': scenes['raining']['background'] = True # check button clicked hide = False broadcast = False for script in sprites['clicked']['Button']: for name, _, block in self.iter_blocks(script): if name == 'hide': hide = True if hide and name == 'broadcast %s': broadcast = block.args[0] break #check sunny if broadcast: # the stage should switch to background Flower for script in sprites['receive']['Stage']: for name, _, block in self.iter_blocks(script): if name == 'switch backdrop to %s' and block.args[0] == 'Flower': scenes['sunny']['background'] = True # the sun should show for script in sprites['receive']['Sun']: for name, _, block in self.iter_blocks(script): if name == 'show': scenes['sunny']['show'] = True # the cloud should hide for script in sprites['receive']['Cloud']: for name, _, block in self.iter_blocks(script): if name == 'hide': scenes['sunny']['hide'] = True # check sun clicked for script in sprites['clicked']['Sun']: for name, _, block in self.iter_blocks(script): if name == 'switch costume to %s' and block.args[0] == 'Rays': scenes['clicked'] = True return scenes
def check49er(self, scripts): # should have a when I receive with animation # should have a hide somewhere other than the gf hide = False show = False walk = False say = False broadcast = False #animation costume1 = False time1 = False move1 = False costume2 = False time2 =False move2 =False costume3 = False time3 =False move3 =False move = set() for (name, _) in KelpPlugin.BLOCKMAPPING['position']: move.add(name) time = set(['wait %s secs', 'glide %s secs to x:%n y:%n']) for script in scripts: if not isinstance(script, kurt.Comment): if KelpPlugin.script_start_type(script) == self.HAT_WHEN_I_RECEIVE: for name, _, block in self.iter_blocks(script.blocks): if name == 'hide': hide = True break if name == 'show': show = True elif show and 'costume' in name: if move2 and time2: costume3 = True elif move1 and time1: costume2 = True else: costume1 = True elif show and name in move: if costume3: move3 = True elif costume2: move2 = True elif costume1: move1 = True if show and name in time: if costume3: time3 = True elif costume2: time2 = True elif costume1: time1 = True walk = costume1 and costume2 and costume3 walk = walk and time1 and time2 and time3 walk = walk and move1 and move2 and move3 if walk and ('say' in name or 'think' in name): say = True elif say and 'broadcast' in name: broadcast = True return walk and say and broadcast and show and hide
def analyze(self, scratch, **kwargs): scenes = { 'renamed': False, 'initialized': { 'Sun': False, 'Button': False }, 'raining': { 'show': False, 'background': False }, 'sunny': { 'show': False, 'hide': False, 'background': False }, 'clicked': False } sprites = {'green flag': dict(), 'receive': dict(), 'clicked': dict()} for sprite in scratch.sprites + [scratch.stage]: if sprite.name not in ['Sun', 'Stage', 'Button', 'Cloud']: return {'renamed': True} for category in sprites.keys(): sprites[category][sprite.name] = set() for script in sprite.scripts: if not isinstance(script, kurt.Comment): if KelpPlugin.script_start_type(script) == self.HAT_MOUSE: sprites['clicked'][sprite.name].add(script) elif KelpPlugin.script_start_type( script) == self.HAT_GREEN_FLAG: sprites['green flag'][sprite.name].add(script) elif KelpPlugin.script_start_type( script) == self.HAT_WHEN_I_RECEIVE: sprites['receive'][sprite.name].add(script) #check green flag for the sun and the button # the sun should start with ClickMeCostume costume for script in sprites['green flag']['Sun']: for name, _, block in self.iter_blocks(script): if name == 'switch costume to %s' and block.args[ 0] == 'ClickMeCostume': scenes['initialized']['Sun'] = True # the button should hide for script in sprites['green flag']['Button']: for name, _, block in self.iter_blocks(script): if name == 'hide': scenes['initialized']['Button'] = True # check cloud clicked costume = False broadcast = False for script in sprites['clicked']['Cloud']: for name, _, block in self.iter_blocks(script): if name == 'switch costume to %s' and block.args[ 0] == 'Raining': costume = True if costume and name == 'broadcast %s': broadcast = block.args[0] break #check raining if broadcast: # the button should show for script in sprites['receive']['Button']: if script[0].args[0] == broadcast: for name, _, block in self.iter_blocks(script): if name == 'show': scenes['raining']['show'] = True # the stage should switch to background Sapling for script in sprites['receive']['Stage']: if script[0].args[0] == broadcast: for name, _, block in self.iter_blocks(script): if name == 'switch backdrop to %s' and block.args[ 0] == 'Sapling': scenes['raining']['background'] = True # check button clicked hide = False broadcast = False for script in sprites['clicked']['Button']: for name, _, block in self.iter_blocks(script): if name == 'hide': hide = True if hide and name == 'broadcast %s': broadcast = block.args[0] break #check sunny if broadcast: # the stage should switch to background Flower for script in sprites['receive']['Stage']: for name, _, block in self.iter_blocks(script): if name == 'switch backdrop to %s' and block.args[ 0] == 'Flower': scenes['sunny']['background'] = True # the sun should show for script in sprites['receive']['Sun']: for name, _, block in self.iter_blocks(script): if name == 'show': scenes['sunny']['show'] = True # the cloud should hide for script in sprites['receive']['Cloud']: for name, _, block in self.iter_blocks(script): if name == 'hide': scenes['sunny']['hide'] = True # check sun clicked for script in sprites['clicked']['Sun']: for name, _, block in self.iter_blocks(script): if name == 'switch costume to %s' and block.args[0] == 'Rays': scenes['clicked'] = True return scenes
def check49er(self, scripts): # should have a when I receive with animation # should have a hide somewhere other than the gf hide = False show = False walk = False say = False broadcast = False #animation costume1 = False time1 = False move1 = False costume2 = False time2 = False move2 = False costume3 = False time3 = False move3 = False move = set() for (name, _) in KelpPlugin.BLOCKMAPPING['position']: move.add(name) time = set(['wait %s secs', 'glide %s secs to x:%n y:%n']) for script in scripts: if not isinstance(script, kurt.Comment): if KelpPlugin.script_start_type( script) == self.HAT_WHEN_I_RECEIVE: for name, _, block in self.iter_blocks(script.blocks): if name == 'hide': hide = True break if name == 'show': show = True elif show and 'costume' in name: if move2 and time2: costume3 = True elif move1 and time1: costume2 = True else: costume1 = True elif show and name in move: if costume3: move3 = True elif costume2: move2 = True elif costume1: move1 = True if show and name in time: if costume3: time3 = True elif costume2: time2 = True elif costume1: time1 = True walk = costume1 and costume2 and costume3 walk = walk and time1 and time2 and time3 walk = walk and move1 and move2 and move3 if walk and ('say' in name or 'think' in name): say = True elif say and 'broadcast' in name: broadcast = True return walk and say and broadcast and show and hide