use of pcgen.core.Campaign in project pcgen by PCGen.
the class LstObjectFileLoader method performMod.
/**
* This method will perform a multi-line .MOD operation. This is used
* for example in MODs of CLASSES which can have multiple lines. Loaders
* can [typically] use the name without checking
* for (or stripping off) .MOD due to the implementation of
* CDOMObject.setName()
* @param entryList
*/
private void performMod(LoadContext context, List<ModEntry> entryList) {
ModEntry entry = entryList.get(0);
// get the name of the object to modify, trimming off the .MOD
int nameEnd = entry.getLstLine().indexOf(MOD_SUFFIX);
String key = entry.getLstLine().substring(0, nameEnd);
List<String> includeItems = entry.source.getIncludeItems();
// remove the leading tag, if any (i.e. CLASS:Druid.MOD
int nameStart = key.indexOf(':');
if (nameStart > 0) {
key = key.substring(nameStart + 1);
}
// get the actual object to modify
T object = context.getReferenceContext().performMod(getObjectKeyed(context, key));
if (object == null) {
if (!includeItems.isEmpty() && !includeItems.contains(key)) {
return;
}
if (excludedObjects.contains(key)) {
return;
}
String message = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Errors.LstFileLoader.ModObjectNotFound", entry.getSource().getURI(), entry.getLineNumber(), key);
Logging.log(Logging.LST_ERROR, message);
setChanged();
return;
}
// modify the object
try {
if (includeItems.isEmpty() || includeItems.contains(key)) {
for (ModEntry element : entryList) {
context.setSourceURI(element.source.getURI());
try {
String origPage = object.get(StringKey.SOURCE_PAGE);
parseLine(context, object, element.getLstLine(), element.getSource());
if (origPage != object.get(StringKey.SOURCE_PAGE)) {
Campaign campaign = element.source.getCampaign();
object.put(ObjectKey.SOURCE_CAMPAIGN, campaign);
object.put(StringKey.SOURCE_SHORT, campaign.get(StringKey.SOURCE_SHORT));
object.put(StringKey.SOURCE_LONG, campaign.get(StringKey.SOURCE_LONG));
object.put(ObjectKey.SOURCE_DATE, campaign.get(ObjectKey.SOURCE_DATE));
object.put(StringKey.SOURCE_WEB, campaign.get(StringKey.SOURCE_WEB));
object.setSourceURI(element.source.getURI());
}
} catch (PersistenceLayerException ple) {
String message = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Errors.LstFileLoader.ModParseError", element.getSource().getURI(), element.getLineNumber(), ple.getMessage());
Logging.errorPrint(message);
setChanged();
}
}
}
completeObject(context, entry.getSource(), object);
} catch (PersistenceLayerException ple) {
String message = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Errors.LstFileLoader.ModParseError", entry.getSource().getURI(), entry.getLineNumber(), ple.getMessage());
Logging.errorPrint(message);
setChanged();
}
}
use of pcgen.core.Campaign 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);
}
}
use of pcgen.core.Campaign 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);
}
use of pcgen.core.Campaign in project pcgen by PCGen.
the class LoadValidator method buildCategoryMap.
private void buildCategoryMap() {
categoryMap = new DoubleKeyMapToList<>();
for (Campaign c : campaignList) {
for (Qualifier q : c.getSafeListFor(ListKey.FORWARDREF)) {
Class<? extends Loadable> qcl = q.getQualifiedClass();
if (CATEGORIZED_CLASS.isAssignableFrom(qcl)) {
CDOMSingleRef<?> ref = q.getQualifiedReference();
String cat = ((CDOMTransparentCategorizedSingleRef<?>) ref).getLSTCategory();
categoryMap.addToListFor(qcl, cat, ref.getLSTformat(false));
}
}
}
}
use of pcgen.core.Campaign in project pcgen by PCGen.
the class CampaignPanel method initSourceSelection.
/**
*
*/
private void initSourceSelection(CampaignTableModel model, JTable table) {
// Select any previous selections
PCGenSettings context = PCGenSettings.getInstance();
String sourceString = context.initProperty(PCGenSettings.CONVERT_SOURCES, "");
String[] sources = sourceString.split("\\|");
for (String srcName : sources) {
for (Campaign camp : gameModeCampaigns) {
if (camp.toString().equals(srcName)) {
for (int i = 0; i < model.getRowCount(); i++) {
if (camp.equals(model.getValueAt(i, 0))) {
table.getSelectionModel().addSelectionInterval(i, i);
break;
}
}
break;
}
}
}
}
Aggregations