use of pcgen.rules.context.AbstractObjectContext in project pcgen by PCGen.
the class FactSetParser method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, T obj, String value) {
FormatManager<F> fmtManager = def.getFormatManager();
FactSetKey<F> fsk = def.getFactSetKey();
StringTokenizer st = new StringTokenizer(value, Constants.PIPE);
boolean firstToken = true;
AbstractObjectContext objContext = context.getObjectContext();
while (st.hasMoreTokens()) {
String token = st.nextToken();
if (Constants.LST_DOT_CLEAR_ALL.equals(token)) {
if (!firstToken) {
return new ParseResult.Fail("Non-sensical situation was " + "encountered while parsing " + getParentToken() + Constants.PIPE + getTokenName() + ": When used, .CLEARALL must be the first argument", context);
}
objContext.removeSet(obj, fsk);
}
Indirect<F> indirect = fmtManager.convertIndirect(token);
objContext.addToSet(obj, fsk, indirect);
}
return ParseResult.SUCCESS;
}
use of pcgen.rules.context.AbstractObjectContext in project pcgen by PCGen.
the class EqmodToken method unparse.
@Override
public String[] unparse(LoadContext context, Equipment eq) {
AbstractObjectContext obj = context.getObjectContext();
String damage = obj.getString(eq, StringKey.DAMAGE_OVERRIDE);
Set<String> set = new TreeSet<>();
if (damage != null) {
set.add(EQMOD_DAMAGE + Constants.PIPE + damage);
}
BigDecimal weight = obj.getObject(eq, ObjectKey.WEIGHT_MOD);
if (weight != null) {
set.add(EQMOD_WEIGHT + Constants.PIPE + weight.toString().replace('.', ','));
}
EquipmentHead head = eq.getEquipmentHeadReference(1);
if (head != null) {
Changes<EqModRef> changes = obj.getListChanges(head, ListKey.EQMOD_INFO);
Collection<EqModRef> added = changes.getAdded();
if (added != null) {
for (EqModRef modRef : added) {
String key = modRef.getRef().getLSTformat(false);
StringBuilder sb = new StringBuilder();
sb.append(key);
for (String s : modRef.getChoices()) {
sb.append(Constants.PIPE);
sb.append(s.replace('|', '='));
}
set.add(sb.toString());
}
}
}
if (set.isEmpty()) {
return null;
}
return new String[] { StringUtil.join(set, Constants.DOT) };
}
use of pcgen.rules.context.AbstractObjectContext in project pcgen by PCGen.
the class AlteqmodToken method unparse.
@Override
public String[] unparse(LoadContext context, Equipment eq) {
AbstractObjectContext obj = context.getObjectContext();
String damage = obj.getString(eq, StringKey.DAMAGE_OVERRIDE);
Set<String> set = new TreeSet<>();
if (damage != null) {
set.add(EQMOD_DAMAGE + Constants.PIPE + damage);
}
BigDecimal weight = obj.getObject(eq, ObjectKey.WEIGHT_MOD);
if (weight != null) {
set.add(EQMOD_WEIGHT + Constants.PIPE + weight.toString().replace('.', ','));
}
EquipmentHead head = eq.getEquipmentHeadReference(2);
if (head != null) {
Changes<EqModRef> changes = obj.getListChanges(head, ListKey.EQMOD_INFO);
Collection<EqModRef> added = changes.getAdded();
if (added != null) {
for (EqModRef modRef : added) {
String key = modRef.getRef().getLSTformat(false);
StringBuilder sb = new StringBuilder();
sb.append(key);
for (String s : modRef.getChoices()) {
sb.append(Constants.PIPE);
sb.append(s.replace('|', '='));
}
set.add(sb.toString());
}
}
}
if (set.isEmpty()) {
return null;
}
return new String[] { StringUtil.join(set, Constants.DOT) };
}
Aggregations