use of pcgen.facade.core.CampaignFacade in project pcgen by PCGen.
the class CharacterManager method getRequiredSourcesForParty.
public static SourceSelectionFacade getRequiredSourcesForParty(File pcpFile, UIDelegate delegate) {
PCGIOHandler ioHandler = new PCGIOHandler();
List<File> files = ioHandler.readCharacterFileList(pcpFile);
if ((files == null) || files.isEmpty()) {
return null;
}
GameModeFacade gameMode = null;
HashSet<CampaignFacade> campaignSet = new HashSet<>();
for (final File file : files) {
SourceSelectionFacade selection = getRequiredSourcesForCharacter(file, delegate);
if (selection == null) {
Logging.errorPrint("Failed to find sources in: " + file.getAbsolutePath());
continue;
}
GameModeFacade game = selection.getGameMode().get();
if (gameMode == null) {
gameMode = game;
} else if (gameMode != game) {
Logging.errorPrint("Characters in " + pcpFile.getAbsolutePath() + " do not share the same game mode");
return null;
}
for (final CampaignFacade campaign : selection.getCampaigns()) {
campaignSet.add(campaign);
}
}
return FacadeFactory.createSourceSelection(gameMode, new ArrayList<>(campaignSet));
}
use of pcgen.facade.core.CampaignFacade 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;
}
use of pcgen.facade.core.CampaignFacade in project pcgen by PCGen.
the class FacadeFactory method initCampaigns.
private static void initCampaigns() {
for (final CampaignFacade campaign : campaigns) {
campaignMap.put(campaign.getName(), campaign);
ListFacade<GameModeFacade> gameModeList = campaign.getGameModes();
for (GameModeFacade gameModeFacade : gameModeList) {
if (!campaignListMap.containsKey(gameModeFacade)) {
campaignListMap.put(gameModeFacade, new DefaultListFacade<>());
}
DefaultListFacade<CampaignFacade> campaignList = campaignListMap.get(gameModeFacade);
if (campaignList.containsElement(campaign)) {
String sourceUri = ((CDOMObject) campaign).getSourceURI().toString();
Logging.errorPrint("Campaign " + sourceUri + " lists GAMEMODE:" + gameModeFacade + " multiple times.");
} else {
campaignList.addElement(campaign);
}
}
if (campaign.showInMenu() && !gameModeList.isEmpty()) {
GameModeFacade game = gameModeList.getElementAt(0);
ListFacade<CampaignFacade> list = new DefaultListFacade<>(Collections.singleton(campaign));
quickSources.addElement(new BasicSourceSelectionFacade(campaign.getName(), list, game));
}
}
}
use of pcgen.facade.core.CampaignFacade in project pcgen by PCGen.
the class CompanionSupportFacadeImplTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
uiDelegate = new MockUIDelegate();
todoManager = new TodoManager();
ListFacade<CampaignFacade> campaigns = new DefaultListFacade<>();
dataSetFacade = new DataSet(Globals.getContext(), SettingsHandler.getGame(), campaigns);
masterRace = TestHelper.makeRace("Wood Elf");
companionRace = TestHelper.makeRace("Weasel");
CDOMReference<Race> race = new CDOMDirectSingleRef<>(companionRace);
CDOMSingleRef<CompanionList> ref = new CDOMSimpleSingleRef<>(CompanionList.class, companionList.getKeyName());
FollowerOption option = new FollowerOption(race, ref);
masterRace.addToListFor(ListKey.COMPANIONLIST, option);
}
use of pcgen.facade.core.CampaignFacade in project pcgen by PCGen.
the class DataLoadTest method getBasicSources.
private static List<SourceSelectionFacade> getBasicSources() {
List<SourceSelectionFacade> basicSources = new ArrayList<>();
for (Campaign campaign : Globals.getCampaignList()) {
if (campaign.showInMenu()) {
SourceSelectionFacade sourceSelection = FacadeFactory.createSourceSelection(campaign.getGameModes().getElementAt(0), Collections.singletonList(campaign), campaign.getName());
basicSources.add(sourceSelection);
}
}
for (GameMode mode : SystemCollections.getUnmodifiableGameModeList()) {
String title = mode.getDefaultSourceTitle();
if (title == null && !mode.getDefaultDataSetList().isEmpty()) {
title = mode.getName();
}
if (!mode.getDefaultDataSetList().isEmpty()) {
List<CampaignFacade> qcamps = new ArrayList<>();
List<String> sources = mode.getDefaultDataSetList();
for (String string : sources) {
Campaign camp = Globals.getCampaignKeyed(string);
assertNotNull("Cannot find source " + string + " for game mode " + mode, camp);
qcamps.add(camp);
}
basicSources.add(FacadeFactory.createSourceSelection(mode, qcamps, mode.getDefaultSourceTitle()));
}
}
return basicSources;
}
Aggregations