use of pcgen.cdom.base.ConcreteTransitionChoice in project pcgen by PCGen.
the class RegionLst method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
}
if (obj instanceof NonInteractive) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Non-Interactive object type: " + obj.getClass().getSimpleName(), context);
}
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
String item = tok.nextToken();
Formula count = FormulaFactory.getFormulaFor(item);
if (!count.isValid()) {
return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
}
if (count.isStatic()) {
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail(getTokenName() + " cannot have only a count: " + value, context);
}
item = tok.nextToken();
if (count.resolveStatic().intValue() <= 0) {
return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0: " + value, context);
}
} else {
count = FormulaFactory.ONE;
}
List<Region> regions = new ArrayList<>();
while (true) {
regions.add(Region.getConstant(item));
if (!tok.hasMoreTokens()) {
break;
}
item = tok.nextToken();
}
SimpleChoiceSet<Region> rcs = new SimpleChoiceSet<>(regions);
ChoiceSet<Region> cs = new ChoiceSet<>(getTokenName(), rcs);
cs.setTitle("Region Selection");
TransitionChoice<Region> tc = new ConcreteTransitionChoice<>(cs, count);
context.getObjectContext().put(obj, ObjectKey.REGION_CHOICE, tc);
tc.setRequired(false);
tc.setChoiceActor(this);
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.ConcreteTransitionChoice in project pcgen by PCGen.
the class ModifyfeatchoiceToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Ability ability, String value) {
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
List<CDOMReference<Ability>> refs = new ArrayList<>();
ReferenceManufacturer<Ability> rm = context.getReferenceContext().getManufacturer(ABILITY_CLASS, AbilityCategory.FEAT);
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
CDOMReference<Ability> ref = TokenUtilities.getTypeOrPrimitive(rm, token);
if (ref == null) {
return ParseResult.INTERNAL_ERROR;
}
refs.add(ref);
}
ReferenceChoiceSet<Ability> rcs = new ReferenceChoiceSet<>(refs);
ModifyChoiceDecorator gfd = new ModifyChoiceDecorator(rcs);
ChoiceSet<CNAbility> cs = new ChoiceSet<>(getTokenName(), gfd);
TabInfo ti = context.getReferenceContext().silentlyGetConstructedCDOMObject(TabInfo.class, Tab.ABILITIES.toString());
String singularName = ti.getResolvedName();
if (singularName.endsWith("s")) {
singularName = singularName.substring(0, singularName.length() - 1);
}
cs.setTitle("Select a " + singularName + " to modify");
TransitionChoice<CNAbility> tc = new ConcreteTransitionChoice<>(cs, FormulaFactory.ONE);
tc.setRequired(false);
context.getObjectContext().put(ability, ObjectKey.MODIFY_CHOICE, tc);
tc.setChoiceActor(this);
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.ConcreteTransitionChoice in project pcgen by PCGen.
the class SkilllistToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
Formula count = FormulaFactory.getFormulaFor(tok.nextToken());
if (!count.isValid()) {
return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
}
if (!count.isStatic() || count.resolveStatic().intValue() <= 0) {
return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0", context);
}
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail(getTokenName() + " must have a | separating " + "count from the list of possible values: " + value, context);
}
List<CDOMReference<ClassSkillList>> refs = new ArrayList<>();
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
CDOMReference<ClassSkillList> ref;
if (Constants.LST_ALL.equals(token)) {
ref = context.getReferenceContext().getCDOMAllReference(SKILLLIST_CLASS);
} else {
ref = context.getReferenceContext().getCDOMReference(SKILLLIST_CLASS, token);
}
refs.add(ref);
}
ReferenceChoiceSet<ClassSkillList> rcs = new ReferenceChoiceSet<>(refs);
if (!rcs.getGroupingState().isValid()) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value);
}
ChoiceSet<ClassSkillList> cs = new ChoiceSet<>(getTokenName(), rcs);
cs.setTitle("Select class whose class-skills this class will inherit");
TransitionChoice<ClassSkillList> tc = new ConcreteTransitionChoice<>(cs, count);
context.getObjectContext().put(pcc, ObjectKey.SKILLLIST_CHOICE, tc);
tc.setRequired(false);
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.ConcreteTransitionChoice in project pcgen by PCGen.
the class SpelllistToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
Formula count = FormulaFactory.getFormulaFor(tok.nextToken());
if (!count.isValid()) {
return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
}
if (!count.isStatic() || count.resolveStatic().intValue() <= 0) {
return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0", context);
}
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail(getTokenName() + " must have a | separating " + "count from the list of possible values: " + value, context);
}
List<CDOMReference<? extends CDOMListObject<Spell>>> refs = new ArrayList<>();
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
CDOMReference<? extends CDOMListObject<Spell>> ref;
if (Constants.LST_ALL.equals(token)) {
ref = context.getReferenceContext().getCDOMAllReference(SPELLLIST_CLASS);
} else if (token.startsWith("DOMAIN.")) {
ref = context.getReferenceContext().getCDOMReference(DOMAINSPELLLIST_CLASS, token.substring(7));
} else {
ref = context.getReferenceContext().getCDOMReference(SPELLLIST_CLASS, token);
}
refs.add(ref);
}
PrimitiveChoiceSet<CDOMListObject<Spell>> rcs = new SpellReferenceChoiceSet(refs);
if (!rcs.getGroupingState().isValid()) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
}
ChoiceSet<? extends CDOMListObject<Spell>> cs = new ChoiceSet<>(getTokenName(), rcs);
cs.setTitle("Select class whose list of spells this class will use");
TransitionChoice<CDOMListObject<Spell>> tc = new ConcreteTransitionChoice<>(cs, count);
context.getObjectContext().put(pcc, ObjectKey.SPELLLIST_CHOICE, tc);
tc.setRequired(false);
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.ConcreteTransitionChoice in project pcgen by PCGen.
the class KitLst method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
}
if (obj instanceof NonInteractive) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Non-Interactive object type: " + obj.getClass().getSimpleName(), context);
}
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
Formula count = FormulaFactory.getFormulaFor(tok.nextToken());
if (!count.isValid()) {
return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
}
if (!count.isStatic()) {
return new ParseResult.Fail("Count in " + getTokenName() + " must be a number", context);
}
if (count.resolveStatic().intValue() <= 0) {
return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0", context);
}
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail(getTokenName() + " must have a | separating " + "count from the list of possible values: " + value, context);
}
List<CDOMReference<Kit>> refs = new ArrayList<>();
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
CDOMReference<Kit> ref;
if (Constants.LST_ALL.equals(token)) {
ref = context.getReferenceContext().getCDOMAllReference(KIT_CLASS);
} else {
ref = context.getReferenceContext().getCDOMReference(KIT_CLASS, token);
}
refs.add(ref);
}
ReferenceChoiceSet<Kit> rcs = new ReferenceChoiceSet<>(refs);
if (!rcs.getGroupingState().isValid()) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
}
ChoiceSet<Kit> cs = new ChoiceSet<>(getTokenName(), new QualifiedDecorator<>(rcs));
cs.setTitle("Kit Selection");
TransitionChoice<Kit> tc = new ConcreteTransitionChoice<>(cs, count);
context.getObjectContext().addToList(obj, ListKey.KIT_CHOICE, tc);
tc.setRequired(false);
tc.setChoiceActor(this);
return ParseResult.SUCCESS;
}
Aggregations