Class MekFileParser

java.lang.Object
megamek.common.loaders.MekFileParser

public class MekFileParser extends Object
Switches between the various type-specific parsers depending on suffix
  • Field Details

  • Constructor Details

  • Method Details

    • initCanonUnitNames

      public static void initCanonUnitNames()
    • initCanonUnitNames

      public static void initCanonUnitNames(File dir, String fileName)
      Initialize the list of canon unit names; should only be called if canonUnitNames is null or needs to be reinitialized.
      Parameters:
      dir - location where the canonUnitNames file should be
      fileName - String name of the file containing canon unit names
    • setCanonUnitNames

      public static void setCanonUnitNames(Vector<String> unitNames)
      Directly assign a Vector of unit names; protected for unit testing purposes
      Parameters:
      unitNames - List of unit names
    • isCanonUnitName

      public static boolean isCanonUnitName(String unitName)
      Tests whether a unit name is on the official canon unit list.

      Callers that hold an Entity usually want Entity.isCanon() instead. That flag is stamped when the unit is loaded, so it goes stale the moment an editor renames the unit; ask this method when the name may have changed since the load.

      Parameters:
      unitName - the unit's short name, as returned by Entity.getShortNameRaw()
      Returns:
      true if the name is a canon unit
    • getEntity

      public Entity getEntity()
    • parse

      public void parse(InputStream is, String fileName) throws Exception
      Throws:
      Exception
    • parse

      public void parse(String content) throws Exception
      Parse a string containing the representation of a unit.
      Parameters:
      content - String containing the unit representation
      Throws:
      Exception
    • postLoadInit

      public static void postLoadInit(Entity ent) throws EntityLoadingException
      File-format agnostic location to do post-load initialization on a unit. Automatically add BattleArmorHandles to all OmniMek's.
      Throws:
      EntityLoadingException
    • linkMGAs

      public static void linkMGAs(Entity entity)
      Links machine gun arrays to their machine guns using the bayWeapon list. We take the first qualifying machine gun in the location correct size and not already linked to this or another MGA and continue linking successive slots until full, or we get to a slot that does not contain a qualifying machine gun. This allows specifying which guns go with which array in the event of multiple MGAs in a location or some MGs that are not linked.
      Parameters:
      entity - Entity with a machine gun array.
    • main

      public static void main(String[] args)
    • loadEntity

      public static Entity loadEntity(File f, String entityName)
    • dispose

      public static void dispose()