Ejemplo n.º 1
0
    def Get_Macros(self, pattern, classes=None, class_names=None):
        '''
        Returns a list of Macros with names matching the given pattern.

        * pattern
          - Wildcard virtual_path matching pattern.
        * classes
          - Optional list of macro classes to include.
        * class_names
          - Optional list of class names to include.
        '''
        # Cache patterns seen, to skip index lookup.
        if pattern not in self._get_macros_cache:
            self._get_macros_cache.add(pattern)

            # The index will match macro names to files, where a file can
            # hold multiple macros. Start by getting the files.
            game_files = File_System.Get_All_Indexed_Files('macros', pattern)

            # Add each file to the database, loading macros, xml, etc, skipping
            # those already loaded.
            for game_file in game_files:
                self.Load_File(game_file)

        # Now pick out the actual macros.
        macro_names = fnmatch.filter(self.macros.keys(), pattern.lower())
        # Filter for wanted classes, if a list was given.
        return [
            self.macros[x] for x in macro_names
            if ((not class_names or self.macros[x].class_name in class_names)
                and (not classes or isinstance(self.macros[x], tuple(classes)))
                )
        ]
Ejemplo n.º 2
0
def _Build_Storage_Objects():

    # These are a bit scattered, some in the units folder and
    # some in storagemodules. Use a name pattern match for this.
    File_System.Get_All_Indexed_Files('macros', 'storage_*')
    #File_System.Load_Files('*assets/props/StorageModules/*.xml')

    # Followup with class check for safety.
    game_files = File_System.Get_Asset_Files_By_Class('macros', 'storage')
    return Create_Objects_From_Asset_Files(game_files, storage_item_macros)
Ejemplo n.º 3
0
def Get_Ship_Macro_Files():
    '''
    Finds and returns all ship macro game files.
    '''
    # Note: normally ship macros start with "ship_".
    # However, this doesn't find the XR shippack, since they all start
    # with "units_" instead; also over-includes on XR shippack since it calls
    # some docking bay macros "ship_storage_".
    File_System.Get_All_Indexed_Files('macros', 'ship_*')
    File_System.Get_All_Indexed_Files('macros', 'units_*')

    # Search out loaded assets, which already have checked the
    # class tags. Do this for each ship class.
    ret_list = []
    for suffix in ['xs', 's', 'm', 'l', 'xl']:
        ret_list += File_System.Get_Asset_Files_By_Class(
            'macros', f'ship_{suffix}')

    return ret_list
Ejemplo n.º 4
0
    def Get_Components(self, pattern):
        '''
        Returns a list of Components with names matching the given pattern.
        '''
        # Cache patterns seen, to skip index lookup.
        if pattern not in self._get_components_cache:
            self._get_components_cache.add(pattern)

            # The index will match names to files, where a file can
            # hold multiple macros. Start by getting the files.
            game_files = File_System.Get_All_Indexed_Files(
                'components', pattern)

            # Add each file to the database, loading macros, xml, etc, skipping
            # those already loaded.
            for game_file in game_files:
                self.Load_File(game_file)

        # Now pick out the actual components.
        component_names = fnmatch.filter(self.components.keys(),
                                         pattern.lower())
        return [self.components[x] for x in component_names]
Ejemplo n.º 5
0
def Remove_Blinking_Ship_Lights():
    '''
    Removes the blinking lights from ships.
    '''

    '''
    Of interest are the omni nodes that contain animations for blinking.

    Example:    
    ' <omni name="XU Omni091" shadow="0" r="255" g="0" b="0" range="2" shadowrange="2" lighteffect="1" trigger="1" intensity="1" specularintensity="1">
    '   <lightanimations>
    '     <lightanimation name="intensity" controller="linear_float">
    '       <key frame="0" value="1"/>
    '       <key frame="4" value="1"/>
    '       <key frame="5" value="0"/>
    '       <key frame="9" value="0"/>
    '       <key frame="10" value="1"/>
    '       <key frame="14" value="1"/>
    '       <key frame="15" value="0"/>
    '       <key frame="64" value="0"/>
    '       <key frame="65" value="1"/>
    '       <key frame="69" value="1"/>
    '       <key frame="70" value="0"/>
    '       <key frame="100" value="0"/>
    '     </lightanimation>
    '   </lightanimations>
    '   <offset>
    '     <position x="-7.476295" y="-0.733321" z="-5.032233"/>
    '   </offset>
    ' </omni>

    Can do a general search for such nodes.
    Note: the blinking rate seems to be similar but not quite the same
    between ships, at least the animation key count can differ (12, 13, etc.).

    Check for "anim_poslights" in the parent part name, though
    this is not consistent across ships (eg. "anim_poslights_left"), but
    adds some safety against accidental removal of other components.

    Note: just removing the omni nodes has no effect, for whatever reason,
    but removing the entire connection node housing them is effective.
    (Removing the part also didn't work.)

    Update: the split medium miners define the anim_poslights part, but
    without accomponying omni lights, and yet still blink.
    Assuming the lights are defined elsewhere, removing the anim_poslights
    connection should turn off blinking.
    
    TODO: in 3.2 connection names were changed on some ships, which throws
    off diff patches which xpath to the connection node by name. Index would
    also fail in this case. Both are in danger of matching the wrong
    connection, which could cause fundumental problems if stored in a save,
    eg. disconnected components (losing shields/whatever).
    How can the xpath creator be induced to use a child node/attribute
    when removing a parent node?
    (Workaround might be to match tags, though no promises on that being safe.)
    '''
    ship_files  = File_System.Get_All_Indexed_Files('components','ship_*')

    # Test with just a kestrel
    #ship_files = [Load_File('assets/units/size_s/ship_tel_s_scout_01.xml')]

    for game_file in ship_files:
        xml_root = game_file.Get_Root()

        modified = False

        # Find the connection that has a uv_animation.
        for conn in xml_root.xpath(".//connection[parts/part/uv_animations/uv_animation]"):
            
            # Check the part name for anim_poslights (or a variation).
            parts = conn.xpath('./parts/part')
            # Expecting just one part.
            if len(parts) > 1:
                print('Error: multiple parts matched in {}, skipping'.format(game_file.virtual_path))
            part_name = parts[0].get('name')
            if 'anim_poslights' not in part_name:
                continue

            # Remove it from its parent.
            conn.getparent().remove(conn)
            modified = True

        if modified:
            # Commit changes right away; don't bother delaying for errors.
            game_file.Update_Root(xml_root)
            # Encourage a better xpath match rule.
            game_file.Add_Forced_Xpath_Attributes('parts/part/@name')
    return
Ejemplo n.º 6
0
def _Build_Cockpit_Objects():
    game_files = File_System.Get_All_Indexed_Files('macros', 'cockpit_*')
    return Create_Objects_From_Asset_Files(game_files, [])


##############################################################################