use of pcgen.core.Campaign in project pcgen by PCGen.
the class CampaignLoader method loadCampaignLstFile.
/**
* Parses a campaign LST file and adds it to the Global container if not already added.
* @param filePath The file path to load.
* @throws PersistenceLayerException
*/
public void loadCampaignLstFile(URI filePath) throws PersistenceLayerException {
// Instantiate a Campaign, which will automatically establish a LoadContext
campaign = new Campaign();
campaign.setSourceURI(filePath);
// Parses the data in the referenced URI and loads it into a LoadContext;
// this quickly goes to the parseLine method below
super.loadLstFile(campaign.getCampaignContext(), filePath);
// Make sure this campaign has not already been added to the Global container
if (Globals.getCampaignByURI(campaign.getSourceURI(), false) == null) {
// Check the campaign's prerequisites, generating errors if any are not met but proceeding
validatePrereqs(campaign.getPrerequisiteList());
List<String> copyright = campaign.getListFor(ListKey.SECTION_15);
if (copyright != null) {
StringBuilder sec15 = Globals.getSection15();
sec15.append("<br><b>Source Material:</b>");
sec15.append(SourceFormat.getFormattedString(campaign, SourceFormat.LONG, true));
sec15.append("<br>");
sec15.append("<b>Section 15 Entry in Source Material:</b><br>");
for (String license : copyright) {
sec15.append(license).append("<br>");
}
}
// Adds this campaign to the Global container.
Globals.addCampaign(campaign);
}
}
use of pcgen.core.Campaign in project pcgen by PCGen.
the class CampaignLoader method initRecursivePccFiles.
/**
* This method initializes any campaigns that include other campaigns,
* avoiding an infinite loop in the event of recursive (for example
* interdependent campaigns)
*
* This specific overloading will recurse down the given
* campaign object dependency tree, then return
*
* @param baseCampaign Campaign object that may or may not require
* other campaigns
*/
public void initRecursivePccFiles(Campaign baseCampaign) //throws PersistenceLayerException
{
if (baseCampaign == null || inittedCampaigns.contains(baseCampaign)) {
return;
}
inittedCampaigns.add(baseCampaign);
// Add all sub-files to the base campaign, regardless of exclusions
for (CampaignSourceEntry cse : baseCampaign.getSafeListFor(ListKey.FILE_PCC)) {
URI fName = cse.getURI();
if (PCGFile.isPCGenCampaignFile(fName)) {
// Find referenced campaign if loaded
Campaign globalSubCampaign = Globals.getCampaignByURI(fName, false);
// If this campaign has not already been loaded, do so
if (globalSubCampaign == null) {
try {
loadCampaignLstFile(fName);
globalSubCampaign = Globals.getCampaignByURI(fName, false);
} catch (PersistenceLayerException e) {
Logging.errorPrint("Recursive init failed on file " + fName, e);
}
}
// add all sub-subs etc to the list
initRecursivePccFiles(globalSubCampaign);
// add subfile to the parent campaign for loading
initRecursivePccFiles(baseCampaign, globalSubCampaign);
}
}
}
use of pcgen.core.Campaign in project pcgen by PCGen.
the class SourceFileLoader method addDefaultEquipmentMods.
private void addDefaultEquipmentMods(LoadContext context) throws PersistenceLayerException {
URI uri = URI.create("file:/" + eqModLoader.getClass().getName() + ".java");
context.setSourceURI(uri);
SourceEntry source = new CampaignSourceEntry(new Campaign(), uri);
LoadContext subContext = context.dropIntoContext("EQUIPMENT");
String aLine;
aLine = "Add Type\tKEY:ADDTYPE\tTYPE:ALL\tCOST:0\tNAMEOPT:NONAME\tSOURCELONG:PCGen Internal\tCHOOSE:EQBUILDER.EQTYPE|COUNT=ALL|TITLE=desired TYPE(s)";
eqModLoader.parseLine(subContext, null, aLine, source);
//
// Add internal equipment modifier for adding weapon/armor types to
// equipment
//
aLine = Constants.INTERNAL_EQMOD_WEAPON + "\tTYPE:Weapon\tVISIBLE:NO\tCHOOSE:NOCHOICE\tNAMEOPT:NONAME";
eqModLoader.parseLine(subContext, null, aLine, source);
aLine = Constants.INTERNAL_EQMOD_ARMOR + "\tTYPE:Armor\tVISIBLE:NO\tCHOOSE:NOCHOICE\tNAMEOPT:NONAME";
eqModLoader.parseLine(subContext, null, aLine, source);
}
use of pcgen.core.Campaign in project pcgen by PCGen.
the class SourceFileLoader method addDefaultDataControlIfNeeded.
/**
* Add default data control files to the supplied list, but only if it is empty.
*
* @param dataDefFileList The list of data control files.
*/
public static List<CampaignSourceEntry> addDefaultDataControlIfNeeded(List<CampaignSourceEntry> dataDefFileList) {
if (dataDefFileList == null) {
dataDefFileList = new ArrayList<>();
}
if (dataDefFileList.isEmpty()) {
File gameModeDir = new File(ConfigurationSettings.getSystemsDir(), "gameModes");
File defaultGameModeDir = new File(gameModeDir, "default");
File df = new File(defaultGameModeDir, "compatibilityDataControl.lst");
Campaign c = new Campaign();
c.setName("Default Data Control File");
CampaignSourceEntry cse = new CampaignSourceEntry(c, df.toURI());
dataDefFileList.add(cse);
}
return dataDefFileList;
}
use of pcgen.core.Campaign in project pcgen by PCGen.
the class SourceFileLoader method loadCampaigns.
private void loadCampaigns() throws PersistenceLayerException {
// Unload the existing campaigns and load our selected campaign
Globals.emptyLists();
PersistenceManager pManager = PersistenceManager.getInstance();
List<URI> uris = new ArrayList<>();
for (CampaignFacade campaignFacade : selectedCampaigns) {
uris.add(((Campaign) campaignFacade).getSourceURI());
}
pManager.setChosenCampaignSourcefiles(uris);
sourcesSet.clear();
licenseFiles.clear();
if (selectedCampaigns.isEmpty()) {
throw new PersistenceLayerException("You must select at least one campaign to load.");
}
// -- sage_sam
try {
LoadContext context = Globals.getContext();
loadCampaigns(selectedGame, selectedCampaigns, context);
// Load custom items
loadCustomItems(context);
finishLoad(selectedCampaigns, context);
// Check for valid race types
// checkRaceTypes();
// Verify weapons are melee or ranged
verifyWeaponsMeleeOrRanged(context);
// Auto-gen additional equipment
if (PCGenSettings.OPTIONS_CONTEXT.initBoolean(PCGenSettings.OPTION_AUTOCREATE_MW_MAGIC_EQUIP, false)) {
EquipmentList.autoGenerateEquipment();
}
for (Campaign campaign : selectedCampaigns) {
sourcesSet.add(SourceFormat.getFormattedString(campaign, SourceFormat.MEDIUM, true));
}
context.setLoaded(selectedCampaigns);
/*
* This needs to happen after auto equipment generation and after
* context.setLoaded, not in finishLoad
*/
context.loadCampaignFacets();
dataset = new DataSet(context, selectedGame, new DefaultListFacade<>(selectedCampaigns));
// // Show the licenses
// showLicensesIfNeeded();
// showSponsorsIfNeeded();
} catch (Throwable thr) {
Logging.errorPrint("Exception loading files.", thr);
uiDelegate.showErrorMessage(Constants.APPLICATION_NAME, "Failed to load campaigns, see log for details.");
}
}
Aggregations