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