Search in sources :

Example 56 with Campaign

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);
    }
}
Also used : Campaign(pcgen.core.Campaign)

Example 57 with 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);
        }
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Campaign(pcgen.core.Campaign) URI(java.net.URI)

Example 58 with Campaign

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);
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Campaign(pcgen.core.Campaign) LoadContext(pcgen.rules.context.LoadContext) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) SourceEntry(pcgen.persistence.lst.SourceEntry) URI(java.net.URI)

Example 59 with Campaign

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;
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Campaign(pcgen.core.Campaign) PCGFile(pcgen.io.PCGFile) File(java.io.File)

Example 60 with Campaign

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.");
    }
}
Also used : Campaign(pcgen.core.Campaign) DataSet(pcgen.core.DataSet) ArrayList(java.util.ArrayList) LoadContext(pcgen.rules.context.LoadContext) URI(java.net.URI) CampaignFacade(pcgen.facade.core.CampaignFacade) DefaultListFacade(pcgen.facade.util.DefaultListFacade)

Aggregations

Campaign (pcgen.core.Campaign)84 URI (java.net.URI)49 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)44 URISyntaxException (java.net.URISyntaxException)17 BeforeClass (org.junit.BeforeClass)16 LoadContext (pcgen.rules.context.LoadContext)16 ArrayList (java.util.ArrayList)14 PlayerCharacter (pcgen.core.PlayerCharacter)11 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)11 File (java.io.File)10 PCClass (pcgen.core.PCClass)10 PCClassLoader (pcgen.persistence.lst.PCClassLoader)10 UnreachableError (pcgen.base.lang.UnreachableError)9 Ability (pcgen.core.Ability)9 GameMode (pcgen.core.GameMode)7 SourceEntry (pcgen.persistence.lst.SourceEntry)7 Test (org.junit.Test)6 HashSet (java.util.HashSet)5 CampaignFacade (pcgen.facade.core.CampaignFacade)5 PCGFile (pcgen.io.PCGFile)5