Search in sources :

Example 1 with AbstractObjectContext

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) AbstractObjectContext(pcgen.rules.context.AbstractObjectContext)

Example 2 with AbstractObjectContext

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) };
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) AbstractObjectContext(pcgen.rules.context.AbstractObjectContext) TreeSet(java.util.TreeSet) EqModRef(pcgen.cdom.helper.EqModRef) BigDecimal(java.math.BigDecimal)

Example 3 with AbstractObjectContext

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) };
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) AbstractObjectContext(pcgen.rules.context.AbstractObjectContext) TreeSet(java.util.TreeSet) EqModRef(pcgen.cdom.helper.EqModRef) BigDecimal(java.math.BigDecimal)

Aggregations

AbstractObjectContext (pcgen.rules.context.AbstractObjectContext)3 BigDecimal (java.math.BigDecimal)2 TreeSet (java.util.TreeSet)2 EqModRef (pcgen.cdom.helper.EqModRef)2 EquipmentHead (pcgen.cdom.inst.EquipmentHead)2 StringTokenizer (java.util.StringTokenizer)1