Search in sources :

Example 1 with DomainList

use of pcgen.cdom.list.DomainList in project pcgen by PCGen.

the class DomainsToken method unparse.

@Override
public String[] unparse(LoadContext context, Deity deity) {
    CDOMReference<DomainList> dl = Deity.DOMAINLIST;
    AssociatedChanges<CDOMReference<Domain>> changes = context.getListContext().getChangesInList(getTokenName(), deity, dl);
    List<String> list = new ArrayList<>();
    Collection<CDOMReference<Domain>> removedItems = changes.getRemoved();
    if (changes.includesGlobalClear()) {
        if (removedItems != null && !removedItems.isEmpty()) {
            context.addWriteMessage("Non-sensical relationship in " + getTokenName() + ": global .CLEAR and local .CLEAR. performed");
            return null;
        }
        list.add(Constants.LST_DOT_CLEAR);
    } else if (removedItems != null && !removedItems.isEmpty()) {
        list.add(Constants.LST_DOT_CLEAR_DOT + ReferenceUtilities.joinLstFormat(removedItems, ",.CLEAR.", true));
    }
    MapToList<CDOMReference<Domain>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
    if (mtl != null && !mtl.isEmpty()) {
        MapToList<Set<Prerequisite>, CDOMReference<Domain>> m = new HashMapToList<>();
        for (CDOMReference<Domain> ab : mtl.getKeySet()) {
            for (AssociatedPrereqObject assoc : mtl.getListFor(ab)) {
                m.addToListFor(new HashSet<>(assoc.getPrerequisiteList()), ab);
            }
        }
        Set<String> set = new TreeSet<>();
        for (Set<Prerequisite> prereqs : m.getKeySet()) {
            Set<CDOMReference<Domain>> domainSet = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
            domainSet.addAll(m.getListFor(prereqs));
            StringBuilder sb = new StringBuilder(ReferenceUtilities.joinLstFormat(domainSet, Constants.COMMA, true));
            if (prereqs != null && !prereqs.isEmpty()) {
                sb.append(Constants.PIPE);
                sb.append(getPrerequisiteString(context, prereqs));
            }
            set.add(sb.toString());
        }
        list.addAll(set);
    }
    if (list.isEmpty()) {
        return null;
    }
    return list.toArray(new String[list.size()]);
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) DomainList(pcgen.cdom.list.DomainList) HashMapToList(pcgen.base.util.HashMapToList) TreeSet(java.util.TreeSet) Domain(pcgen.core.Domain) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 2 with DomainList

use of pcgen.cdom.list.DomainList in project pcgen by PCGen.

the class DomainsToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Deity deity, String value) {
    StringTokenizer pipeTok = new StringTokenizer(value, Constants.PIPE);
    StringTokenizer commaTok = new StringTokenizer(pipeTok.nextToken(), Constants.COMMA);
    CDOMReference<DomainList> dl = Deity.DOMAINLIST;
    ArrayList<AssociatedPrereqObject> proList = new ArrayList<>();
    boolean first = true;
    boolean foundAll = false;
    boolean foundOther = false;
    boolean foundClear = false;
    while (commaTok.hasMoreTokens()) {
        String tokString = commaTok.nextToken();
        if (looksLikeAPrerequisite(tokString)) {
            return new ParseResult.Fail("Invalid " + getTokenName() + ": PRExxx was comma delimited : " + value, context);
        }
        if (Constants.LST_DOT_CLEAR.equals(tokString)) {
            if (!first) {
                return new ParseResult.Fail("  Non-sensical " + getTokenName() + ": .CLEAR was not the first list item: " + value, context);
            }
            context.getListContext().removeAllFromList(getTokenName(), deity, dl);
            foundClear = true;
        } else if (tokString.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
            CDOMReference<Domain> ref;
            String clearText = tokString.substring(7);
            if (Constants.LST_ALL.equals(clearText) || Constants.LST_ANY.equals(clearText)) {
                ref = context.getReferenceContext().getCDOMAllReference(DOMAIN_CLASS);
            } else {
                ref = context.getReferenceContext().getCDOMReference(DOMAIN_CLASS, clearText);
            }
            context.getListContext().removeFromList(getTokenName(), deity, dl, ref);
            foundClear = true;
        } else if (Constants.LST_ALL.equals(tokString) || Constants.LST_ANY.equals(tokString)) {
            CDOMGroupRef<Domain> ref = context.getReferenceContext().getCDOMAllReference(DOMAIN_CLASS);
            proList.add(context.getListContext().addToList(getTokenName(), deity, dl, ref));
            foundAll = true;
        } else {
            CDOMSingleRef<Domain> ref = context.getReferenceContext().getCDOMReference(DOMAIN_CLASS, tokString);
            proList.add(context.getListContext().addToList(getTokenName(), deity, dl, ref));
            foundOther = true;
        }
        first = false;
    }
    if (foundAll && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ALL and a specific reference: " + value, context);
    }
    while (pipeTok.hasMoreTokens()) {
        if (foundClear) {
            return new ParseResult.Fail("Cannot use PREREQs when using .CLEAR or .CLEAR. in " + getTokenName(), context);
        }
        String tokString = pipeTok.nextToken();
        Prerequisite prereq = getPrerequisite(tokString);
        if (prereq == null) {
            return new ParseResult.Fail("   (Did you put items after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
        }
        for (AssociatedPrereqObject ao : proList) {
            ao.addPrerequisite(prereq);
        }
    }
    return ParseResult.SUCCESS;
}
Also used : ArrayList(java.util.ArrayList) DomainList(pcgen.cdom.list.DomainList) StringTokenizer(java.util.StringTokenizer) Domain(pcgen.core.Domain) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 3 with DomainList

use of pcgen.cdom.list.DomainList in project pcgen by PCGen.

the class DeityToken method getCollection.

@Override
public <R> Collection<R> getCollection(PlayerCharacter pc, Converter<Domain, R> c) {
    HashSet<R> returnSet = new HashSet<>();
    Deity deity = pc.getDisplay().getDeity();
    if (deity == null) {
        return returnSet;
    }
    CDOMReference<DomainList> list = Deity.DOMAINLIST;
    Collection<CDOMReference<Domain>> mods = deity.getListMods(list);
    for (CDOMReference<Domain> ref : mods) {
        Collection<AssociatedPrereqObject> assoc = deity.getListAssociations(list, ref);
        for (AssociatedPrereqObject apo : assoc) {
            if (PrereqHandler.passesAll(apo.getPrerequisiteList(), pc, deity)) {
                returnSet.addAll(c.convert(ref));
                break;
            }
        }
    }
    return returnSet;
}
Also used : Deity(pcgen.core.Deity) DomainList(pcgen.cdom.list.DomainList) Domain(pcgen.core.Domain) CDOMReference(pcgen.cdom.base.CDOMReference) HashSet(java.util.HashSet) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Aggregations

AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)3 CDOMReference (pcgen.cdom.base.CDOMReference)3 DomainList (pcgen.cdom.list.DomainList)3 Domain (pcgen.core.Domain)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Prerequisite (pcgen.core.prereq.Prerequisite)2 Set (java.util.Set)1 StringTokenizer (java.util.StringTokenizer)1 TreeSet (java.util.TreeSet)1 HashMapToList (pcgen.base.util.HashMapToList)1 Deity (pcgen.core.Deity)1