Search in sources :

Example 1 with StringManager

use of pcgen.base.format.StringManager in project pcgen by PCGen.

the class FreeMarkerTest method createChecks.

private void createChecks() {
    StringManager sm = new StringManager();
    FactKey<String> sn = FactKey.getConstant("ShortName", sm);
    PCCheck pcc = new PCCheck();
    pcc.setName("Willpower");
    pcc.put(sn, new BasicIndirect<>(sm, "Will"));
    cf.add(id, pcc);
    pcc = new PCCheck();
    pcc.setName("Reflex");
    pcc.put(sn, new BasicIndirect<>(sm, "Ref"));
    cf.add(id, pcc);
    pcc = new PCCheck();
    pcc.setName("Fortitude");
    pcc.put(sn, new BasicIndirect<>(sm, "Fort"));
    cf.add(id, pcc);
    FactKeyActor<?> fka = new FactKeyActor<>(sn);
    CDOMObjectWrapper.load(dsid, pcc.getClass(), "shortname", fka);
}
Also used : FactKeyActor(pcgen.output.actor.FactKeyActor) PCCheck(pcgen.core.PCCheck) StringManager(pcgen.base.format.StringManager)

Example 2 with StringManager

use of pcgen.base.format.StringManager 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 3 with StringManager

use of pcgen.base.format.StringManager in project pcgen by PCGen.

the class BuildUtilities method createFactSet.

/**
	 * Define a new FACTSET to hold a set of strings for a type of object. 
	 * @param context The context in which the data is being loaded 
	 * @param factsetname The name of the new FACTSET
	 * @param cls The object type the set will apply to.
	 * @return The full definition, already loaded into the context. 
	 */
public static FactSetDefinition<?, String> createFactSet(LoadContext context, String factsetname, Class<? extends Loadable> cls) {
    FactSetDefinition<?, String> fd = new FactSetDefinition<>();
    fd.setUsableLocation(cls);
    fd.setName("*" + factsetname);
    fd.setFactSetName(factsetname);
    fd.setFormatManager(new StringManager());
    context.getReferenceContext().importObject(fd);
    return fd;
}
Also used : FactSetDefinition(pcgen.cdom.content.factset.FactSetDefinition) StringManager(pcgen.base.format.StringManager)

Example 4 with StringManager

use of pcgen.base.format.StringManager in project pcgen by PCGen.

the class LoadContextTest method testCloneInMasterListsAssoc.

/**
	 * Test method for {@link pcgen.rules.context.LoadContext#cloneInMasterLists(pcgen.cdom.base.CDOMObject, java.lang.String)}.
	 * Verify that associations from other objects to the object being cloned 
	 * are copied over. 
	 */
public final void testCloneInMasterListsAssoc() {
    final LoadContext context = Globals.getContext();
    FactKey.getConstant("ClassType", new StringManager());
    FactKey.getConstant("SpellType", new StringManager());
    Spell testSpell = TestHelper.makeSpell("LoadContextTest");
    PCClass wiz = TestHelper.makeClass("Wizard");
    CDOMReference<ClassSpellList> ref = TokenUtilities.getTypeOrPrimitive(context, ClassSpellList.class, wiz.getKeyName());
    AssociatedPrereqObject edge = context.getListContext().addToMasterList("CLASSES", testSpell, ref, testSpell);
    edge.setAssociation(AssociationKey.SPELL_LEVEL, 1);
    context.getReferenceContext().buildDerivedObjects();
    assertTrue(context.getReferenceContext().resolveReferences(null));
    context.commit();
    Spell newSpell = context.performCopy(testSpell, "New Spell");
    context.commit();
    assertEquals("Old spell name incorrect", "LoadContextTest", testSpell.getDisplayName());
    assertEquals("New spell name incorrect", "New Spell", newSpell.getDisplayName());
    // Check associations
    MasterListInterface masterLists = SettingsHandler.getGame().getMasterLists();
    Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(ref, testSpell);
    assertEquals("Incorrect size of assoc list for orig spell", 1, assoc.size());
    AssociatedPrereqObject apo = assoc.iterator().next();
    assertEquals("Incorrect level", 1, apo.getAssociation(AssociationKey.SPELL_LEVEL).intValue());
    assoc = masterLists.getAssociations(ref, newSpell);
    assertEquals("Incorrect size of assoc list for new spell", 1, assoc.size());
    apo = assoc.iterator().next();
    assertEquals("Incorrect level", 1, apo.getAssociation(AssociationKey.SPELL_LEVEL).intValue());
}
Also used : MasterListInterface(pcgen.cdom.base.MasterListInterface) ClassSpellList(pcgen.cdom.list.ClassSpellList) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell) StringManager(pcgen.base.format.StringManager) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 5 with StringManager

use of pcgen.base.format.StringManager in project pcgen by PCGen.

the class TableLoaderTest method testBasic.

//TODO Blank Data in middle of Row?
//TODO Blank Data at end of row?
@Test
public void testBasic() {
    try {
        loader.loadLstString(context, uri, "#Let me tell you about this table\n\n,,,\n" + "STARTTABLE:A\n\n,,,\n" + "#It's the story of a parsing test\n" + "Name,Value,\n\n,,,\n" + "\"#And testing tolerance\",For lots of things\n" + "STRING,NUMBER,,\n\n,,,\n\n" + "#Because really....\n" + "This,1\n\n" + "#Why call the comments?\n,,,\n" + "\"That\",\"2\"\n" + "\"The \"\"Other\"\"\",\"3\"\n,,,\n\n" + "ENDTABLE:A\n" + "#They seem to just take up a lot of space");
        DataTable a = context.getReferenceContext().silentlyGetConstructedCDOMObject(DataTable.class, "A");
        assertEquals(2, a.getColumnCount());
        assertEquals(new StringManager(), a.getFormat(0));
        assertEquals(new NumberManager(), a.getFormat(1));
        assertEquals("This", a.get("Name", 0));
        assertEquals("That", a.get("Name", 1));
        assertEquals("The \"Other\"", a.get("Name", 2));
        assertEquals(1, a.get("Value", 0));
        assertEquals(2, a.get("Value", 1));
        assertEquals(3, a.get("Value", 2));
        assertEquals(2, a.lookupExact("That", "Value"));
    } catch (PersistenceLayerException e) {
        fail("Did not Expect Failure: " + e.getLocalizedMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) DataTable(pcgen.cdom.format.table.DataTable) NumberManager(pcgen.base.format.NumberManager) StringManager(pcgen.base.format.StringManager) Test(org.junit.Test)

Aggregations

StringManager (pcgen.base.format.StringManager)14 Test (org.junit.Test)3 NumberManager (pcgen.base.format.NumberManager)3 DataTable (pcgen.cdom.format.table.DataTable)3 Deity (pcgen.core.Deity)3 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 UnreachableError (pcgen.base.lang.UnreachableError)2 FactDefinition (pcgen.cdom.content.fact.FactDefinition)2 FactSetDefinition (pcgen.cdom.content.factset.FactSetDefinition)2 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)2 PCClassLoader (pcgen.persistence.lst.PCClassLoader)2 OrderedPairManager (pcgen.base.format.OrderedPairManager)1 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 MasterListInterface (pcgen.cdom.base.MasterListInterface)1 ChallengeRating (pcgen.cdom.content.ChallengeRating)1 ClassSpellList (pcgen.cdom.list.ClassSpellList)1 PCCheck (pcgen.core.PCCheck)1