use of pcgen.core.ChronicleEntry in project pcgen by PCGen.
the class PCGVer2Parser method parseChronicleEntryLine.
/*
* ###############################################################
* Character Chronicle Entry methods
* ###############################################################
*/
private void parseChronicleEntryLine(final String line) {
final PCGTokenizer tokens;
try {
tokens = new PCGTokenizer(line);
} catch (PCGParseException pcgpex) {
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.IllegalChronicleEntry", line, pcgpex.getMessage());
warnings.add(msg);
return;
}
final ChronicleEntry ce = new ChronicleEntry();
for (PCGElement element : tokens.getElements()) {
final String tag = element.getName();
if (IOConstants.TAG_CHRONICLE_ENTRY.equals(tag)) {
ce.setOutputEntry("Y".equals(element.getText()));
} else if (IOConstants.TAG_EXPERIENCE.equals(tag)) {
try {
ce.setXpField(Integer.parseInt(element.getText()));
} catch (NumberFormatException nfe) {
ce.setXpField(0);
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.InvalidChronicleEntry", line);
warnings.add(msg);
break;
}
} else if (IOConstants.TAG_CAMPAIGN.equals(tag)) {
ce.setCampaign(EntityEncoder.decode(element.getText()));
} else if (IOConstants.TAG_ADVENTURE.equals(tag)) {
ce.setAdventure(EntityEncoder.decode(element.getText()));
} else if (IOConstants.TAG_PARTY.equals(tag)) {
ce.setParty(EntityEncoder.decode(element.getText()));
} else if (IOConstants.TAG_DATE.equals(tag)) {
ce.setDate(EntityEncoder.decode(element.getText()));
} else if (IOConstants.TAG_GM.equals(tag)) {
ce.setGmField(EntityEncoder.decode(element.getText()));
} else if (IOConstants.TAG_CHRONICLE.equals(tag)) {
ce.setChronicle(EntityEncoder.decode(element.getText()));
}
}
thePC.addChronicleEntry(ce);
}
use of pcgen.core.ChronicleEntry in project pcgen by PCGen.
the class CountCommandTest method testCountCampaignHistory.
/**
* Verify counting CAMPAIGNHISTORY entries.
*/
public void testCountCampaignHistory() {
final PlayerCharacter character = getCharacter();
String countDefault = "count(\"CAMPAIGNHISTORY\")";
String countVisible = "count(\"CAMPAIGNHISTORY\",\"EXPORT=YES\")";
String countHidden = "count(\"CAMPAIGNHISTORY\",\"EXPORT=NO\")";
String countAll = "count(\"CAMPAIGNHISTORY\",\"EXPORT=NO[or]EXPORT=YES\")";
// No entries yet
is(character.getVariableValue(countDefault, ""), eq(0.0, 0.1), countDefault + " no choices");
is(character.getVariableValue(countVisible, ""), eq(0.0, 0.1), countVisible + " no choices");
is(character.getVariableValue(countHidden, ""), eq(0.0, 0.1), countHidden + " no choices");
is(character.getVariableValue(countAll, ""), eq(0.0, 0.1), countAll + " no choices");
ChronicleEntry hiddenEntry = TestHelper.buildChronicleEntry(false, "Campaign", "Date", "GM", "Party", "Adventure", 1390, "Chronicle");
character.addChronicleEntry(hiddenEntry);
character.setDirty(true);
is(character.getVariableValue(countDefault, ""), eq(0.0, 0.1), countDefault + " one hidden");
is(character.getVariableValue(countVisible, ""), eq(0.0, 0.1), countVisible + " one hidden");
is(character.getVariableValue(countHidden, ""), eq(1.0, 0.1), countHidden + " one hidden");
is(character.getVariableValue(countAll, ""), eq(1.0, 0.1), countAll + " one hidden");
ChronicleEntry visibleEntry = TestHelper.buildChronicleEntry(true, "Campaign", "Date2", "GM", "Party", "Adventure2", 1390, "Chronicle2");
character.addChronicleEntry(visibleEntry);
character.setDirty(true);
is(character.getVariableValue(countDefault, ""), eq(1.0, 0.1), countDefault + " one hidden, one visible");
is(character.getVariableValue(countVisible, ""), eq(1.0, 0.1), countVisible + " one hidden, one visible");
is(character.getVariableValue(countHidden, ""), eq(1.0, 0.1), countHidden + " one hidden, one visible");
is(character.getVariableValue(countAll, ""), eq(2.0, 0.1), countAll + " one hidden, one visible");
ChronicleEntry thirdEntry = TestHelper.buildChronicleEntry(true, "Campaign", "Date3", "GM", "Party", "Adventure3", 1390, "Chronicle2");
character.addChronicleEntry(thirdEntry);
character.setDirty(true);
is(character.getVariableValue(countDefault, ""), eq(2.0, 0.1), countDefault + " one hidden, two visible");
is(character.getVariableValue(countVisible, ""), eq(2.0, 0.1), countVisible + " one hidden, two visible");
is(character.getVariableValue(countHidden, ""), eq(1.0, 0.1), countHidden + " one hidden, two visible");
is(character.getVariableValue(countAll, ""), eq(3.0, 0.1), countAll + " one hidden, two visible");
}
use of pcgen.core.ChronicleEntry in project pcgen by PCGen.
the class CampaignHistoryToken method getTargetChronicleEntry.
private ChronicleEntry getTargetChronicleEntry(int targetIndex, Visibility visibility, CharacterDisplay display) {
Collection<ChronicleEntry> entries = display.getChronicleEntries();
int i = 0;
for (ChronicleEntry chronicleEntry : entries) {
if ((chronicleEntry.isOutputEntry() && visibility == Visibility.HIDDEN) || (!chronicleEntry.isOutputEntry() && visibility == Visibility.VISIBLE)) {
continue;
}
if (i == targetIndex) {
return chronicleEntry;
}
i++;
}
return null;
}
use of pcgen.core.ChronicleEntry in project pcgen by PCGen.
the class ChronicleEntryFacetTest method testAddSingleTwiceRemove.
@Override
public void testAddSingleTwiceRemove() {
ChronicleEntry t1 = getObject();
getFacet().add(id, t1);
assertEquals(1, getFacet().getCount(id));
assertFalse(getFacet().isEmpty(id));
assertNotNull(getFacet().getSet(id));
assertEquals(1, getFacet().getSet(id).size());
assertEquals(t1, getFacet().getSet(id).iterator().next());
assertEventCount(1, 0);
// Add same, now twice in list
getFacet().add(id, t1);
assertEquals(2, getFacet().getCount(id));
assertFalse(getFacet().isEmpty(id));
assertNotNull(getFacet().getSet(id));
assertEquals(2, getFacet().getSet(id).size());
assertEquals(t1, getFacet().getSet(id).iterator().next());
assertEventCount(2, 0);
// Only requires one Remove (internally a Set, not List)
getFacet().remove(id, t1);
assertEquals(1, getFacet().getCount(id));
assertFalse(getFacet().isEmpty(id));
assertNotNull(getFacet().getSet(id));
assertEquals(1, getFacet().getSet(id).size());
assertEquals(t1, getFacet().getSet(id).iterator().next());
assertEventCount(2, 1);
// Second has no effect
getFacet().remove(id, t1);
testListUnsetZeroCount();
testListUnsetEmpty();
testListUnsetEmptySet();
assertEventCount(2, 2);
}
use of pcgen.core.ChronicleEntry in project pcgen by PCGen.
the class ChronicleEntryFacetTest method getObject.
@Override
protected ChronicleEntry getObject() {
ChronicleEntry ce = new ChronicleEntry();
ce.setChronicle("Chr: " + n++);
return ce;
}
Aggregations