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());
}
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();
}
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));
}
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;
}
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;
}
Aggregations