Search in sources :

Example 1 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.

the class Campaign method getNotFoundSubCampaigns.

/**
	 * Returns a list of the CampaignSourceEntry objects that were referenced 
	 * by this Campaign but that could nto be found.
	 * 
	 * @return A list of <tt>CampaignSourceEntry</tt> objects that could not be found.
	 */
public List<CampaignSourceEntry> getNotFoundSubCampaigns() {
    final List<CampaignSourceEntry> pccFiles = getSafeListFor(ListKey.FILE_PCC);
    final List<CampaignSourceEntry> ret = new ArrayList<>();
    for (final CampaignSourceEntry cse : pccFiles) {
        final Campaign campaign = Globals.getCampaignByURI(cse.getURI(), true);
        if (campaign == null) {
            ret.add(cse);
        }
    }
    return ret;
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) ArrayList(java.util.ArrayList)

Example 2 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.

the class SourceFileLoader method readPccFiles.

/**
	 * This method reads the PCC (Campaign) files and, if options are allowed to
	 * be set in the sources, sets the SettingsHandler settings to reflect the
	 * changes from the campaign files.
	 *
	 * @param aSelectedCampaignsList
	 *            List of Campaigns to load
	 */
private Collection<Campaign> readPccFiles(Iterable<Campaign> aSelectedCampaignsList) {
    Collection<Campaign> loadedSet = new HashSet<>();
    // along with any options required by the campaigns...
    for (Campaign campaign : aSelectedCampaignsList) {
        if (Logging.isDebugMode()) {
            Logging.debugPrint("Loading campaign " + campaign);
        }
        loadedCampaigns.add(campaign);
        List<String> copyright = campaign.getListFor(ListKey.SECTION_15);
        if (copyright != null) {
            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>");
            }
        }
        // Update whether licenses need shown
        showOGL |= campaign.getSafe(ObjectKey.IS_OGL);
        showD20 |= campaign.getSafe(ObjectKey.IS_D20);
        showLicensed |= campaign.getSafe(ObjectKey.IS_LICENSED);
        if (campaign.getSafe(ObjectKey.IS_LICENSED)) {
            List<String> licenseList = campaign.getSafeListFor(ListKey.LICENSE);
            if (licenseList != null && !licenseList.isEmpty()) {
                licensesToDisplayString.append(licenseList);
            }
            List<CampaignSourceEntry> licenseURIs = campaign.getSafeListFor(ListKey.LICENSE_FILE);
            if (licenseURIs != null) {
                licenseFiles.addAll(licenseURIs);
            }
        }
        // check if maturity warning needs to be shown
        showMature |= campaign.getSafe(ObjectKey.IS_MATURE);
        if (campaign.getSafe(ObjectKey.IS_MATURE)) {
            matureCampaigns.append(SourceFormat.LONG.getField(campaign) + " (" + campaign.getSafe(StringKey.PUB_NAME_LONG) + ")<br>");
        }
        // Load the LST files to be loaded for the campaign
        addQualifiedSources(campaign, ListKey.FILE_LST_EXCLUDE);
        for (ListKey<CampaignSourceEntry> lk : CampaignLoader.OBJECT_FILE_LISTKEY) {
            addQualifiedSources(campaign, lk);
        }
        loadedSet.add(campaign);
        if (PCGenSettings.OPTIONS_CONTEXT.initBoolean(PCGenSettings.OPTION_ALLOWED_IN_SOURCES, true)) {
            setCampaignOptions(campaign);
        }
        // Add all sub-files to the main campaign, regardless of exclusions
        for (CampaignSourceEntry fName : campaign.getSafeListFor(ListKey.FILE_PCC)) {
            URI uri = fName.getURI();
            if (PCGFile.isPCGenCampaignFile(uri)) {
                loadedSet.add(Globals.getCampaignByURI(uri, false));
            } else {
                Logging.errorPrint("The referenced source " + uri + " is not valid.");
            }
        }
    }
    // ...but make sure to remove those files specified by LSTEXCLUDE;
    // LSTEXCLUDE should be treated as a global exclusion.
    // sage_sam 29 Dec 2003, Bug #834834
    stripLstExcludes();
    return loadedSet;
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Campaign(pcgen.core.Campaign) URI(java.net.URI) HashSet(java.util.HashSet)

Example 3 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.

the class SourceFileLoader method loadCampaigns.

private void loadCampaigns(GameMode gamemode, final List<Campaign> aSelectedCampaignsList, LoadContext context) throws PersistenceLayerException {
    Logging.log(Logging.INFO, "Loading game " + gamemode + " and sources " + aSelectedCampaignsList + ".");
    //		// The first thing we need to do is load the
    //		// correct statsandchecks.lst file for this gameMode
    //		GameMode gamemode = SettingsHandler.getGame();
    //		if (gamemode == null)
    //		{
    //			// Autoload campaigns is set but there
    //			// is no current gameMode, so just return
    //			return;
    //		}
    File gameModeDir = new File(ConfigurationSettings.getSystemsDir(), "gameModes");
    File specificGameModeDir = new File(gameModeDir, gamemode.getFolderName());
    // Sort the campaigns
    sortCampaignsByRank(aSelectedCampaignsList);
    // Read the campaigns
    Collection<Campaign> loaded = readPccFiles(aSelectedCampaignsList);
    // Add custom campaign files at the start of the lists
    addCustomFilesToStartOfList();
    // Notify our observers of how many files we intend
    // to load in total so that they can set up any
    // progress meters that they want to.
    setMaximum(countTotalFilesToLoad());
    // Load using the new LstFileLoaders
    List<CampaignSourceEntry> dataDefFileList = fileLists.getListFor(ListKey.FILE_DATACTRL);
    dataDefFileList = addDefaultDataControlIfNeeded(dataDefFileList);
    dataControlLoader.loadLstFiles(context, dataDefFileList);
    processFactDefinitions(context);
    tableLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_DATATABLE));
    dynamicLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_DYNAMIC));
    //Load Variables (foundation for other items)
    variableLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_VARIABLE));
    defineBuiltinVariables(context);
    List<CampaignSourceEntry> globalModFileList = fileLists.getListFor(ListKey.FILE_GLOBALMOD);
    if (globalModFileList.isEmpty()) {
        File defaultGameModeDir = new File(gameModeDir, "default");
        File df = new File(defaultGameModeDir, "compatibilityGlobalModifier.lst");
        Campaign c = new Campaign();
        c.setName("Default Global Modifier File");
        CampaignSourceEntry cse = new CampaignSourceEntry(c, df.toURI());
        globalModFileList.add(cse);
    }
    globalModifierLoader.loadLstFiles(context, globalModFileList);
    // load ability categories first as they used to only be at the game mode
    abilityCategoryLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_ABILITY_CATEGORY));
    for (Campaign c : loaded) {
        c.applyTo(context.getReferenceContext());
    }
    sizeLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_SIZE));
    //Now load PCC stat, check, alignment
    statLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_STAT));
    savesLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_SAVE));
    alignmentLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_ALIGNMENT));
    // load weapon profs first
    wProfLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_WEAPON_PROF));
    WeaponProf wp = context.getReferenceContext().silentlyGetConstructedCDOMObject(WeaponProf.class, "Unarmed Strike");
    if (wp == null) {
        wp = new WeaponProf();
        wp.setName(LanguageBundle.getString("Equipment.UnarmedStrike"));
        wp.put(StringKey.KEY_NAME, "Unarmed Strike");
        wp.addToListFor(ListKey.TYPE, Type.SIMPLE);
        context.getReferenceContext().importObject(wp);
    }
    aProfLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_ARMOR_PROF));
    sProfLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_SHIELD_PROF));
    // load skills before classes to handle class skills
    skillLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_SKILL));
    // load before races to handle auto known languages
    languageLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_LANGUAGE));
    // load before race or class to handle feats
    featLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_FEAT));
    // load before race or class to handle abilities
    abilityLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_ABILITY));
    raceLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_RACE));
    //Domain must load before CLASS - thpr 10/29/06
    domainLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_DOMAIN));
    spellLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_SPELL));
    deityLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_DEITY));
    classLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_CLASS));
    templateLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_TEMPLATE));
    // loaded before equipment (required)
    eqModLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_EQUIP_MOD));
    equipmentLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_EQUIP));
    companionModLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_COMPANION_MOD));
    kitLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_KIT));
    // Load the bio settings files
    bioLoader.setGameMode(gamemode.getName());
    bioLoader.loadLstFiles(context, fileLists.getListFor(ListKey.FILE_BIO_SET));
    // Check for the default deities
    checkRequiredDeities(specificGameModeDir, context);
    // Add default EQ mods
    addDefaultEquipmentMods(context);
    classLoader.loadSubLines(context);
    /*
		 * This is technically bad behavior, but we at least want to provide the
		 * hint here since we are using WeakReferences as a container for
		 * references to ensure those that are not used are not resolved.
		 */
    System.gc();
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Campaign(pcgen.core.Campaign) WeaponProf(pcgen.core.WeaponProf) PCGFile(pcgen.io.PCGFile) File(java.io.File)

Example 4 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.

the class SourceFileLoader method addCustomFilesToStartOfList.

private void addCustomFilesToStartOfList() {
    CampaignSourceEntry tempSource = null;
    // The dummy campaign for custom data.
    Campaign customCampaign = new Campaign();
    customCampaign.setName("Custom");
    customCampaign.addToListFor(ListKey.DESCRIPTION, new Description("Custom data"));
    //
    // Add the custom bioset file to the start of the list if it exists
    //
    File bioSetFile = new File(CustomData.customBioSetFilePath(true));
    if (bioSetFile.exists()) {
        tempSource = new CampaignSourceEntry(customCampaign, bioSetFile.toURI());
        fileLists.removeFromListFor(ListKey.FILE_BIO_SET, tempSource);
        fileLists.addToListFor(ListKey.FILE_BIO_SET, 0, tempSource);
    }
    //
    // Add the custom class file to the start of the list if it exists
    //
    File classFile = new File(CustomData.customClassFilePath(true));
    if (classFile.exists()) {
        tempSource = new CampaignSourceEntry(customCampaign, classFile.toURI());
        fileLists.removeFromListFor(ListKey.FILE_CLASS, tempSource);
        fileLists.addToListFor(ListKey.FILE_CLASS, 0, tempSource);
    }
    //
    // Add the custom deity file to the start of the list if it exists
    //
    File deityFile = new File(CustomData.customDeityFilePath(true));
    if (deityFile.exists()) {
        tempSource = new CampaignSourceEntry(customCampaign, deityFile.toURI());
        fileLists.removeFromListFor(ListKey.FILE_DEITY, tempSource);
        fileLists.addToListFor(ListKey.FILE_DEITY, 0, tempSource);
    }
    //
    // Add the custom domain file to the start of the list if it exists
    //
    File domainFile = new File(CustomData.customDomainFilePath(true));
    if (domainFile.exists()) {
        tempSource = new CampaignSourceEntry(customCampaign, domainFile.toURI());
        fileLists.removeFromListFor(ListKey.FILE_DOMAIN, tempSource);
        fileLists.addToListFor(ListKey.FILE_DOMAIN, 0, tempSource);
    }
    //
    // Add the custom ability file to the start of the list if it exists
    //
    File abilityFile = new File(CustomData.customAbilityFilePath(true));
    if (abilityFile.exists()) {
        tempSource = new CampaignSourceEntry(customCampaign, abilityFile.toURI());
        fileLists.removeFromListFor(ListKey.FILE_ABILITY, tempSource);
        fileLists.addToListFor(ListKey.FILE_ABILITY, 0, tempSource);
    }
    //
    // Add the custom feat file to the start of the list if it exists
    //
    File featFile = new File(CustomData.customFeatFilePath(true));
    if (featFile.exists()) {
        tempSource = new CampaignSourceEntry(customCampaign, featFile.toURI());
        fileLists.removeFromListFor(ListKey.FILE_FEAT, tempSource);
        fileLists.addToListFor(ListKey.FILE_FEAT, 0, tempSource);
    }
    //
    // Add the custom language file to the start of the list if it exists
    //
    File languageFile = new File(CustomData.customLanguageFilePath(true));
    if (languageFile.exists()) {
        tempSource = new CampaignSourceEntry(customCampaign, languageFile.toURI());
        fileLists.removeFromListFor(ListKey.FILE_LANGUAGE, tempSource);
        fileLists.addToListFor(ListKey.FILE_LANGUAGE, 0, tempSource);
    }
    //
    // Add the custom race file to the start of the list if it exists
    //
    File raceFile = new File(CustomData.customRaceFilePath(true));
    if (raceFile.exists()) {
        tempSource = new CampaignSourceEntry(customCampaign, raceFile.toURI());
        fileLists.removeFromListFor(ListKey.FILE_RACE, tempSource);
        fileLists.addToListFor(ListKey.FILE_RACE, 0, tempSource);
    }
    //
    // Add the custom skill file to the start of the list if it exists
    //
    File skillFile = new File(CustomData.customSkillFilePath(true));
    if (skillFile.exists()) {
        tempSource = new CampaignSourceEntry(customCampaign, skillFile.toURI());
        fileLists.removeFromListFor(ListKey.FILE_SKILL, tempSource);
        fileLists.addToListFor(ListKey.FILE_SKILL, 0, tempSource);
    }
    //
    // Add the custom spell file to the start of the list if it exists
    //
    File spellFile = new File(CustomData.customSpellFilePath(true));
    if (spellFile.exists()) {
        tempSource = new CampaignSourceEntry(customCampaign, spellFile.toURI());
        fileLists.removeFromListFor(ListKey.FILE_SPELL, tempSource);
        fileLists.addToListFor(ListKey.FILE_SPELL, 0, tempSource);
    }
    //
    // Add the custom template file to the start of the list if it exists
    //
    File templateFile = new File(CustomData.customTemplateFilePath(true));
    if (templateFile.exists()) {
        tempSource = new CampaignSourceEntry(customCampaign, templateFile.toURI());
        fileLists.removeFromListFor(ListKey.FILE_TEMPLATE, tempSource);
        fileLists.addToListFor(ListKey.FILE_TEMPLATE, 0, tempSource);
    }
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Campaign(pcgen.core.Campaign) Description(pcgen.core.Description) PCGFile(pcgen.io.PCGFile) File(java.io.File)

Example 5 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.

the class VariableReport method getCampaignsForGameMode.

private List<Campaign> getCampaignsForGameMode(GameMode game) {
    List<String> gameModeList = new ArrayList<>();
    gameModeList.addAll(game.getAllowedModes());
    // Only add those campaigns in the user's chosen folder and game mode
    List<Campaign> allCampaigns = Globals.getCampaignList();
    Set<Campaign> gameModeCampaigns = new HashSet<>();
    for (Campaign campaign : allCampaigns) {
        if (campaign.containsAnyInList(ListKey.GAME_MODE, gameModeList)) {
            gameModeCampaigns.add(campaign);
            for (CampaignSourceEntry fName : campaign.getSafeListFor(ListKey.FILE_PCC)) {
                URI uri = fName.getURI();
                if (PCGFile.isPCGenCampaignFile(uri)) {
                    Campaign c = Globals.getCampaignByURI(uri, false);
                    if (c != null) {
                        gameModeCampaigns.add(c);
                    }
                }
            }
        }
    }
    return new ArrayList<>(gameModeCampaigns);
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Campaign(pcgen.core.Campaign) ArrayList(java.util.ArrayList) URI(java.net.URI) HashSet(java.util.HashSet)

Aggregations

CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)95 URI (java.net.URI)54 Campaign (pcgen.core.Campaign)44 URISyntaxException (java.net.URISyntaxException)27 LoadContext (pcgen.rules.context.LoadContext)25 UnreachableError (pcgen.base.lang.UnreachableError)19 BeforeClass (org.junit.BeforeClass)16 PCClassLoader (pcgen.persistence.lst.PCClassLoader)15 TreeSet (java.util.TreeSet)12 PlayerCharacter (pcgen.core.PlayerCharacter)11 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)11 ArrayList (java.util.ArrayList)9 PCClass (pcgen.core.PCClass)9 File (java.io.File)8 GenericLoader (pcgen.persistence.lst.GenericLoader)8 CDOMReference (pcgen.cdom.base.CDOMReference)7 SourceEntry (pcgen.persistence.lst.SourceEntry)7 Ability (pcgen.core.Ability)6 FeatLoader (pcgen.persistence.lst.FeatLoader)6 AbilityList (pcgen.cdom.list.AbilityList)5