use of pcgen.cdom.base.NonInteractive 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.NonInteractive in project pcgen by PCGen.
the class AddLst method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(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);
}
int pipeLoc = value.indexOf(Constants.PIPE);
if (pipeLoc == -1) {
if (Constants.LST_DOT_CLEAR.equals(value)) {
if (obj instanceof PCClassLevel) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Warning: You performed an invalid " + ".CLEAR in a ADD: Token");
cpr.addErrorMessage(" A non-level limited .CLEAR was " + "used in a Class Level line in " + obj.getKeyName());
return cpr;
}
} else if (value.startsWith(".CLEAR.LEVEL")) {
if (!(obj instanceof PCClassLevel)) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Warning: You performed an invalid .CLEAR in a ADD: Token");
cpr.addErrorMessage(" A level limited .CLEAR ( " + value + " ) was not used in a Class Level line in " + obj.getClass().getSimpleName() + ' ' + obj.getKeyName());
return cpr;
}
String levelString = value.substring(12);
try {
int level = Integer.parseInt(levelString);
if (level != obj.get(IntegerKey.LEVEL)) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Warning: You performed an invalid " + ".CLEAR in a ADD: Token");
cpr.addErrorMessage(" A level limited .CLEAR ( " + value + " ) was used in a Class Level line");
cpr.addErrorMessage(" But was asked to clear a " + "different Class Level ( " + level + " ) than the Class Level Line it appeared on: " + obj.getKeyName());
return cpr;
}
} catch (NumberFormatException e) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Warning: You performed an invalid .CLEAR in a ADD: Token");
cpr.addErrorMessage(" A level limited .CLEAR ( " + value + " ) was used in a Class Level line");
cpr.addErrorMessage(" But the level ( " + levelString + " ) was not an integer in: " + obj.getKeyName());
return cpr;
}
} else {
return new ParseResult.Fail(getTokenName() + " requires a SubToken and argument, found: " + value, context);
}
context.getObjectContext().removeList(obj, ListKey.ADD);
return ParseResult.SUCCESS;
}
return context.processSubToken(obj, getTokenName(), value.substring(0, pipeLoc), value.substring(pipeLoc + 1));
}
use of pcgen.cdom.base.NonInteractive in project pcgen by PCGen.
the class ChooseLst method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(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);
}
String key;
String val;
int pipeLoc = value.indexOf(Constants.PIPE);
if (value.startsWith("FEAT=")) {
key = "FEATEQ";
val = value.substring(5);
} else if (value.startsWith("LANGAUTO:")) {
key = "LANGAUTO";
val = value.substring(9);
} else if (pipeLoc == -1) {
key = value;
val = null;
} else {
key = value.substring(0, pipeLoc);
val = value.substring(pipeLoc + 1);
}
if (!((obj instanceof Ability) || (obj instanceof Domain) || (obj instanceof Race) || (obj instanceof PCTemplate) || (obj instanceof Skill) || (obj instanceof EquipmentModifier))) {
//Allow TEMPBONUS related choose
if (!"NUMBER".equals(key)) {
return new ParseResult.Fail(getTokenName() + " is not supported for " + obj.getClass().getSimpleName(), context);
}
}
if (key.startsWith("NUMCHOICES=")) {
String maxCount = key.substring(11);
if (maxCount == null || maxCount.isEmpty()) {
return new ParseResult.Fail("NUMCHOICES in CHOOSE must be a formula: " + value, context);
}
Formula f = FormulaFactory.getFormulaFor(maxCount);
if (!f.isValid()) {
return new ParseResult.Fail("Number of Choices in " + getTokenName() + " was not valid: " + f.toString(), context);
}
context.getObjectContext().put(obj, FormulaKey.NUMCHOICES, f);
pipeLoc = val.indexOf(Constants.PIPE);
if (pipeLoc == -1) {
key = val;
val = null;
} else {
key = val.substring(0, pipeLoc);
val = val.substring(pipeLoc + 1);
}
}
return context.processSubToken(obj, getTokenName(), key, val);
}
use of pcgen.cdom.base.NonInteractive 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