Пример #1
0
 def __init__(self,_playerNum):
     self.fighters = []
     
     # Load all files.
     directory = settingsManager.createPath("fighters")
     fighter_count = 0
     for subdir in next(os.walk(directory))[1]:
         if(subdir == '__pycache__'):
             continue
         fighter_py = settingsManager.importFromURI(directory, os.path.join(directory,subdir,"fighter.py"),_suffix=str(fighter_count))
         #try:
         if fighter_py:
             fighter = fighter_py.getFighter(os.path.join(directory,subdir),_playerNum)
         else:
             fighter = abstractFighter.AbstractFighter(os.path.join(directory,subdir),_playerNum)
         if (fighter == None):
             print("No fighter found at " + os.path.join(directory,subdir,"fighter.py"))
         else:
             fighter_count += 1
             self.fighters.append(fighter)      
     
     self.current_index = 0
     self.current_fighter = self.fighters[0]
     self.wheel_size = 9
     self.visible_sprites = [None for _ in range(self.wheel_size)]
     self.animateWheel()
     self.wheel_shadow = spriteManager.ImageSprite(settingsManager.createPath(os.path.join("sprites","cssbar_shadow.png")))
     self.fill_color='#000000'
Пример #2
0
 def __init__(self,_playerNum):
     self.fighters = []
     
     # Load all files.
     directory = settingsManager.createPath("fighters")
     fighter_count = 0
     for subdir in next(os.walk(directory))[1]:
         if(subdir == '__pycache__'):
             continue
         fighter_py = settingsManager.importFromURI(directory, os.path.join(directory,subdir,"fighter.py"),_suffix=str(fighter_count))
         #try:
         if fighter_py:
             fighter = fighter_py.getFighter(os.path.join(directory,subdir),_playerNum)
         else:
             fighter = abstractFighter.AbstractFighter(os.path.join(directory,subdir),_playerNum)
         if (fighter == None):
             print("No fighter found at " + os.path.join(directory,subdir,"fighter.py"))
         else:
             fighter_count += 1
             self.fighters.append(fighter)      
     
     self.current_index = 0
     self.current_fighter = self.fighters[0]
     self.wheel_size = 9
     self.visible_sprites = [None for _ in range(self.wheel_size)]
     self.animateWheel()
     self.wheel_shadow = spriteManager.ImageSprite(settingsManager.createPath(os.path.join("sprites","cssbar_shadow.png")))
     self.fill_color='#000000'
Пример #3
0
 def __init__(self,playerNum,sprites):
     var = {
             'weight': 100,
             'gravity': .5,
             'maxFallSpeed': 20,
             'maxGroundSpeed': 6,
             'maxAirSpeed': 6,
             'friction': 0.2,
             'airControl': 0.6,
             'jumps': 1,
             'jumpHeight': 12,
             'airJumpHeight':14
             }
     abstractFighter.AbstractFighter.__init__(self,
                              playerNum,
                              sprites, #Start Sprite
                              "HBoxie", #Name
                              var)
     self.actions = settingsManager.importFromURI(__file__,'hitboxie_actions.py',suffix=str(playerNum))
     
     
     try:
         self.current_action = self.actions.NeutralAction()
     except:
         raise ValueError(os.path.normpath(os.path.join(os.path.dirname(__file__).replace('main.exe',''), 'hitboxie_actions.py')))
Пример #4
0
 def getStages(self):
     # Load all files.
     directory = settingsManager.createPath("stages")
     stagecount = 0
     for subdir in next(os.walk(directory))[1]:
         stage = settingsManager.importFromURI(directory, os.path.join(directory,subdir,"stage.py"),suffix=str(stagecount))
         print(stage)
         if (stage == None):
             raise ValueError("No stages found at " + os.path.join(directory,subdir,"stage.py"))
         stagecount += 1
         self.stages.append(stage)
    def unpack(self, _action, _actor):
        for argname, arg in self.args.iteritems():
            if isinstance(arg, FuncData) or isinstance(
                    arg, VarData) or isinstance(arg, EvalData):
                self.args[argname] = arg.unpack(_action, _actor)

        if self.source == 'article' and hasattr(_actor, 'owner'):
            if hasattr(_actor, self.functionName):
                method = getattr(_actor, self.functionName)
                return method(**self.args)
            else:
                print('No such function exists in article: ' +
                      str(self.functionName))
                return None
        elif self.source == 'object':
            if hasattr(_actor, self.functionName):
                method = getattr(_actor, self.functionName)
                return method(**self.args)
            else:
                print('No such function exists in object: ' +
                      str(self.functionName))
                return None
        elif self.source == 'actor':
            if hasattr(_actor, 'owner'):
                _actor = _actor.owner
            if hasattr(_actor, self.functionName):
                method = getattr(_actor, self.functionName)
                return method(**self.args)
            else:
                print('No such function exists in actor: ' +
                      str(self.functionName))
                return None
        elif self.source == 'action':
            if hasattr(_action, self.functionName):
                method = getattr(_action, self.functionName)
                return method(**self.args)
            else:
                print('No such function exists in action: ' +
                      str(self.functionName))
                return None
        else:
            module = settingsManager.importFromURI(self.source,
                                                   self.source.split('/')[-1])
            print(module)
            if hasattr(module, self.functionName):
                method = getattr(module, self.functionName)
                return method(**self.args)
            else:
                print('No such function exists in ' + module + ': ' +
                      str(self.functionName))
                return None
            #TODO we'll fix this later. Add in the ability to call a function by filepath.
        return None
 def unpack(self,_action,_actor):
     for argname,arg in self.args.iteritems():
         if isinstance(arg, FuncData) or isinstance(arg, VarData) or isinstance(arg, EvalData):
             self.args[argname] = arg.unpack(_action,_actor)
             
     if self.source == 'article' and hasattr(_actor, 'owner'):
         if hasattr(_actor, self.functionName):
             method = getattr(_actor, self.functionName)
             return method(**self.args)
         else:
             print('No such function exists in article: '+str(self.functionName))
             return None
     elif self.source == 'object':
         if hasattr(_actor, self.functionName):
             method = getattr(_actor, self.functionName)
             return method(**self.args)
         else:
             print('No such function exists in object: '+str(self.functionName))
             return None
     elif self.source == 'actor':
         if hasattr(_actor, 'owner'):
             _actor = _actor.owner
         if hasattr(_actor, self.functionName):
             method = getattr(_actor, self.functionName)
             return method(**self.args)
         else:
             print('No such function exists in actor: '+str(self.functionName))
             return None
     elif self.source == 'action':
         if hasattr(_action, self.functionName):
             method = getattr(_action, self.functionName)
             return method(**self.args)
         else:
             print('No such function exists in action: '+str(self.functionName))
             return None
     else:
         module = settingsManager.importFromURI(self.source, self.source.split('/')[-1])
         print(module)
         if hasattr(module, self.functionName):
             method = getattr(module, self.functionName)
             return method(**self.args)
         else:
             print('No such function exists in '+ module +': '+str(self.functionName))
             return None
         #TODO we'll fix this later. Add in the ability to call a function by filepath.
     return None
Пример #7
0
 def getStages(self):
     # Load all files.
     directory = settingsManager.createPath("stages")
     stage_count = 0
     for subdir in next(os.walk(directory))[1]:
         if (subdir == '__pycache__'):
             continue
         stage = settingsManager.importFromURI(directory,
                                               os.path.join(
                                                   directory, subdir,
                                                   "stage.py"),
                                               _suffix=str(stage_count))
         if (stage == None):
             raise ValueError("No stages found at " +
                              os.path.join(directory, subdir, "stage.py"))
         stage_count += 1
         self.stages.append(stage)
 def __init__(self,
              playerNum,
              sprite,
              attributes):
     
     self.attr = attributes
     self.vars = {}
     self.flags = {}
     self.functionHooks = {
                           'beforeUpdate': [],
                           'afterUpdate' : []
                           }
     
     self.sprite = sprite
     self.current_action = None
     
     self.velocity = vector2D.Vec2d()
     self.actions = settingsManager.importFromURI(__file__,'baseActions.py')
Пример #9
0
 def __init__(self):
     self.fighters = []
     
     # Load all files.
     directory = settingsManager.createPath("fighters")
     fightercount = 0
     for subdir in next(os.walk(directory))[1]:
         fighter = settingsManager.importFromURI(directory, os.path.join(directory,subdir,"fighter.py"),suffix=str(fightercount))
         print(fighter)
         if (fighter == None):
             raise ValueError("No fighter found at " + os.path.join(directory,subdir,"fighter.py"))
         fightercount += 1
         self.fighters.append(fighter)      
     
     self.currentIndex = 0
     self.currentFighter = self.fighters[0]
     self.wheelSize = 9
     self.visibleSprites = [None for _ in range(self.wheelSize)]
     self.animateWheel()
     self.wheelShadow = spriteManager.ImageSprite(settingsManager.createPath(os.path.join("sprites","cssbar_shadow.png")))
    def changeFighter(self, *_args):
        global fighter
        dirname, _ = os.path.split(self.fighter_file.name)
        if self.fighter_file.name.endswith(".py"):
            fighter_module = settingsManager.importFromURI(self.fighter_file, self.fighter_file.name, True)
            if hasattr(fighter_module, "Fighter"):
                new_fighter = fighter_module.Fighter(dirname, 0)
                showinfo(
                    "Advanced mode warning",
                    "Legacy Editor cannot edit Advanced Mode (.py) fighter files. The fighter will be opened in read-only mode. Depending on the fighter, there may be inconsistencies with behavior in-game compared to what you view here.",
                )
            else:
                showinfo(
                    "Error loading fighter",
                    "File does not contain a fighter. Are you sure you are loading the right Python file?",
                )
                return
        else:
            new_fighter = engine.abstractFighter.AbstractFighter(dirname, 0)

        new_fighter.loadSpriteLibrary(0)
        new_fighter.initialize()
        fighter = new_fighter
        self.wm_title("Legacy Editor - " + fighter.name)
    def loadArticle(self,_articleName):
        article_xml = self.articles_xml.find(_articleName)
        
        #Check if it's a Python article
        if article_xml is not None and article_xml.find('loadCodeAction') is not None:
            file_name = article_xml.find('loadCodeAction').find('file').text
            article_name = article_xml.find('loadCodeAction').find('action').text
            new_action = settingsManager.importFromURI(os.path.join(self.base_dir,file_name), file_name)
            return getattr(new_action, article_name)()
    
        #Get the action variables
        length = int(self.loadNodeWithDefault(article_xml, 'length', 1))
        sprite_name = self.loadNodeWithDefault(article_xml, 'sprite', None)
        sprite_rate = int(self.loadNodeWithDefault(article_xml, 'sprite_rate', 1))
        img_width = int(self.loadNodeWithDefault(article_xml, 'img_width', 0))
        draw_depth = int(self.loadNodeWithDefault(article_xml, 'draw_depth', 1))
        origin_point = make_tuple(self.loadNodeWithDefault(article_xml, 'origin_point', '(0,0)'))
        facing_direction = int(self.loadNodeWithDefault(article_xml, 'facing_direction', 0))
        
        article_vars = {}
        if article_xml.find('vars') is not None:
            for var in article_xml.find('vars'):
                t = var.attrib['type'] if var.attrib.has_key('type') else None
                if t and t == 'int':
                    article_vars[var.tag] = int(var.text)
                elif t and t == 'float':
                    article_vars[var.tag] = float(var.text)
                elif t and t == 'bool':
                    article_vars[var.tag] = (var.text == 'True')
                elif t and t == 'tuple':
                    article_vars[var.tag] = make_tuple(var.text)
                else: article_vars[var.tag] = var.text
        
        tags = []
        if article_xml.find('tags') is not None:
            for tagNode in article_xml.find('tags'):
                tags.append(tagNode.tag)
        
        #Load the SetUp subactions
        set_up_actions = []
        if article_xml.find('setUp') is not None:
            for subact in article_xml.find('setUp'):
                if subaction.subactionFactory.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    set_up_actions.append(subaction.subactionFactory.buildFromXml(subact.tag,subact))
                    
        #Load the tearDown subactions
        tear_down_actions = []
        if article_xml.find('tearDown') is not None:
            for subact in article_xml.find('tearDown'):
                if subaction.subactionFactory.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    tear_down_actions.append(subaction.subactionFactory.buildFromXml(subact.tag,subact))
        
        actions_on_clank = []
        if article_xml.find('onClank') is not None:
            for subact in article_xml.find('onClank'):
                if subaction.subactionFactory.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    actions_on_clank.append(subaction.subactionFactory.buildFromXml(subact.tag,subact))

        actions_on_prevail = []
        if article_xml.find('onPrevail') is not None:
            for subact in article_xml.find('onPrevail'):
                if subaction.subactionFactory.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    actions_on_prevail.append(subaction.subactionFactory.buildFromXml(subact.tag,subact))
        
        #Load all of the frames
        frames = article_xml.findall('frame')
        subactions_before_frame = []
        subactions_after_frame = []
        subactions_at_last_frame = []
        
        for frame in frames:
            if frame.attrib['number'] == 'before':
                for subact in frame:
                    if subaction.subactionFactory.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                        subactions_before_frame.append(subaction.subactionFactory.buildFromXml(subact.tag,subact))
            if frame.attrib['number'] == 'after':
                for subact in frame:
                    if subaction.subactionFactory.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                        subactions_after_frame.append(subaction.subactionFactory.buildFromXml(subact.tag,subact))
                frames.remove(frame)
            if frame.attrib['number'] == 'last':
                for subact in frame:
                    if subaction.subactionFactory.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                        subactions_at_last_frame.append(subaction.subactionFactory.buildFromXml(subact.tag,subact))
                frames.remove(frame)
            
        subactions_at_frame = []
                        
        #Iterate through every frame possible (not just the ones defined)
        for frame_number in range(0,length+1):
            sublist = []
            if frames:
                for frame in frames:
                    if frame.attrib['number'] == str(frame_number): #If this frame matches the number we're on
                        for subact in frame:
                            if subaction.subactionFactory.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                                sublist.append(subaction.subactionFactory.buildFromXml(subact.tag,subact))
                                
                        frames.remove(frame) #Done with this one
                         
            subactions_at_frame.append(sublist) #Put the list in, whether it's empty or not

        #Interpret frame ranges
        for frame in frames:
            if "," in frame.attrib['number'] and frame.attrib['number'].replace(",","").replace(" ","").isdigit():
                for subact in frame:
                    if subaction.subactionFactory.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                        for frame_num in make_tuple(frame.attrib['number']):
                            subactions_at_frame[frame_num].append(subaction.subactionFactory.buildFromXml(subact.tag,subact))
                frames.remove(frame)

        for frame in frames:
            if "-" in frame.attrib['number'] and frame.attrib['number'].replace("-","").replace(" ","").isdigit():
                ends = frame.attrib['number'].split("-")
                for subact in frame:
                    if subaction.subactionFactory.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                        for frame_num in range(int(ends[0]), int(ends[1])+1):
                            subactions_at_frame[frame_num].append(subaction.subactionFactory.buildFromXml(subact.tag,subact))
                frames.remove(frame)
        
        event_actions = dict()
        conds = article_xml.findall('conditional')
        conds.extend(article_xml.findall('event'))
        for cond in conds:
            event_list = []
            for subact in cond:
                if subaction.subactionFactory.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    event_list.append(subaction.subactionFactory.buildFromXml(subact.tag,subact))
            event_actions[cond.attrib['name']] = event_list
        
        
        collision_actions = dict()
        collisions = article_xml.findall('collision')
        for col in collisions:
            collision_list = []
            for subact in col:
                if subaction.subactionFactory.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    collision_list.append(subaction.subactionFactory.buildFromXml(subact.tag,subact))
            collision_actions[col.attrib['other']] = collision_list
        
        #Create and populate the Dynamic Action
        dyn_article = article.DynamicArticle(self.owner, os.path.join(self.article_path,sprite_name),
                                             img_width, origin_point, length, sprite_rate, facing_direction,
                                             draw_depth,tags)
        
        dyn_article.actions_before_frame = subactions_before_frame
        dyn_article.actions_at_frame = subactions_at_frame
        dyn_article.actions_after_frame = subactions_after_frame
        dyn_article.actions_at_last_frame = subactions_at_last_frame
        dyn_article.set_up_actions = set_up_actions
        dyn_article.tear_down_actions = tear_down_actions
        dyn_article.actions_on_clank = actions_on_clank
        dyn_article.actions_on_prevail = actions_on_prevail
        dyn_article.events = event_actions
        dyn_article.collision_actions = collision_actions
        if sprite_name: dyn_article.sprite_name = sprite_name
        if sprite_rate: dyn_article.base_sprite_rate = sprite_rate
        
        dyn_article.default_vars = article_vars
        return dyn_article
Пример #12
0
    def loadArticle(self, _articleName):
        article_xml = self.articles_xml.find(_articleName)

        #Check if it's a Python article
        if article_xml is not None and article_xml.find(
                'loadCodeAction') is not None:
            file_name = article_xml.find('loadCodeAction').find('file').text
            article_name = article_xml.find('loadCodeAction').find(
                'action').text
            new_action = settingsManager.importFromURI(
                os.path.join(self.base_dir, file_name), file_name)
            return getattr(new_action, article_name)()

        #Get the action variables
        length = int(self.loadNodeWithDefault(article_xml, 'length', 1))
        sprite_name = self.loadNodeWithDefault(article_xml, 'sprite', None)
        sprite_rate = int(
            self.loadNodeWithDefault(article_xml, 'sprite_rate', 1))
        img_width = int(self.loadNodeWithDefault(article_xml, 'img_width', 0))
        draw_depth = int(self.loadNodeWithDefault(article_xml, 'draw_depth',
                                                  1))
        origin_point = make_tuple(
            self.loadNodeWithDefault(article_xml, 'origin_point', '(0,0)'))
        facing_direction = int(
            self.loadNodeWithDefault(article_xml, 'facing_direction', 0))

        article_vars = {}
        if article_xml.find('vars') is not None:
            for var in article_xml.find('vars'):
                t = var.attrib['type'] if var.attrib.has_key('type') else None
                if t and t == 'int':
                    article_vars[var.tag] = int(var.text)
                elif t and t == 'float':
                    article_vars[var.tag] = float(var.text)
                elif t and t == 'bool':
                    article_vars[var.tag] = (var.text == 'True')
                elif t and t == 'tuple':
                    article_vars[var.tag] = make_tuple(var.text)
                else:
                    article_vars[var.tag] = var.text

        tags = []
        if article_xml.find('tags') is not None:
            for tagNode in article_xml.find('tags'):
                tags.append(tagNode.tag)

        #Load the SetUp subactions
        set_up_actions = []
        if article_xml.find('setUp') is not None:
            for subact in article_xml.find('setUp'):
                if subaction.subactionFactory.subaction_dict.has_key(
                        subact.tag):  #Subactions string to class dict
                    set_up_actions.append(
                        subaction.subactionFactory.buildFromXml(
                            subact.tag, subact))

        #Load the tearDown subactions
        tear_down_actions = []
        if article_xml.find('tearDown') is not None:
            for subact in article_xml.find('tearDown'):
                if subaction.subactionFactory.subaction_dict.has_key(
                        subact.tag):  #Subactions string to class dict
                    tear_down_actions.append(
                        subaction.subactionFactory.buildFromXml(
                            subact.tag, subact))

        actions_on_clank = []
        if article_xml.find('onClank') is not None:
            for subact in article_xml.find('onClank'):
                if subaction.subactionFactory.subaction_dict.has_key(
                        subact.tag):  #Subactions string to class dict
                    actions_on_clank.append(
                        subaction.subactionFactory.buildFromXml(
                            subact.tag, subact))

        actions_on_prevail = []
        if article_xml.find('onPrevail') is not None:
            for subact in article_xml.find('onPrevail'):
                if subaction.subactionFactory.subaction_dict.has_key(
                        subact.tag):  #Subactions string to class dict
                    actions_on_prevail.append(
                        subaction.subactionFactory.buildFromXml(
                            subact.tag, subact))

        #Load all of the frames
        frames = article_xml.findall('frame')
        subactions_before_frame = []
        subactions_after_frame = []
        subactions_at_last_frame = []

        for frame in frames:
            if frame.attrib['number'] == 'before':
                for subact in frame:
                    if subaction.subactionFactory.subaction_dict.has_key(
                            subact.tag):  #Subactions string to class dict
                        subactions_before_frame.append(
                            subaction.subactionFactory.buildFromXml(
                                subact.tag, subact))
            if frame.attrib['number'] == 'after':
                for subact in frame:
                    if subaction.subactionFactory.subaction_dict.has_key(
                            subact.tag):  #Subactions string to class dict
                        subactions_after_frame.append(
                            subaction.subactionFactory.buildFromXml(
                                subact.tag, subact))
                frames.remove(frame)
            if frame.attrib['number'] == 'last':
                for subact in frame:
                    if subaction.subactionFactory.subaction_dict.has_key(
                            subact.tag):  #Subactions string to class dict
                        subactions_at_last_frame.append(
                            subaction.subactionFactory.buildFromXml(
                                subact.tag, subact))
                frames.remove(frame)

        subactions_at_frame = []

        #Iterate through every frame possible (not just the ones defined)
        for frame_number in range(0, length + 1):
            sublist = []
            if frames:
                for frame in frames:
                    if frame.attrib['number'] == str(
                            frame_number
                    ):  #If this frame matches the number we're on
                        for subact in frame:
                            if subaction.subactionFactory.subaction_dict.has_key(
                                    subact.tag
                            ):  #Subactions string to class dict
                                sublist.append(
                                    subaction.subactionFactory.buildFromXml(
                                        subact.tag, subact))

                        frames.remove(frame)  #Done with this one

            subactions_at_frame.append(
                sublist)  #Put the list in, whether it's empty or not

        #Interpret frame ranges
        for frame in frames:
            if "," in frame.attrib['number'] and frame.attrib[
                    'number'].replace(",", "").replace(" ", "").isdigit():
                for subact in frame:
                    if subaction.subactionFactory.subaction_dict.has_key(
                            subact.tag):  #Subactions string to class dict
                        for frame_num in make_tuple(frame.attrib['number']):
                            subactions_at_frame[frame_num].append(
                                subaction.subactionFactory.buildFromXml(
                                    subact.tag, subact))
                frames.remove(frame)

        for frame in frames:
            if "-" in frame.attrib['number'] and frame.attrib[
                    'number'].replace("-", "").replace(" ", "").isdigit():
                ends = frame.attrib['number'].split("-")
                for subact in frame:
                    if subaction.subactionFactory.subaction_dict.has_key(
                            subact.tag):  #Subactions string to class dict
                        for frame_num in range(int(ends[0]), int(ends[1]) + 1):
                            subactions_at_frame[frame_num].append(
                                subaction.subactionFactory.buildFromXml(
                                    subact.tag, subact))
                frames.remove(frame)

        event_actions = dict()
        conds = article_xml.findall('conditional')
        conds.extend(article_xml.findall('event'))
        for cond in conds:
            event_list = []
            for subact in cond:
                if subaction.subactionFactory.subaction_dict.has_key(
                        subact.tag):  #Subactions string to class dict
                    event_list.append(
                        subaction.subactionFactory.buildFromXml(
                            subact.tag, subact))
            event_actions[cond.attrib['name']] = event_list

        collision_actions = dict()
        collisions = article_xml.findall('collision')
        for col in collisions:
            collision_list = []
            for subact in col:
                if subaction.subactionFactory.subaction_dict.has_key(
                        subact.tag):  #Subactions string to class dict
                    collision_list.append(
                        subaction.subactionFactory.buildFromXml(
                            subact.tag, subact))
            collision_actions[col.attrib['other']] = collision_list

        #Create and populate the Dynamic Action
        dyn_article = article.DynamicArticle(
            self.owner, os.path.join(self.article_path,
                                     sprite_name), img_width, origin_point,
            length, sprite_rate, facing_direction, draw_depth, tags)

        dyn_article.actions_before_frame = subactions_before_frame
        dyn_article.actions_at_frame = subactions_at_frame
        dyn_article.actions_after_frame = subactions_after_frame
        dyn_article.actions_at_last_frame = subactions_at_last_frame
        dyn_article.set_up_actions = set_up_actions
        dyn_article.tear_down_actions = tear_down_actions
        dyn_article.actions_on_clank = actions_on_clank
        dyn_article.actions_on_prevail = actions_on_prevail
        dyn_article.events = event_actions
        dyn_article.collision_actions = collision_actions
        if sprite_name: dyn_article.sprite_name = sprite_name
        if sprite_rate: dyn_article.base_sprite_rate = sprite_rate

        dyn_article.default_vars = article_vars
        return dyn_article
    def loadAction(self,_actionName):
        #Load the action XML
        action_xml = self.actions_xml.find(_actionName)
        
        #Check if it's a Python action
        if action_xml is not None and action_xml.find('loadCodeAction') is not None:
            file_name = action_xml.find('loadCodeAction').find('file').text
            action_name = action_xml.find('loadCodeAction').find('action').text
            new_action = settingsManager.importFromURI(os.path.join(self.base_dir,file_name), file_name)
            return getattr(new_action, action_name)()
        
        #Get the baseClass
        class_ = None
        if (action_xml is not None) and (action_xml.find('base') is not None):
            if hasattr(baseActions, action_xml.find('base').text): 
                class_ = getattr(baseActions, action_xml.find('base').text)
        else:
            if hasattr(baseActions, _actionName):
                class_ = getattr(baseActions,_actionName)
        
        if class_: base = class_
        else: base = action.Action
        if action_xml is None:
            return base()
        
        #Get the action variables
        length = int(self.loadNodeWithDefault(action_xml, 'length', 1))
        starting_frame = int(self.loadNodeWithDefault(action_xml, 'starting_frame', 0))
        sprite_name = self.loadNodeWithDefault(action_xml, 'sprite', None)
        sprite_rate = int(self.loadNodeWithDefault(action_xml, 'sprite_rate', 1))
        loop = self.loadNodeWithDefault(action_xml, 'loop', False) == 'True'
        
        action_vars = {}
        if action_xml.find('vars') is not None:
            for var in action_xml.find('vars'):
                t = var.attrib['type'] if var.attrib.has_key('type') else None
                if t and t == 'int':
                    action_vars[var.tag] = int(var.text)
                elif t and t == 'float':
                    action_vars[var.tag] = float(var.text)
                elif t and t == 'bool':
                    action_vars[var.tag] = (var.text == 'True')
                elif t and t == 'tuple':
                    action_vars[var.tag] = make_tuple(var.text)
                else: action_vars[var.tag] = var.text
                
        #Load the SetUp subactions
        set_up_actions = []
        if action_xml.find('setUp') is not None:
            for subact in action_xml.find('setUp'):
                if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    set_up_actions.append(subaction.SubAction.buildFromXml(subact.tag,subact))
                    
        #Load the tearDown subactions
        tear_down_actions = []
        if action_xml.find('tearDown') is not None:
            for subact in action_xml.find('tearDown'):
                if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    tear_down_actions.append(subaction.SubAction.buildFromXml(subact.tag,subact))
        
        #Load the stateTransition subactions
        state_transition_actions = []
        if action_xml.find('transitions') is not None:
            for subact in action_xml.find('transitions'):
                if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    state_transition_actions.append(subaction.SubAction.buildFromXml(subact.tag,subact))
        
        actions_on_clank = []
        if action_xml.find('onClank') is not None:
            for subact in action_xml.find('onClank'):
                if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    actions_on_clank.append(subaction.SubAction.buildFromXml(subact.tag,subact))

        actions_on_prevail = []
        if action_xml.find('onPrevail') is not None:
            for subact in action_xml.find('onPrevail'):
                if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    actions_on_prevail.append(subaction.SubAction.buildFromXml(subact.tag,subact))
        
        #Load all of the frames
        frames = action_xml.findall('frame')
        subactions_before_frame = []
        subactions_after_frame = []
        subactions_at_last_frame = []
        
        for frame in frames:
            if frame.attrib['number'] == 'before':
                for subact in frame:
                    if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                        subactions_before_frame.append(subaction.SubAction.buildFromXml(subact.tag,subact))
                frames.remove(frame)
            if frame.attrib['number'] == 'after':
                for subact in frame:
                    if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                        subactions_after_frame.append(subaction.SubAction.buildFromXml(subact.tag,subact))
                frames.remove(frame)
            if frame.attrib['number'] == 'last':
                for subact in frame:
                    if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                        subactions_at_last_frame.append(subaction.SubAction.buildFromXml(subact.tag,subact))
                frames.remove(frame)

        subactions_at_frame = []            
                        
        #Iterate through every frame possible (not just the ones defined)
        for frame_number in range(0,length+1):
            sublist = []
            if frames:
                for frame in frames:
                    if frame.attrib['number'] == str(frame_number): #If this frame matches the number we're on
                        for subact in frame:
                            if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                                sublist.append(subaction.SubAction.buildFromXml(subact.tag,subact))
                                
                        frames.remove(frame) #Done with this one
                         
            subactions_at_frame.append(sublist) #Put the list in, whether it's empty or not

        #Interpret frame ranges
        for frame in frames:
            if "," in frame.attrib['number'] and frame.attrib['number'].replace(",","").replace(" ","").isdigit():
                for subact in frame:
                    if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                        for frame_num in make_tuple(frame.attrib['number']):
                            subactions_at_frame[frame_num].append(subaction.SubAction.buildFromXml(subact.tag,subact))
                frames.remove(frame)

        for frame in frames:
            if "-" in frame.attrib['number'] and frame.attrib['number'].replace("-","").replace(" ","").isdigit():
                ends = frame.attrib['number'].split("-")
                for subact in frame:
                    if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                        for frame_num in range(int(ends[0]), int(ends[1])+1):
                            subactions_at_frame[frame_num].append(subaction.SubAction.buildFromXml(subact.tag,subact))
                frames.remove(frame)
                    
        conditional_actions = dict()
        conds = action_xml.findall('conditional')
        for cond in conds:
            conditional_list = []
            for subact in cond:
                if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    conditional_list.append(subaction.SubAction.buildFromXml(subact.tag,subact))
            conditional_actions[cond.attrib['name']] = conditional_list
        
        event_actions = dict()
        events = action_xml.findall('event')
        #Because we're merging events and conditionals, this checks for either.
        events.extend(action_xml.findall('conditional'))
        for event in events:
            event_list = []
            for subact in event:
                if subaction.subaction_dict.has_key(subact.tag):
                    event_list.append(subaction.SubAction.buildFromXml(subact.tag,subact))
            event_actions[event.attrib['name']] = event_list
            
        #Create and populate the Dynamic Action
        dyn_action = base()
        dyn_action.frame = starting_frame
        dyn_action.last_frame = length
        dyn_action.name = _actionName
        dyn_action.actions_before_frame = subactions_before_frame
        dyn_action.actions_at_frame = subactions_at_frame
        dyn_action.actions_after_frame = subactions_after_frame
        dyn_action.actions_at_last_frame = subactions_at_last_frame
        dyn_action.state_transition_actions = state_transition_actions
        dyn_action.set_up_actions = set_up_actions
        dyn_action.tear_down_actions = tear_down_actions
        dyn_action.actions_on_clank = actions_on_clank
        dyn_action.actions_on_prevail = actions_on_prevail
        dyn_action.events = event_actions
        if sprite_name: dyn_action.sprite_name = sprite_name
        if sprite_rate: dyn_action.base_sprite_rate = sprite_rate
        dyn_action.loop = loop
        
        dyn_action.default_vars = action_vars
        for key,val in action_vars.iteritems():
            setattr(dyn_action,key,val)
        
        return dyn_action
    def loadArticle(self,_articleName):
        article_xml = self.articles_xml.find(_articleName)
        
        #Check if it's a Python article
        if article_xml is not None and article_xml.find('loadCodeAction') is not None:
            file_name = article_xml.find('loadCodeAction').find('file').text
            article_name = article_xml.find('loadCodeAction').find('action').text
            new_action = settingsManager.importFromURI(os.path.join(self.base_dir,file_name), file_name)
            return getattr(new_action, article_name)()
    
        #Get the action variables
        length = int(self.loadNodeWithDefault(article_xml, 'length', 1))
        sprite_name = self.loadNodeWithDefault(article_xml, 'sprite', None)
        sprite_rate = int(self.loadNodeWithDefault(article_xml, 'sprite_rate', 1))
        img_width = int(self.loadNodeWithDefault(article_xml, 'img_width', 0))
        draw_depth = int(self.loadNodeWithDefault(article_xml, 'draw_depth', 1))
        origin_point = make_tuple(self.loadNodeWithDefault(article_xml, 'origin_point', '(0,0)'))
        facing_direction = int(self.loadNodeWithDefault(article_xml, 'facing_direction', 0))
        
        tags = []
        if article_xml.find('tags') is not None:
            for tagNode in article_xml.find('tags'):
                tags.append(tagNode.tag)
        
        #Load the SetUp subactions
        set_up_actions = []
        if article_xml.find('setUp') is not None:
            for subact in article_xml.find('setUp'):
                if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    set_up_actions.append(subaction.SubAction.buildFromXml(subact.tag,subact))
                    
        #Load the tearDown subactions
        tear_down_actions = []
        if article_xml.find('tearDown') is not None:
            for subact in article_xml.find('tearDown'):
                if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    tear_down_actions.append(subaction.SubAction.buildFromXml(subact.tag,subact))
        
        actions_on_clank = []
        if article_xml.find('onClank') is not None:
            for subact in article_xml.find('onClank'):
                if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    actions_on_clank.append(subaction.SubAction.buildFromXml(subact.tag,subact))

        actions_on_prevail = []
        if article_xml.find('onPrevail') is not None:
            for subact in article_xml.find('onPrevail'):
                if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    actions_on_prevail.append(subaction.SubAction.buildFromXml(subact.tag,subact))
        
        #Load all of the frames
        frames = article_xml.findall('frame')
        subactions_before_frame = []
        subactions_after_frame = []
        subactions_at_last_frame = []
        
        for frame in frames:
            if frame.attrib['number'] == 'before':
                for subact in frame:
                    if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                        subactions_before_frame.append(subaction.SubAction.buildFromXml(subact.tag,subact))
            if frame.attrib['number'] == 'after':
                for subact in frame:
                    if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                        subactions_after_frame.append(subaction.SubAction.buildFromXml(subact.tag,subact))
                frames.remove(frame)
            if frame.attrib['number'] == 'last':
                for subact in frame:
                    if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                        subactions_at_last_frame.append(subaction.SubAction.buildFromXml(subact.tag,subact))
                frames.remove(frame)
            
        subactions_at_frame = []
                        
        #Iterate through every frame possible (not just the ones defined)
        for frame_number in range(0,length+1):
            sublist = []
            if frames:
                for frame in frames:
                    if frame.attrib['number'] == str(frame_number): #If this frame matches the number we're on
                        for subact in frame:
                            if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                                sublist.append(subaction.SubAction.buildFromXml(subact.tag,subact))
                                
                        frames.remove(frame) #Done with this one
                         
            subactions_at_frame.append(sublist) #Put the list in, whether it's empty or not
        
        conditional_actions = dict()
        conds = article_xml.findall('conditional')
        for cond in conds:
            conditional_list = []
            for subact in cond:
                if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    conditional_list.append(subaction.SubAction.buildFromXml(subact.tag,subact))
            conditional_actions[cond.attrib['name']] = conditional_list
         
         
        collision_actions = dict()
        collisions = article_xml.findall('collision')
        for col in collisions:
            collision_list = []
            for subact in col:
                if subaction.subaction_dict.has_key(subact.tag): #Subactions string to class dict
                    collision_list.append(subaction.SubAction.buildFromXml(subact.tag,subact))
            collision_actions[col.attrib['other']] = collision_list
        
        #Create and populate the Dynamic Action
        dyn_article = article.DynamicArticle(self.owner, os.path.join(self.article_path,sprite_name),
                                             img_width, origin_point, length, sprite_rate, facing_direction,
                                             draw_depth,tags)
        
        dyn_article.actions_before_frame = subactions_before_frame
        dyn_article.actions_at_frame = subactions_at_frame
        dyn_article.actions_after_frame = subactions_after_frame
        dyn_article.actions_at_last_frame = subactions_at_last_frame
        dyn_article.set_up_actions = set_up_actions
        dyn_article.tear_down_actions = tear_down_actions
        dyn_article.actions_on_clank = actions_on_clank
        dyn_article.actions_on_prevail = actions_on_prevail
        dyn_article.conditional_actions = conditional_actions
        dyn_article.collision_actions = collision_actions
        if sprite_name: dyn_article.sprite_name = sprite_name
        if sprite_rate: dyn_article.base_sprite_rate = sprite_rate
        
        return dyn_article
Пример #15
0
    def loadAction(self, _actionName):
        #Load the action XML
        action_xml = self.actions_xml.find(_actionName)
        print('loading action', action_xml, _actionName)
        #Check if it's a Python action
        if action_xml is not None and action_xml.find(
                'loadCodeAction') is not None:
            file_name = action_xml.find('loadCodeAction').find('file').text
            action_name = action_xml.find('loadCodeAction').find('action').text
            new_action = settingsManager.importFromURI(
                os.path.join(self.base_dir, file_name), file_name)
            return getattr(new_action, action_name)()

        #Get the baseClass
        class_ = None
        if (action_xml is not None) and (action_xml.find('base') is not None):
            if hasattr(baseActions, action_xml.find('base').text):
                class_ = getattr(baseActions, action_xml.find('base').text)
        else:
            if hasattr(baseActions, _actionName):
                class_ = getattr(baseActions, _actionName)

        if class_: base = class_
        else: base = action.Action
        if action_xml is None:
            return base()

        #Get the action variables
        length = int(self.loadNodeWithDefault(action_xml, 'length', 1))
        starting_frame = int(
            self.loadNodeWithDefault(action_xml, 'starting_frame', 0))
        sprite_name = self.loadNodeWithDefault(action_xml, 'sprite', None)
        sprite_rate = int(
            self.loadNodeWithDefault(action_xml, 'sprite_rate', 1))
        loop = self.loadNodeWithDefault(action_xml, 'loop', False) == 'True'

        action_vars = {}
        if action_xml.find('vars') is not None:
            for var in action_xml.find('vars'):
                t = var.attrib['type'] if var.attrib.has_key('type') else None
                if t and t == 'int':
                    action_vars[var.tag] = int(var.text)
                elif t and t == 'float':
                    action_vars[var.tag] = float(var.text)
                elif t and t == 'bool':
                    action_vars[var.tag] = (var.text == 'True')
                elif t and t == 'tuple':
                    action_vars[var.tag] = make_tuple(var.text)
                else:
                    action_vars[var.tag] = var.text

        #Load the SetUp subactions
        set_up_actions = []
        if action_xml.find('setUp') is not None:
            for subact in action_xml.find('setUp'):
                print('loading setup actions', subaction.subactionFactory,
                      subact, subact.tag)
                if subaction.subactionFactory.getSubaction(subact.tag):
                    set_up_actions.append(
                        subaction.subactionFactory.buildFromXml(
                            subact.tag, subact))
        print('loading set up actions', set_up_actions)
        #Load the tearDown subactions
        tear_down_actions = []
        if action_xml.find('tearDown') is not None:
            for subact in action_xml.find('tearDown'):
                if subaction.subactionFactory.getSubaction(
                        subact.tag):  #Subactions string to class dict
                    tear_down_actions.append(
                        subaction.subactionFactory.buildFromXml(
                            subact.tag, subact))

        #Load the stateTransition subactions
        state_transition_actions = []
        if action_xml.find('transitions') is not None:
            for subact in action_xml.find('transitions'):
                if subaction.subactionFactory.getSubaction(
                        subact.tag):  #Subactions string to class dict
                    state_transition_actions.append(
                        subaction.subactionFactory.buildFromXml(
                            subact.tag, subact))

        actions_on_clank = []
        if action_xml.find('onClank') is not None:
            for subact in action_xml.find('onClank'):
                if subaction.subactionFactory.getSubaction(
                        subact.tag):  #Subactions string to class dict
                    actions_on_clank.append(
                        subaction.subactionFactory.buildFromXml(
                            subact.tag, subact))

        actions_on_prevail = []
        if action_xml.find('onPrevail') is not None:
            for subact in action_xml.find('onPrevail'):
                if subaction.subactionFactory.getSubaction(
                        subact.tag):  #Subactions string to class dict
                    actions_on_prevail.append(
                        subaction.subactionFactory.buildFromXml(
                            subact.tag, subact))

        #Load all of the frames
        frames = action_xml.findall('frame')
        subactions_before_frame = []
        subactions_after_frame = []
        subactions_at_last_frame = []

        for frame in frames:
            if frame.attrib['number'] == 'before':
                for subact in frame:
                    if subaction.subactionFactory.getSubaction(
                            subact.tag):  #Subactions string to class dict
                        subactions_before_frame.append(
                            subaction.subactionFactory.buildFromXml(
                                subact.tag, subact))
                frames.remove(frame)
            if frame.attrib['number'] == 'after':
                for subact in frame:
                    if subaction.subactionFactory.getSubaction(
                            subact.tag):  #Subactions string to class dict
                        subactions_after_frame.append(
                            subaction.subactionFactory.buildFromXml(
                                subact.tag, subact))
                frames.remove(frame)
            if frame.attrib['number'] == 'last':
                for subact in frame:
                    if subaction.subactionFactory.getSubaction(
                            subact.tag):  #Subactions string to class dict
                        subactions_at_last_frame.append(
                            subaction.subactionFactory.buildFromXml(
                                subact.tag, subact))
                frames.remove(frame)

        subactions_at_frame = []

        #Iterate through every frame possible (not just the ones defined)
        for frame_number in range(0, length + 1):
            sublist = []
            if frames:
                for frame in frames:
                    if frame.attrib['number'] == str(
                            frame_number
                    ):  #If this frame matches the number we're on
                        for subact in frame:
                            if subaction.subactionFactory.getSubaction(
                                    subact.tag
                            ):  #Subactions string to class dict
                                sublist.append(
                                    subaction.subactionFactory.buildFromXml(
                                        subact.tag, subact))

                        frames.remove(frame)  #Done with this one

            subactions_at_frame.append(
                sublist)  #Put the list in, whether it's empty or not

        #Interpret frame ranges
        for frame in frames:
            if "," in frame.attrib['number'] and frame.attrib[
                    'number'].replace(",", "").replace(" ", "").isdigit():
                for subact in frame:
                    if subaction.subactionFactory.getSubaction(
                            subact.tag):  #Subactions string to class dict
                        for frame_num in make_tuple(frame.attrib['number']):
                            subactions_at_frame[frame_num].append(
                                subaction.subactionFactory.buildFromXml(
                                    subact.tag, subact))
                frames.remove(frame)

        for frame in frames:
            if "-" in frame.attrib['number'] and frame.attrib[
                    'number'].replace("-", "").replace(" ", "").isdigit():
                ends = frame.attrib['number'].split("-")
                for subact in frame:
                    if subaction.subactionFactory.getSubaction(
                            subact.tag):  #Subactions string to class dict
                        for frame_num in range(int(ends[0]), int(ends[1]) + 1):
                            subactions_at_frame[frame_num].append(
                                subaction.subactionFactory.buildFromXml(
                                    subact.tag, subact))
                frames.remove(frame)

        event_actions = dict()
        conds = action_xml.findall('conditional')
        for cond in conds:
            conditional_list = []
            for subact in cond:
                if subaction.subactionFactory.getSubaction(
                        subact.tag):  #Subactions string to class dict
                    conditional_list.append(
                        subaction.subactionFactory.buildFromXml(
                            subact.tag, subact))
            event_actions[cond.attrib['name']] = conditional_list

        events = action_xml.findall('event')
        #Because we're merging events and conditionals, this checks for either.
        events.extend(action_xml.findall('conditional'))
        for event in events:
            event_list = []
            for subact in event:
                if subaction.subactionFactory.getSubaction(subact.tag):
                    event_list.append(
                        subaction.subactionFactory.buildFromXml(
                            subact.tag, subact))
            event_actions[event.attrib['name']] = event_list

        #Create and populate the Dynamic Action
        dyn_action = base()
        dyn_action.frame = starting_frame
        dyn_action.last_frame = length
        dyn_action.name = _actionName
        dyn_action.actions_before_frame = subactions_before_frame
        dyn_action.actions_at_frame = subactions_at_frame
        dyn_action.actions_after_frame = subactions_after_frame
        dyn_action.actions_at_last_frame = subactions_at_last_frame
        dyn_action.state_transition_actions = state_transition_actions
        dyn_action.set_up_actions = set_up_actions
        dyn_action.tear_down_actions = tear_down_actions
        dyn_action.actions_on_clank = actions_on_clank
        dyn_action.actions_on_prevail = actions_on_prevail
        dyn_action.events = event_actions
        if sprite_name: dyn_action.sprite_name = sprite_name
        if sprite_rate: dyn_action.base_sprite_rate = sprite_rate
        dyn_action.loop = loop

        dyn_action.default_vars = action_vars
        for key, val in action_vars.iteritems():
            setattr(dyn_action, key, val)

        return dyn_action