Class LifePathIO
java.lang.Object
mekhq.campaign.personnel.advancedCharacterBuilder.LifePathIO
Reads and writes Life Path definitions as JSON files.
A Life Path file is ordinary JSON that may be preceded by a licence header written as # comment lines.
JSON has no comment syntax, so every read here skips forward to the first line beginning with {
before handing the text to Jackson.
Files are read from two places: the shipped data directory, and a directory under the user's own
directory. Both are scanned recursively.
- Since:
- 0.50.11
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe outcome of asking the user to open a Life Path file. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionloadAllLifePaths(Campaign campaign) Loads every Life Path available to the campaign, from both the shipped data directory and the user directory.Asks the user to pick a Life Path file, then reads it.static voidsaveAction(LifePath originalRecord, File file, boolean includeLegalStatement) Writes a Life Path to an exact file, stamping it with the current version as it goes.writeToJSONWithDialog(LifePath record, boolean includeLegalStatement) Asks the user where to save a Life Path, then writes it there.static voidwriteToJSONWithoutDialog(LifePath record, String directory, boolean includeLegalStatement) Writes a Life Path into the given directory, under a file name derived from its own name.
-
Constructor Details
-
LifePathIO
public LifePathIO()
-
-
Method Details
-
loadAllLifePaths
Loads every Life Path available to the campaign, from both the shipped data directory and the user directory.A user Life Path whose id matches a shipped one replaces it, matching how camos, portraits and units already behave.
- Parameters:
campaign- the campaign being loaded, used only to parent any dialog the load raises- Returns:
- every Life Path found, keyed by id
- Since:
- 0.50.11
-
loadFromJSONWithDialog
Asks the user to pick a Life Path file, then reads it.- Returns:
- the Life Path, or the reason it could not be read, or neither when the user cancelled
- Since:
- 0.50.11
-
writeToJSONWithoutDialog
public static void writeToJSONWithoutDialog(LifePath record, String directory, boolean includeLegalStatement) Writes a Life Path into the given directory, under a file name derived from its own name.- Parameters:
record- the Life Path to writedirectory- the directory to write into, created if absentincludeLegalStatement- whether to prepend the MegaMek Data licence header- Since:
- 0.50.11
-
saveAction
Writes a Life Path to an exact file, stamping it with the current version as it goes.- Parameters:
originalRecord- the Life Path to writefile- the file to overwriteincludeLegalStatement- whether to prepend the MegaMek Data licence header- Since:
- 0.50.11
-
writeToJSONWithDialog
Asks the user where to save a Life Path, then writes it there.The file is returned so the caller knows whether the save actually happened. Anything the caller commits only on a successful save, such as a newly generated id, can then wait for that.
- Parameters:
record- the Life Path to writeincludeLegalStatement- whether to prepend the MegaMek Data licence header- Returns:
- the file written, or empty when the user cancelled
- Since:
- 0.50.11
-