Search in sources :

Example 71 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.

the class RunConvertPanel method performAnalysis.

/**
	 * @see pcgen.gui2.converter.panel.ConvertSubPanel#performAnalysis(pcgen.cdom.base.CDOMObject)
	 */
@Override
public boolean performAnalysis(final CDOMObject pc) {
    logSummary(pc);
    final File rootDir = pc.get(ObjectKey.DIRECTORY);
    final File outDir = pc.get(ObjectKey.WRITE_DIRECTORY);
    totalCampaigns = new ArrayList<>(pc.getSafeListFor(ListKey.CAMPAIGN));
    for (Campaign campaign : pc.getSafeListFor(ListKey.CAMPAIGN)) {
        // Add all sub-files to the main campaign, regardless of exclusions
        for (CampaignSourceEntry fName : campaign.getSafeListFor(ListKey.FILE_PCC)) {
            URI uri = fName.getURI();
            if (PCGFile.isPCGenCampaignFile(uri)) {
                Campaign c = Globals.getCampaignByURI(uri, false);
                if (c != null) {
                    totalCampaigns.add(c);
                }
            }
        }
    }
    sortCampaignsByRank(totalCampaigns);
    new Thread(new Runnable() {

        @Override
        public void run() {
            Logging.registerHandler(getHandler());
            SettingsHandler.setGame(pc.get(ObjectKey.GAME_MODE).getName());
            GameMode mode = SettingsHandler.getGame();
            //Necessary for "good" behavior
            mode.resolveInto(context.getReferenceContext());
            //Necessary for those still using Globals.getContext
            mode.resolveInto(mode.getContext().getReferenceContext());
            LSTConverter converter;
            Writer changeLogWriter;
            try {
                changeLogWriter = new FileWriter(changeLogFile);
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                String startTime = simpleDateFormat.format(new Date());
                changeLogWriter.append("PCGen Data Converter v" + PCGenPropBundle.getVersionNumber() + " - conversion started at " + startTime + "\n");
                changeLogWriter.append("Outputting files to " + outDir.getAbsolutePath() + "\n");
            } catch (IOException e1) {
                Logging.errorPrint("Failed to initialise LSTConverter", e1);
                return;
            }
            converter = new LSTConverter(context, rootDir, outDir.getAbsolutePath(), RunConvertPanel.this, changeLogWriter);
            converter.addObserver(RunConvertPanel.this);
            int numFiles = 0;
            for (Campaign campaign : totalCampaigns) {
                numFiles += converter.getNumFilesInCampaign(campaign);
            }
            setTotalFileCount(numFiles);
            converter.initCampaigns(totalCampaigns);
            for (Campaign campaign : totalCampaigns) {
                converter.processCampaign(campaign);
            }
            ObjectInjector oi = new ObjectInjector(context, outDir, rootDir, converter);
            try {
                oi.writeInjectedObjects(totalCampaigns);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                changeLogWriter.close();
            } catch (IOException e) {
                Logging.errorPrint("LSTConverter.wrapUp failed", e);
            }
            converter.deleteObserver(RunConvertPanel.this);
            Logging.removeHandler(getHandler());
            try {
                // Wait for any left over messages to catch up
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            // Ignore exception
            }
            setCurrentFilename("");
            addMessage("\nConversion complete.");
            if (getHandler().getNumErrors() > 0) {
                JOptionPane.showMessageDialog(null, LanguageBundle.getFormattedString(//$NON-NLS-1$
                "in_lstConvErrorsFound", getHandler().getNumErrors()), LanguageBundle.getString(//$NON-NLS-1$
                "in_lstConvErrorsTitle"), JOptionPane.ERROR_MESSAGE);
            }
            progressBar.setValue(progressBar.getMaximum());
            fireProgressEvent(ProgressEvent.AUTO_ADVANCE);
        }
    }).start();
    return true;
}
Also used : LSTConverter(pcgen.gui2.converter.LSTConverter) FileWriter(java.io.FileWriter) IOException(java.io.IOException) URI(java.net.URI) Date(java.util.Date) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) GameMode(pcgen.core.GameMode) Campaign(pcgen.core.Campaign) PCGFile(pcgen.io.PCGFile) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) ObjectInjector(pcgen.gui2.converter.ObjectInjector) Writer(java.io.Writer) FileWriter(java.io.FileWriter)

Example 72 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.

the class BiosetToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Campaign campaign, String value) {
    CampaignSourceEntry cse = context.getCampaignSourceEntry(campaign, value);
    if (cse == null) {
        //Error
        return ParseResult.INTERNAL_ERROR;
    }
    if (!cse.getIncludeItems().isEmpty()) {
        return new ParseResult.Fail(getTokenName() + " does not allow INCLUDE: " + value, context);
    }
    if (!cse.getExcludeItems().isEmpty()) {
        return new ParseResult.Fail(getTokenName() + " does not allow EXCLUDE: " + value, context);
    }
    context.getObjectContext().addToList(campaign, ListKey.FILE_BIO_SET, cse);
    return ParseResult.SUCCESS;
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry)

Example 73 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.

the class BiosetToken method unparse.

@Override
public String[] unparse(LoadContext context, Campaign campaign) {
    Changes<CampaignSourceEntry> cseChanges = context.getObjectContext().getListChanges(campaign, ListKey.FILE_BIO_SET);
    Collection<CampaignSourceEntry> added = cseChanges.getAdded();
    if (added == null) {
        //empty indicates no token
        return null;
    }
    Set<String> set = new TreeSet<>();
    for (CampaignSourceEntry cse : added) {
        set.add(cse.getLSTformat());
    }
    return set.toArray(new String[set.size()]);
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) TreeSet(java.util.TreeSet)

Example 74 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.

the class GlobalModifierToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Campaign campaign, String value) {
    CampaignSourceEntry cse = context.getCampaignSourceEntry(campaign, value);
    if (cse == null) {
        //Error
        return ParseResult.INTERNAL_ERROR;
    }
    if (!cse.getIncludeItems().isEmpty()) {
        return new ParseResult.Fail(getTokenName() + " does not support Include");
    }
    if (!cse.getExcludeItems().isEmpty()) {
        return new ParseResult.Fail(getTokenName() + " does not support Exclude");
    }
    if (!cse.getPrerequisites().isEmpty()) {
        return new ParseResult.Fail(getTokenName() + " does not support Prerequisites");
    }
    context.getObjectContext().addToList(campaign, ListKey.FILE_GLOBALMOD, cse);
    return ParseResult.SUCCESS;
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry)

Example 75 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.

the class LicenseToken method unparse.

@Override
public String[] unparse(LoadContext context, Campaign campaign) {
    Changes<String> changes = context.getObjectContext().getListChanges(campaign, ListKey.LICENSE);
    Changes<CampaignSourceEntry> filechanges = context.getObjectContext().getListChanges(campaign, ListKey.LICENSE_FILE);
    List<String> set = new ArrayList<>();
    Collection<String> added = changes.getAdded();
    if (added != null && !added.isEmpty()) {
        set.addAll(added);
    }
    Collection<CampaignSourceEntry> addeduri = filechanges.getAdded();
    if (addeduri != null && !addeduri.isEmpty()) {
        for (CampaignSourceEntry cse : addeduri) {
            set.add("FILE=" + cse.getLSTformat());
        }
    }
    if (set.isEmpty()) {
        //Okay, no license info
        return null;
    }
    return set.toArray(new String[set.size()]);
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) ArrayList(java.util.ArrayList)

Aggregations

CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)95 URI (java.net.URI)54 Campaign (pcgen.core.Campaign)44 URISyntaxException (java.net.URISyntaxException)27 LoadContext (pcgen.rules.context.LoadContext)25 UnreachableError (pcgen.base.lang.UnreachableError)19 BeforeClass (org.junit.BeforeClass)16 PCClassLoader (pcgen.persistence.lst.PCClassLoader)15 TreeSet (java.util.TreeSet)12 PlayerCharacter (pcgen.core.PlayerCharacter)11 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)11 ArrayList (java.util.ArrayList)9 PCClass (pcgen.core.PCClass)9 File (java.io.File)8 GenericLoader (pcgen.persistence.lst.GenericLoader)8 CDOMReference (pcgen.cdom.base.CDOMReference)7 SourceEntry (pcgen.persistence.lst.SourceEntry)7 Ability (pcgen.core.Ability)6 FeatLoader (pcgen.persistence.lst.FeatLoader)6 AbilityList (pcgen.cdom.list.AbilityList)5