Search in sources :

Example 66 with Campaign

use of pcgen.core.Campaign in project pcgen by PCGen.

the class WriteDirectoryPanel method getExistingPccs.

private List<Campaign> getExistingPccs() {
    List<File> existingFiles = new ArrayList<>();
    findPCCFiles(path, existingFiles);
    List<Campaign> matchingCampaigns = new ArrayList<>();
    for (Campaign camp : campaignList) {
        File campFile = new File(camp.getSourceURI());
        for (File file : existingFiles) {
            if (file.getName().equals(campFile.getName())) {
                matchingCampaigns.add(camp);
                break;
            }
        }
    }
    return matchingCampaigns;
}
Also used : Campaign(pcgen.core.Campaign) ArrayList(java.util.ArrayList) File(java.io.File)

Example 67 with Campaign

use of pcgen.core.Campaign 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 68 with Campaign

use of pcgen.core.Campaign in project pcgen by PCGen.

the class SourceModel method getSource.

private String getSource(StringKey sourceWeb) {
    String sourceValue = cdo.get(sourceWeb);
    //Fall back on Campaign if necessary
    if (sourceValue == null) {
        Campaign campaign = cdo.get(ObjectKey.SOURCE_CAMPAIGN);
        sourceValue = campaign.get(sourceWeb);
    }
    return sourceValue;
}
Also used : Campaign(pcgen.core.Campaign)

Example 69 with Campaign

use of pcgen.core.Campaign in project pcgen by PCGen.

the class PreVarTest method test2857848b.

public void test2857848b() {
    final PCClass warrior = new PCClass();
    warrior.setName("Warrior");
    LoadContext context = Globals.getContext();
    context.unconditionallyProcess(warrior, "DEFINE", "MyVar|0");
    context.unconditionallyProcess(warrior, "BONUS", "VAR|MyVar|2");
    final PCClass notawarrior = new PCClass();
    notawarrior.setName("NotAWarrior");
    Skill concentration = context.getReferenceContext().constructCDOMObject(Skill.class, "Concentration");
    context.unconditionallyProcess(notawarrior, "CSKILL", "Concentration");
    context.unconditionallyProcess(notawarrior, "BONUS", "SKILL|Concentration|5|PREVARGT:MyVar,1");
    assertTrue(context.getReferenceContext().resolveReferences(null));
    PCClassLoader loader = new PCClassLoader();
    try {
        SourceEntry se = new CampaignSourceEntry(new Campaign(), new URI("file://test"));
        loader.completeObject(context, se, warrior);
        loader.completeObject(context, se, notawarrior);
        PlayerCharacter character = this.getCharacter();
        character.incrementClassLevel(1, notawarrior);
        assertEquals(0, SkillModifier.modifier(concentration, character).intValue());
        character.incrementClassLevel(1, warrior);
        assertEquals(5, SkillModifier.modifier(concentration, character).intValue());
    } catch (URISyntaxException | PersistenceLayerException e) {
        fail(e.getMessage());
    }
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Skill(pcgen.core.Skill) Campaign(pcgen.core.Campaign) PlayerCharacter(pcgen.core.PlayerCharacter) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader) SourceEntry(pcgen.persistence.lst.SourceEntry) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) URISyntaxException(java.net.URISyntaxException) PCClass(pcgen.core.PCClass) URI(java.net.URI)

Example 70 with Campaign

use of pcgen.core.Campaign in project pcgen by PCGen.

the class PreVarTest method test2856626.

public void test2856626() {
    LoadContext context = Globals.getContext();
    final PCClass warrior = new PCClass();
    warrior.setName("Warrior");
    context.getReferenceContext().importObject(warrior);
    context.unconditionallyProcess(warrior, "SAB", "Test Works|PREVARGTEQ:CL,2");
    assertTrue(context.getReferenceContext().resolveReferences(null));
    PlayerCharacter character = this.getCharacter();
    character.incrementClassLevel(1, warrior);
    PCClassLoader loader = new PCClassLoader();
    try {
        CampaignSourceEntry se = new CampaignSourceEntry(new Campaign(), new URI("file://test"));
        loader.completeObject(context, se, warrior);
        PCClass notawarrior = loader.getCopy(context, "Warrior", "NotAWarrior", se);
        List<SpecialAbility> sabList = notawarrior.getListFor(ListKey.SAB);
        assertNotNull(sabList);
        assertEquals(1, sabList.size());
        SpecialAbility sab = sabList.get(0);
        assertFalse(sab.qualifies(character, notawarrior));
        character.incrementClassLevel(1, notawarrior);
        assertFalse(sab.qualifies(character, notawarrior));
        character.incrementClassLevel(1, notawarrior);
        assertTrue(sab.qualifies(character, notawarrior));
    } catch (URISyntaxException | PersistenceLayerException e) {
        fail(e.getMessage());
    }
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) PlayerCharacter(pcgen.core.PlayerCharacter) Campaign(pcgen.core.Campaign) SpecialAbility(pcgen.core.SpecialAbility) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader) URISyntaxException(java.net.URISyntaxException) PCClass(pcgen.core.PCClass) URI(java.net.URI)

Aggregations

Campaign (pcgen.core.Campaign)84 URI (java.net.URI)49 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)44 URISyntaxException (java.net.URISyntaxException)17 BeforeClass (org.junit.BeforeClass)16 LoadContext (pcgen.rules.context.LoadContext)16 ArrayList (java.util.ArrayList)14 PlayerCharacter (pcgen.core.PlayerCharacter)11 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)11 File (java.io.File)10 PCClass (pcgen.core.PCClass)10 PCClassLoader (pcgen.persistence.lst.PCClassLoader)10 UnreachableError (pcgen.base.lang.UnreachableError)9 Ability (pcgen.core.Ability)9 GameMode (pcgen.core.GameMode)7 SourceEntry (pcgen.persistence.lst.SourceEntry)7 Test (org.junit.Test)6 HashSet (java.util.HashSet)5 CampaignFacade (pcgen.facade.core.CampaignFacade)5 PCGFile (pcgen.io.PCGFile)5