use of pcgen.persistence.PersistenceManager in project pcgen by PCGen.
the class Gui2CampaignInfoFactory method getRequirementsHTMLString.
@Override
public String getRequirementsHTMLString(CampaignFacade campaign, List<CampaignFacade> testList) {
if (campaign == null || !(campaign instanceof Campaign)) {
return "";
}
Campaign aCamp = (Campaign) campaign;
PersistenceManager pman = PersistenceManager.getInstance();
List<URI> oldList = setSourcesForPrereqTesting(testList, pman);
String preReqHtml = PrerequisiteUtilities.preReqHTMLStringsForList(null, null, aCamp.getPrerequisiteList(), false);
pman.setChosenCampaignSourcefiles(oldList);
return preReqHtml;
}
use of pcgen.persistence.PersistenceManager in project pcgen by PCGen.
the class PreCampaignTest method testTypeMatch.
/**
* Test matching by book type.
*
* @throws Exception the exception
*/
@Test
public void testTypeMatch() throws Exception {
// Setup campaigns
PersistenceManager pmgr = PersistenceManager.getInstance();
List<URI> uris = new ArrayList<>();
uris.add(camp1.getSourceURI());
pmgr.setChosenCampaignSourcefiles(uris);
final PreParserFactory factory = PreParserFactory.getInstance();
Prerequisite preCamp1 = factory.parse("PRECAMPAIGN:1,BOOKTYPE=Wild");
assertFalse("No typed campaign should be found", PrereqHandler.passes(preCamp1, null, sourceCamp));
uris.add(camp6TypeParent.getSourceURI());
pmgr.setChosenCampaignSourcefiles(uris);
assertFalse("Nested typed campaign should not be found", PrereqHandler.passes(preCamp1, null, sourceCamp));
uris.add(camp4Wild.getSourceURI());
pmgr.setChosenCampaignSourcefiles(uris);
assertTrue("Typed campaign should be found", PrereqHandler.passes(preCamp1, null, sourceCamp));
}
use of pcgen.persistence.PersistenceManager in project pcgen by PCGen.
the class PreCampaignTest method testNestedTypeMatch.
/**
* Test matching by book type.
*
* @throws Exception the exception
*/
@Test
public void testNestedTypeMatch() throws Exception {
// Setup campaigns
PersistenceManager pmgr = PersistenceManager.getInstance();
List<URI> uris = new ArrayList<>();
uris.add(camp1.getSourceURI());
pmgr.setChosenCampaignSourcefiles(uris);
final PreParserFactory factory = PreParserFactory.getInstance();
Prerequisite preCamp1 = factory.parse("PRECAMPAIGN:1,INCLUDESBOOKTYPE=Wild");
assertFalse("No typed campaign should be found", PrereqHandler.passes(preCamp1, null, sourceCamp));
uris.add(camp6TypeParent.getSourceURI());
pmgr.setChosenCampaignSourcefiles(uris);
assertTrue("Nested typed campaign should be found", PrereqHandler.passes(preCamp1, null, sourceCamp));
}
use of pcgen.persistence.PersistenceManager in project pcgen by PCGen.
the class PreCampaignTester method countCampaignByBookType.
/**
* Count the number of campaign currently loaded or selected that
* are of the book type.
*
* @param bookType the book type
* @param includeSubCampaigns Should we count included sub campaigns that match
*
* @return the number of matching campaigns
*/
private int countCampaignByBookType(String bookType, boolean includeSubCampaigns) {
Set<Campaign> matchingCampaigns = new HashSet<>();
PersistenceManager pMan = PersistenceManager.getInstance();
List<URI> selCampaigns = pMan.getChosenCampaignSourcefiles();
for (URI element : selCampaigns) {
final Campaign aCampaign = Globals.getCampaignByURI(element, false);
List<Campaign> fullCampList;
if (includeSubCampaigns) {
fullCampList = getFullCampaignList(aCampaign);
} else {
fullCampList = new ArrayList<>();
fullCampList.add(aCampaign);
}
for (Campaign camp : fullCampList) {
for (String listType : camp.getBookTypeList()) {
if (bookType.equalsIgnoreCase(listType)) {
matchingCampaigns.add(camp);
break;
}
}
}
}
return matchingCampaigns.size();
}
use of pcgen.persistence.PersistenceManager in project pcgen by PCGen.
the class FacadeFactory method passesPrereqs.
public static boolean passesPrereqs(List<CampaignFacade> campaigns) {
PersistenceManager pman = PersistenceManager.getInstance();
List<URI> oldList = pman.getChosenCampaignSourcefiles();
List<URI> uris = new ArrayList<>();
for (CampaignFacade campaignFacade : campaigns) {
uris.add(((Campaign) campaignFacade).getSourceURI());
}
pman.setChosenCampaignSourcefiles(uris);
for (CampaignFacade campaignFacade : campaigns) {
Campaign camp = ((Campaign) campaignFacade);
if (!camp.qualifies(null, camp)) {
pman.setChosenCampaignSourcefiles(oldList);
return false;
}
}
pman.setChosenCampaignSourcefiles(oldList);
return true;
}
Aggregations