Example #1
0
 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
Example #2
0
    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)
Example #3
0
 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
Example #4
0
    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)}
Example #5
0
    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)
Example #6
0
    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)}
Example #7
0
    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
Example #8
0
    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
Example #9
0
 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
Example #10
0
    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}
Example #11
0
 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
Example #12
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
Example #13
0
 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
Example #14
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
Example #15
0
 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
Example #16
0
 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 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}
Example #18
0
    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}
Example #19
0
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
Example #20
0
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
Example #21
0
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)
Example #22
0
 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 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)
Example #24
0
    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):
        if not getattr(scratch, 'kelp_prepared', False):
            KelpPlugin.tag_reachable_scripts(scratch)

        # initializaton - we only need to look at Green Flag scripts for Race Initialization
        scripts = {'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)

        #initialize boolean initialization variables to False
        catPos = False
        catSize = False
        roosterPos = False
        roosterOrien = False
        roosterSet = False
        catSet = 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 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:
                            catSet = 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}
Example #26
0
    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
Example #27
0
    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
Example #28
0
    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 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
        }