Search in sources :

Example 11 with CampaignSourceEntry

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

the class PCClassTest method testGetPCCText.

/**
	 * Test the processing of getPCCText to ensure that it correctly produces
	 * an LST representation of an object and that the LST can then be reloaded
	 * to recrete the object.
	 *
	 * @throws PersistenceLayerException
	 */
public void testGetPCCText() throws PersistenceLayerException {
    FactKey.getConstant("Abb", new StringManager());
    // Test a basic class
    String classPCCText = humanoidClass.getPCCText();
    assertNotNull("PCC Text for race should not be null", classPCCText);
    CampaignSourceEntry source;
    try {
        source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    PCClass reconstClass = null;
    System.out.println("Got text:" + classPCCText);
    reconstClass = parsePCClassText(classPCCText, source);
    assertEquals("getPCCText should be the same after being encoded and reloaded", classPCCText, reconstClass.getPCCText());
    assertEquals("Class abbrev was not restored after saving and reloading.", humanoidClass.getAbbrev(), reconstClass.getAbbrev());
    // Test a class with some innate spells
    String b = "1" + "\t" + "SPELLS:" + "Humanoid|TIMES=1|CASTERLEVEL=var(\"TCL\")|Create undead,11+WIS";
    PCClassLoader classLoader = new PCClassLoader();
    classLoader.parseLine(Globals.getContext(), humanoidClass, b, source);
    classPCCText = humanoidClass.getPCCText();
    assertNotNull("PCC Text for race should not be null", classPCCText);
    reconstClass = null;
    System.out.println("Got text:" + classPCCText);
    reconstClass = parsePCClassText(classPCCText, source);
    assertEquals("getPCCText should be the same after being encoded and reloaded", classPCCText, reconstClass.getPCCText());
    assertEquals("Class abbrev was not restored after saving and reloading.", humanoidClass.getAbbrev(), reconstClass.getAbbrev());
    Collection<CDOMReference<Spell>> startSpells = humanoidClass.getOriginalClassLevel(1).getListMods(Spell.SPELLS);
    Collection<CDOMReference<Spell>> reconstSpells = reconstClass.getOriginalClassLevel(1).getListMods(Spell.SPELLS);
    assertEquals("All spell should have been reconstituted.", startSpells.size(), reconstSpells.size());
    assertEquals("Spell names should been preserved.", startSpells, reconstSpells);
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) PCClassLoader(pcgen.persistence.lst.PCClassLoader) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI) CDOMReference(pcgen.cdom.base.CDOMReference) StringManager(pcgen.base.format.StringManager)

Example 12 with CampaignSourceEntry

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

the class ChallengeRatingPathfinderTest method additionalSetUp.

@Override
protected void additionalSetUp() throws Exception {
    SettingsHandler.getGame().setCRSteps("1/2|1/3|1/4|1/6|1/8");
    SettingsHandler.getGame().setCRThreshold("BASECR");
    SettingsHandler.getGame().setMonsterRoleList(new ArrayList<>(Arrays.asList("Combat", "Skill", "Druid")));
    SettingsHandler.getGame().addClassType("PC			CRFORMULA:CL	ISMONSTER:NO	CRMOD:-1	CRMODPRIORITY:1");
    SettingsHandler.getGame().addClassType("NPC			CRFORMULA:CL	ISMONSTER:NO	CRMOD:-2	CRMODPRIORITY:2");
    SettingsHandler.getGame().addClassType("Monster		CRFORMULA:0		ISMONSTER:YES");
    SettingsHandler.getGame().addClassType("Companion	CRFORMULA:NONE	ISMONSTER:YES");
    LoadContext context = Globals.getContext();
    BuildUtilities.createFact(context, "ClassType", PCClass.class);
    SourceFileLoader.processFactDefinitions(context);
    CampaignSourceEntry source = TestHelper.createSource(getClass());
    GenericLoader<Race> raceLoader = new GenericLoader<>(Race.class);
    PCClassLoader classLoader = new PCClassLoader();
    final String standardRaceLine = "Standard Race";
    raceLoader.parseLine(context, null, standardRaceLine, source);
    standardRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Standard Race");
    final String koboldRaceLine = "Kobold	CRMOD:NPC|-3";
    raceLoader.parseLine(context, null, koboldRaceLine, source);
    koboldRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Kobold");
    final String drowNobleLine = "Drow Noble	CRMOD:PC.NPC|0";
    raceLoader.parseLine(context, null, drowNobleLine, source);
    drowNobleRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Drow Noble");
    final String babauLine = "Babau	MONSTERCLASS:TestMonsterClass:7	CR:6	ROLE:Combat.Skill";
    raceLoader.parseLine(context, null, babauLine, source);
    babauRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Babau");
    final String dryadLine = "Dryad	MONSTERCLASS:TestMonsterClass:8	CR:7	ROLE:Druid";
    raceLoader.parseLine(context, null, dryadLine, source);
    dryadRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Dryad");
    final String companionLine = "TestCompanion MONSTERCLASS:TestCompanionClass:4";
    raceLoader.parseLine(context, null, companionLine, source);
    companionRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "TestCompanion");
    final String zombieLine = "Zombie	MONSTERCLASS:TestMonsterClass:1	CR:1/2	ROLE:Combat";
    raceLoader.parseLine(context, null, zombieLine, source);
    zombieRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Zombie");
    final String direRatLine = "Dire Rat	MONSTERCLASS:TestMonsterClass:1	CR:1/3	ROLE:Combat";
    raceLoader.parseLine(context, null, direRatLine, source);
    direRatRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Dire rat");
    final String miteLine = "Mite	MONSTERCLASS:TestMonsterClass:1	CR:1/4	ROLE:Combat";
    raceLoader.parseLine(context, null, miteLine, source);
    miteRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Mite");
    final String beetleLine = "Beetle	MONSTERCLASS:TestMonsterClass:1	CR:1/6	ROLE:Combat";
    raceLoader.parseLine(context, null, beetleLine, source);
    beetleRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Beetle");
    final String centipedeLine = "Centipede	MONSTERCLASS:TestMonsterClass:1	CR:1/8	Centipede";
    raceLoader.parseLine(context, null, centipedeLine, source);
    centipedeRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Centipede");
    final String pcClassLine = "CLASS:TestPCClass	TYPE:PC		ROLE:Combat";
    pcClass = classLoader.parseLine(context, null, pcClassLine, source);
    context.getReferenceContext().importObject(pcClass);
    final String pcClassLine2 = "CLASS:TestPCClass2	TYPE:PC		ROLE:Druid";
    pcClass2 = classLoader.parseLine(context, null, pcClassLine2, source);
    context.getReferenceContext().importObject(pcClass2);
    final String npcClassLine = "CLASS:TestNPCClass2	TYPE:NPC";
    npcClass = classLoader.parseLine(context, null, npcClassLine, source);
    context.getReferenceContext().importObject(npcClass);
    final String npcClassLine2 = "CLASS:TestNPCClass2	TYPE:NPC";
    npcClass2 = classLoader.parseLine(context, null, npcClassLine2, source);
    context.getReferenceContext().importObject(npcClass2);
    final String monsterClassLine = "CLASS:TestMonsterClass	HD:8	CLASSTYPE:Monster";
    monsterClass = classLoader.parseLine(context, null, monsterClassLine, source);
    context.getReferenceContext().importObject(monsterClass);
    final String companionClassLine = "CLASS:TestCompanionClass	HD:8	CLASSTYPE:Companion";
    companionClass = classLoader.parseLine(context, null, companionClassLine, source);
    context.getReferenceContext().importObject(companionClass);
    context.commit();
    BuildUtilities.createFact(context, "ClassType", PCClass.class);
    FactDefinition<?, String> fd = BuildUtilities.createFact(context, "SpellType", PCClass.class);
    fd.setSelectable(true);
    SourceFileLoader.processFactDefinitions(context);
    context.getReferenceContext().buildDerivedObjects();
    context.resolveDeferredTokens();
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) LoadContext(pcgen.rules.context.LoadContext) GenericLoader(pcgen.persistence.lst.GenericLoader) PCClassLoader(pcgen.persistence.lst.PCClassLoader)

Example 13 with CampaignSourceEntry

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

the class RequiredTokenTest method classSetUp.

@BeforeClass
public static void classSetUp() throws URISyntaxException {
    testCampaign = new CampaignSourceEntry(new Campaign(), new URI("file:/Test%20Case"));
    classSetUpFired = true;
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Campaign(pcgen.core.Campaign) URI(java.net.URI) BeforeClass(org.junit.BeforeClass)

Example 14 with CampaignSourceEntry

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

the class ValueTokenTest method classSetUp.

@BeforeClass
public static void classSetUp() throws URISyntaxException {
    testCampaign = new CampaignSourceEntry(new Campaign(), new URI("file:/Test%20Case"));
    classSetUpFired = true;
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Campaign(pcgen.core.Campaign) URI(java.net.URI) BeforeClass(org.junit.BeforeClass)

Example 15 with CampaignSourceEntry

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

the class VisibleTokenTest method classSetUp.

@BeforeClass
public static void classSetUp() throws URISyntaxException {
    testCampaign = new CampaignSourceEntry(new Campaign(), new URI("file:/Test%20Case"));
    classSetUpFired = true;
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Campaign(pcgen.core.Campaign) URI(java.net.URI) BeforeClass(org.junit.BeforeClass)

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