Package megamek.common.loaders
Class MekFileParser
java.lang.Object
megamek.common.loaders.MekFileParser
Switches between the various type-specific parsers depending on suffix
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMekFileParser(File f, String entryName) MekFileParser(InputStream is, String fileName) MekFileParser(String content) -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddispose()static voidstatic voidinitCanonUnitNames(File dir, String fileName) Initialize the list of canon unit names; should only be called if canonUnitNames is null or needs to be reinitialized.static booleanisCanonUnitName(String unitName) Tests whether a unit name is on the official canon unit list.static voidLinks machine gun arrays to their machine guns using the bayWeapon list.static EntityloadEntity(File f, String entityName) static voidvoidparse(InputStream is, String fileName) voidParse a string containing the representation of a unit.static voidpostLoadInit(Entity ent) File-format agnostic location to do post-load initialization on a unit.static voidsetCanonUnitNames(Vector<String> unitNames) Directly assign a Vector of unit names; protected for unit testing purposes
-
Field Details
-
FILENAME_OFFICIAL_UNITS
- See Also:
-
-
Constructor Details
-
MekFileParser
- Throws:
EntityLoadingException
-
MekFileParser
- Throws:
EntityLoadingException
-
MekFileParser
- Throws:
EntityLoadingException
-
MekFileParser
- Throws:
EntityLoadingException
-
-
Method Details
-
initCanonUnitNames
public static void initCanonUnitNames() -
initCanonUnitNames
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 befileName- String name of the file containing canon unit names
-
setCanonUnitNames
Directly assign a Vector of unit names; protected for unit testing purposes- Parameters:
unitNames- List of unit names
-
isCanonUnitName
Tests whether a unit name is on the official canon unit list.Callers that hold an
Entityusually wantEntity.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 byEntity.getShortNameRaw()- Returns:
trueif the name is a canon unit
-
getEntity
-
parse
- Throws:
Exception
-
parse
Parse a string containing the representation of a unit.- Parameters:
content- String containing the unit representation- Throws:
Exception
-
postLoadInit
File-format agnostic location to do post-load initialization on a unit. Automatically add BattleArmorHandles to all OmniMek's.- Throws:
EntityLoadingException
-
linkMGAs
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-Entitywith a machine gun array.
-
main
-
loadEntity
-
dispose
public static void dispose()
-