Package megamek.common
Class SourceBooks
java.lang.Object
megamek.common.SourceBooks
This class manages sourcebook information, usually loaded from the data/sourcebooks folder. Sourcebooks are not
automatically loaded into memory when instantiating this class but are loaded on-demand only.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a sourcebooks manager for sourcebooks in the standard sourcebooks folder.SourceBooks(String directoryPath) Creates a sourcebooks manager for any sourcebooks in the given directory. -
Method Summary
Modifier and TypeMethodDescriptionReturns a list of available sourcebook filenames (with the ".yaml" extension removed).static voidstatic StringformatSourceList(Collection<String> sources) static SourceBooksbooleanisNonCanonBySource(String source, String published) loadSourceBook(String fileName) Tries to read a sourcebook file of the given name.loadSourceBooks(String sourceList) Loads any sourcebooks listed in a comma-separated source field.static StringnormalizeSourceList(String sourceList) voidsaveSourceBook(String fileName, SourceBook sourceBook) Saves a sourcebook as a YAML file in the sourcebook directory.sourceBookFile(String fileName) sourceBookKey(String fileName) splitSourceList(String sourceList)
-
Constructor Details
-
SourceBooks
Creates a sourcebooks manager for any sourcebooks in the given directory. This constructor is for testing/debugging.- Parameters:
directoryPath- The sourcebooks path to use
-
SourceBooks
public SourceBooks()Creates a sourcebooks manager for sourcebooks in the standard sourcebooks folder. This constructor does not load anything and is a cheap operation; sourcebooks are only individually loaded on demand.
-
-
Method Details
-
getStandardSourceBooks
-
availableSourcebooks
Returns a list of available sourcebook filenames (with the ".yaml" extension removed). The returned values can directly be used to obtain a book. The returned list is empty if there are no source books in the folder or if there is some error (IOExceptions are caught in this method).SourceBooks sourceBooks = new SourceBooks(); List<String> allBooks = sourceBooks.availableSourcebooks(); String firstBook = allBooks.getFirst() // assuming there are sourcebooks Optional<SourceBook> book = sourceBooks.loadSourceBook(firstBook);- Returns:
- A list of available sourcebooks
- See Also:
-
loadSourceBook
Tries to read a sourcebook file of the given name. The filename can include the .yaml extension but does not have to.- Parameters:
fileName- The filename of the sourcebook to load- Returns:
- The book, if it can be loaded.
-
saveSourceBook
Saves a sourcebook as a YAML file in the sourcebook directory.- Parameters:
fileName- The sourcebook filename or key. The .yaml extension is optional.sourceBook- The sourcebook data to save.- Throws:
IOException- if the sourcebook cannot be written.
-
clearCaches
public static void clearCaches() -
sourceBookFile
-
sourceBookKey
-
loadSourceBooks
Loads any sourcebooks listed in a comma-separated source field.- Parameters:
sourceList- A comma-separated source list, such as "TR:3039,RG29"- Returns:
- The sourcebooks that could be loaded, in source-list order
-
isNonCanonBySource
- Returns:
- true when no sourcebook entries are present or all listed sourcebooks are non-canon or cannot be loaded.
-
splitSourceList
-
normalizeSourceList
-
formatSourceList
-