Search in sources :

Example 1 with PCGIOHandler

use of pcgen.io.PCGIOHandler in project pcgen by PCGen.

the class AbstractSaveRestoreTest method runWriteRead.

protected void runWriteRead(boolean dump) {
    GameMode mode = SettingsHandler.getGame();
    String pcgString = (new PCGVer2Creator(pc, mode, null)).createPCGString();
    if (dump)
        System.err.println(pcgString);
    InputStream is = new ByteArrayInputStream(pcgString.getBytes());
    PCGIOHandler ioh = new PCGIOHandler();
    ioh.read(reloadedPC, is, true);
    assertEquals(ioh.getErrors().toString(), 0, ioh.getErrors().size());
    assertEquals(ioh.getWarnings().toString(), 0, ioh.getWarnings().size());
}
Also used : GameMode(pcgen.core.GameMode) PCGIOHandler(pcgen.io.PCGIOHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PCGVer2Creator(pcgen.io.PCGVer2Creator)

Example 2 with PCGIOHandler

use of pcgen.io.PCGIOHandler in project pcgen by PCGen.

the class ImagePreview method updateImage.

/**
	 * Update the image
	 * @param file
	 * @throws IOException
	 */
private void updateImage(final File file) throws IOException {
    if (file == null || !file.exists()) {
        image = null;
        return;
    }
    if (PCGFile.isPCGenCharacterFile(file)) {
        aPC = new PlayerCharacter(Collections.emptyList());
        new PCGIOHandler().readForPreview(aPC, file.getAbsolutePath());
        final String portraitPath = aPC.getDisplay().getPortraitPath();
        image = StringUtils.isEmpty(portraitPath) ? null : ImageIO.read(new File(portraitPath));
    } else {
        aPC = null;
        image = ImageIO.read(file);
    }
    repaint();
}
Also used : PCGIOHandler(pcgen.io.PCGIOHandler) PlayerCharacter(pcgen.core.PlayerCharacter) PCGFile(pcgen.io.PCGFile) File(java.io.File)

Example 3 with PCGIOHandler

use of pcgen.io.PCGIOHandler 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 4 with PCGIOHandler

use of pcgen.io.PCGIOHandler in project pcgen by PCGen.

the class CharacterManager method openParty.

/**
	 * This opens an existing party from a file and adds all characters to the
	 * list of open characters.
	 *  
	 * @param file the file to load this party from
	 * @param delegate the UIDelegate that these characters will use
	 * @param dataset the dataset that this will be loaded with
	 * @return The party that was opened.
	 */
public static PartyFacade openParty(File file, final UIDelegate delegate, final DataSetFacade dataset) {
    //$NON-NLS-1$
    Logging.log(Logging.INFO, "Loading party " + file.getAbsolutePath());
    PCGIOHandler ioHandler = new PCGIOHandler();
    ioHandler.readCharacterFileList(file).forEach(charFile -> openCharacter(charFile, delegate, dataset));
    characters.setFile(file);
    return characters;
}
Also used : PCGIOHandler(pcgen.io.PCGIOHandler)

Example 5 with PCGIOHandler

use of pcgen.io.PCGIOHandler in project pcgen by PCGen.

the class CharacterManager method getRequiredSourcesForCharacter.

/**
	 * 
	 * @param pcgFile a character file
	 * @param delegate  The UIDelegate used to display message to the user
	 * @return a SourceSelectionFacade or null if no sources could be found
	 */
public static SourceSelectionFacade getRequiredSourcesForCharacter(File pcgFile, UIDelegate delegate) {
    if (!PCGFile.isPCGenCharacterFile(pcgFile)) {
        throw new IllegalArgumentException();
    }
    final PCGIOHandler ioHandler = new PCGIOHandler();
    SourceSelectionFacade selection = ioHandler.readSources(pcgFile);
    if (!ioHandler.getErrors().isEmpty()) {
        ioHandler.getErrors().forEach(msg -> {
            delegate.showErrorMessage(Constants.APPLICATION_NAME, msg);
            Logging.errorPrint(msg);
        });
        return null;
    }
    return selection;
}
Also used : PCGIOHandler(pcgen.io.PCGIOHandler) SourceSelectionFacade(pcgen.facade.core.SourceSelectionFacade)

Aggregations

PCGIOHandler (pcgen.io.PCGIOHandler)8 File (java.io.File)3 PCGFile (pcgen.io.PCGFile)3 GameMode (pcgen.core.GameMode)2 PlayerCharacter (pcgen.core.PlayerCharacter)2 CampaignFacade (pcgen.facade.core.CampaignFacade)2 SourceSelectionFacade (pcgen.facade.core.SourceSelectionFacade)2 PropertyChangeListener (java.beans.PropertyChangeListener)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 JFileChooser (javax.swing.JFileChooser)1 FileFilter (javax.swing.filechooser.FileFilter)1 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)1 GameModeFacade (pcgen.facade.core.GameModeFacade)1 PCGVer2Creator (pcgen.io.PCGVer2Creator)1 PlayerCharacterWasLoadedMessage (pcgen.pluginmgr.messages.PlayerCharacterWasLoadedMessage)1