java.lang.Object
mekhq.campaign.personnel.advancedCharacterBuilder.LifePathIO

public class LifePathIO extends Object
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
  • Constructor Details

    • LifePathIO

      public LifePathIO()
  • Method Details

    • loadAllLifePaths

      public static Map<UUID,LifePath> loadAllLifePaths(Campaign campaign)
      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

      public static LifePathIO.LifePathLoadResult 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 write
      directory - the directory to write into, created if absent
      includeLegalStatement - whether to prepend the MegaMek Data licence header
      Since:
      0.50.11
    • saveAction

      public static void saveAction(LifePath originalRecord, File file, boolean includeLegalStatement)
      Writes a Life Path to an exact file, stamping it with the current version as it goes.
      Parameters:
      originalRecord - the Life Path to write
      file - the file to overwrite
      includeLegalStatement - whether to prepend the MegaMek Data licence header
      Since:
      0.50.11
    • writeToJSONWithDialog

      public static Optional<File> writeToJSONWithDialog(LifePath record, boolean includeLegalStatement)
      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 write
      includeLegalStatement - whether to prepend the MegaMek Data licence header
      Returns:
      the file written, or empty when the user cancelled
      Since:
      0.50.11