Search in sources :

Example 11 with ClassSkillList

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

the class SkillListTokenTest method testUnparseMultiple.

/*
	 * TODO Need to figure out who's responsibility this is!
	 */
// @Test
// public void testUnparseBadList() throws PersistenceLayerException
// {
// Language wp1 = construct(primaryContext, "TestWP1");
// ReferenceChoiceSet<Language> rcs = buildRCS(CDOMDirectSingleRef
// .getRef(wp1), primaryContext.ref
// .getCDOMAllReference(getTargetClass()));
// assertFalse(rcs.getGroupingState().isValid());
// PersistentTransitionChoice<Language> tc = buildTC(rcs);
// tc.setChoiceActor(subtoken);
// primaryProf.put(ObjectKey.CHOOSE_LANGAUTO, tc);
// assertBadUnparse();
// }
@Test
public void testUnparseMultiple() throws PersistenceLayerException {
    ClassSkillList wp1 = construct(primaryContext, "TestWP1");
    ClassSkillList wp2 = construct(primaryContext, "TestWP2");
    PersistentTransitionChoice<ClassSkillList> tc = buildChoice(CDOMDirectSingleRef.getRef(wp1), CDOMDirectSingleRef.getRef(wp2));
    primaryProf.put(ObjectKey.SKILLLIST_CHOICE, tc);
    String[] unparsed = getToken().unparse(primaryContext, primaryProf);
    expectSingle(unparsed, "1|TestWP1|TestWP2");
}
Also used : ClassSkillList(pcgen.cdom.list.ClassSkillList) Test(org.junit.Test)

Example 12 with ClassSkillList

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

the class SkillListTokenTest method testUnparseSingle.

@Test
public void testUnparseSingle() throws PersistenceLayerException {
    ClassSkillList wp1 = construct(primaryContext, "TestWP1");
    PersistentTransitionChoice<ClassSkillList> tc = buildChoice(CDOMDirectSingleRef.getRef(wp1));
    primaryProf.put(ObjectKey.SKILLLIST_CHOICE, tc);
    String[] unparsed = getToken().unparse(primaryContext, primaryProf);
    expectSingle(unparsed, "1|TestWP1");
}
Also used : ClassSkillList(pcgen.cdom.list.ClassSkillList) Test(org.junit.Test)

Example 13 with ClassSkillList

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

the class MonccskillToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Race race, String value) {
    boolean firstToken = true;
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    CDOMGroupRef<ClassSkillList> monsterList = context.getReferenceContext().getCDOMTypeReference(ClassSkillList.class, "Monster");
    while (tok.hasMoreTokens()) {
        String tokText = tok.nextToken();
        if (Constants.LST_DOT_CLEAR.equals(tokText)) {
            if (!firstToken) {
                return new ParseResult.Fail("Non-sensical situation was " + "encountered while parsing " + getTokenName() + ": When used, .CLEAR must be the first argument", context);
            }
            context.getListContext().removeAllFromList(getTokenName(), race, monsterList);
        } else if (tokText.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
            CDOMReference<Skill> skill;
            String clearText = tokText.substring(7);
            if (Constants.LST_ALL.equals(clearText)) {
                skill = context.getReferenceContext().getCDOMAllReference(SKILL_CLASS);
            } else {
                skill = getSkillReference(context, clearText);
            }
            if (skill == null) {
                return new ParseResult.Fail("  Error was encountered while parsing " + getTokenName(), context);
            }
            context.getListContext().removeFromList(getTokenName(), race, monsterList, skill);
        } else {
            /*
				 * Note this is done one-by-one, because .CLEAR. token type
				 * needs to be able to perform the unlink. That could be
				 * changed, but the increase in complexity isn't worth it.
				 * (Changing it to a grouping object that didn't place links in
				 * the graph would also make it harder to trace the source of
				 * class skills, etc.)
				 */
            CDOMReference<Skill> skill;
            if (Constants.LST_ALL.equals(tokText)) {
                foundAny = true;
                skill = context.getReferenceContext().getCDOMAllReference(SKILL_CLASS);
            } else {
                foundOther = true;
                skill = getSkillReference(context, tokText);
            }
            if (skill == null) {
                return new ParseResult.Fail("  Error was encountered while parsing " + getTokenName(), context);
            }
            AssociatedPrereqObject apo = context.getListContext().addToList(getTokenName(), race, monsterList, skill);
            apo.setAssociation(AssociationKey.SKILL_COST, SkillCost.CROSS_CLASS);
        }
        firstToken = false;
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
    }
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) ParseResult(pcgen.rules.persistence.token.ParseResult) ClassSkillList(pcgen.cdom.list.ClassSkillList) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 14 with ClassSkillList

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

the class MonccskillToken method unparse.

@Override
public String[] unparse(LoadContext context, Race race) {
    CDOMGroupRef<ClassSkillList> monsterList = context.getReferenceContext().getCDOMTypeReference(ClassSkillList.class, "Monster");
    AssociatedChanges<CDOMReference<Skill>> changes = context.getListContext().getChangesInList(getTokenName(), race, monsterList);
    List<String> list = new ArrayList<>();
    Collection<CDOMReference<Skill>> removedItems = changes.getRemoved();
    if (removedItems != null && !removedItems.isEmpty()) {
        if (changes.includesGlobalClear()) {
            context.addWriteMessage("Non-sensical relationship in " + getTokenName() + ": global .CLEAR and local .CLEAR. performed");
            return null;
        }
        list.add(Constants.LST_DOT_CLEAR_DOT + ReferenceUtilities.joinLstFormat(removedItems, "|.CLEAR."));
    }
    if (changes.includesGlobalClear()) {
        list.add(Constants.LST_DOT_CLEAR);
    }
    MapToList<CDOMReference<Skill>, AssociatedPrereqObject> map = changes.getAddedAssociations();
    if (map != null && !map.isEmpty()) {
        Set<CDOMReference<Skill>> added = map.getKeySet();
        for (CDOMReference<Skill> ab : added) {
            for (AssociatedPrereqObject assoc : map.getListFor(ab)) {
                if (!SkillCost.CROSS_CLASS.equals(assoc.getAssociation(AssociationKey.SKILL_COST))) {
                    context.addWriteMessage("Skill Cost must be " + "CROSS_CLASS for Token " + getTokenName());
                    return null;
                }
            }
        }
        list.add(ReferenceUtilities.joinLstFormat(added, Constants.PIPE));
    }
    if (list.isEmpty()) {
        // Zero indicates no add or clear
        return null;
    }
    return list.toArray(new String[list.size()]);
}
Also used : ArrayList(java.util.ArrayList) ClassSkillList(pcgen.cdom.list.ClassSkillList) Skill(pcgen.core.Skill) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 15 with ClassSkillList

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

the class MoncskillToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Race race, String value) {
    boolean firstToken = true;
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    CDOMGroupRef<ClassSkillList> monsterList = context.getReferenceContext().getCDOMTypeReference(ClassSkillList.class, "Monster");
    while (tok.hasMoreTokens()) {
        String tokText = tok.nextToken();
        if (Constants.LST_DOT_CLEAR.equals(tokText)) {
            if (!firstToken) {
                return new ParseResult.Fail("Non-sensical situation was " + "encountered while parsing " + getTokenName() + ": When used, .CLEAR must be the first argument", context);
            }
            context.getListContext().removeAllFromList(getTokenName(), race, monsterList);
        } else if (tokText.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
            CDOMReference<Skill> skill = null;
            String clearText = tokText.substring(7);
            if (Constants.LST_ALL.equals(clearText)) {
                skill = context.getReferenceContext().getCDOMAllReference(SKILL_CLASS);
            } else {
                if (Constants.LST_LIST.equals(clearText)) {
                    context.getObjectContext().removeFromList(race, ListKey.NEW_CHOOSE_ACTOR, this);
                } else {
                    skill = getSkillReference(context, clearText);
                    if (skill == null) {
                        return new ParseResult.Fail("  Error was encountered while parsing " + getTokenName(), context);
                    }
                }
            }
            if (skill != null) {
                context.getListContext().removeFromList(getTokenName(), race, monsterList, skill);
            }
        } else {
            /*
				 * Note this is done one-by-one, because .CLEAR. token type
				 * needs to be able to perform the unlink. That could be
				 * changed, but the increase in complexity isn't worth it.
				 * (Changing it to a grouping object that didn't place links in
				 * the graph would also make it harder to trace the source of
				 * class skills, etc.)
				 */
            CDOMReference<Skill> skill = null;
            if (Constants.LST_ALL.equals(tokText)) {
                foundAny = true;
                skill = context.getReferenceContext().getCDOMAllReference(SKILL_CLASS);
            } else {
                foundOther = true;
                if (Constants.LST_LIST.equals(tokText)) {
                    context.getObjectContext().addToList(race, ListKey.NEW_CHOOSE_ACTOR, this);
                } else {
                    skill = getSkillReference(context, tokText);
                    if (skill == null) {
                        return new ParseResult.Fail("  Error was encountered while parsing " + getTokenName(), context);
                    }
                }
            }
            if (skill != null) {
                AssociatedPrereqObject apo = context.getListContext().addToList(getTokenName(), race, monsterList, skill);
                apo.setAssociation(AssociationKey.SKILL_COST, SkillCost.CLASS);
            }
        }
        firstToken = false;
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
    }
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) ParseResult(pcgen.rules.persistence.token.ParseResult) ClassSkillList(pcgen.cdom.list.ClassSkillList) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Aggregations

ClassSkillList (pcgen.cdom.list.ClassSkillList)25 CDOMReference (pcgen.cdom.base.CDOMReference)8 PCClass (pcgen.core.PCClass)8 Skill (pcgen.core.Skill)8 Test (org.junit.Test)6 CharID (pcgen.cdom.enumeration.CharID)6 ArrayList (java.util.ArrayList)5 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)5 StringTokenizer (java.util.StringTokenizer)4 ParseResult (pcgen.rules.persistence.token.ParseResult)4 SkillCost (pcgen.cdom.enumeration.SkillCost)3 SubClass (pcgen.core.SubClass)3 Formula (pcgen.base.formula.Formula)2 ChoiceSet (pcgen.cdom.base.ChoiceSet)2 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)2 Race (pcgen.core.Race)2 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)2 CDOMObject (pcgen.cdom.base.CDOMObject)1 ChooseSelectionActor (pcgen.cdom.base.ChooseSelectionActor)1 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)1