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)
Example #2
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 #3
0
    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)
Example #4
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 #5
0
    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)
Example #6
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
        
        # 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)
     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 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)

        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
Example #10
0
    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 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)
Example #12
0
 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
Example #13
0
    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 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 #15
0
    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}
Example #16
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)
Example #17
0
    def analyze(self, scratch):
        if not getattr(scratch, 'kelp_prepared', False):
            KelpPlugin.tag_reachable_scripts(scratch)

        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):
        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 #19
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)