Search in sources :

Example 6 with CampaignFacade

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));
}
Also used : PCGIOHandler(pcgen.io.PCGIOHandler) SourceSelectionFacade(pcgen.facade.core.SourceSelectionFacade) GameModeFacade(pcgen.facade.core.GameModeFacade) PCGFile(pcgen.io.PCGFile) File(java.io.File) CampaignFacade(pcgen.facade.core.CampaignFacade) HashSet(java.util.HashSet)

Example 7 with CampaignFacade

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;
}
Also used : Campaign(pcgen.core.Campaign) PersistenceManager(pcgen.persistence.PersistenceManager) ArrayList(java.util.ArrayList) URI(java.net.URI) CampaignFacade(pcgen.facade.core.CampaignFacade)

Example 8 with CampaignFacade

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));
        }
    }
}
Also used : GameModeFacade(pcgen.facade.core.GameModeFacade) CampaignFacade(pcgen.facade.core.CampaignFacade) DefaultListFacade(pcgen.facade.util.DefaultListFacade)

Example 9 with CampaignFacade

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);
}
Also used : CDOMDirectSingleRef(pcgen.cdom.reference.CDOMDirectSingleRef) DataSet(pcgen.core.DataSet) FollowerOption(pcgen.core.FollowerOption) CompanionList(pcgen.cdom.list.CompanionList) CDOMSimpleSingleRef(pcgen.cdom.reference.CDOMSimpleSingleRef) CampaignFacade(pcgen.facade.core.CampaignFacade) Race(pcgen.core.Race) DefaultListFacade(pcgen.facade.util.DefaultListFacade)

Example 10 with CampaignFacade

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;
}
Also used : GameMode(pcgen.core.GameMode) SourceSelectionFacade(pcgen.facade.core.SourceSelectionFacade) Campaign(pcgen.core.Campaign) ArrayList(java.util.ArrayList) CampaignFacade(pcgen.facade.core.CampaignFacade)

Aggregations

CampaignFacade (pcgen.facade.core.CampaignFacade)20 ArrayList (java.util.ArrayList)6 Campaign (pcgen.core.Campaign)5 GameMode (pcgen.core.GameMode)4 GameModeFacade (pcgen.facade.core.GameModeFacade)4 SourceSelectionFacade (pcgen.facade.core.SourceSelectionFacade)4 DefaultListFacade (pcgen.facade.util.DefaultListFacade)4 URI (java.net.URI)3 BorderLayout (java.awt.BorderLayout)2 Dimension (java.awt.Dimension)2 JPanel (javax.swing.JPanel)2 JScrollPane (javax.swing.JScrollPane)2 DataSet (pcgen.core.DataSet)2 GameModeDisplayFacade (pcgen.facade.core.GameModeDisplayFacade)2 HtmlInfoBuilder (pcgen.gui2.util.HtmlInfoBuilder)2 PCGIOHandler (pcgen.io.PCGIOHandler)2 Point (java.awt.Point)1 File (java.io.File)1 HashSet (java.util.HashSet)1 Box (javax.swing.Box)1