MCPcopy Create free account
hub / github.com/PCGen/pcgen / AbilityToken

Class AbilityToken

code/src/java/plugin/lsttokens/choose/AbilityToken.java:52–321  ·  view source on GitHub ↗

New chooser plugin, handles Abilities.

Source from the content-addressed store, hash-verified

50 */
51
52public class AbilityToken extends AbstractTokenWithSeparator<CDOMObject>
53 implements CDOMSecondaryToken<CDOMObject>, CategorizedChooser<Ability>
54{
55 private static final Class<AbilityCategory> ABILITY_CATEGORY_CLASS = AbilityCategory.class;
56
57 @Override
58 public String getParentToken()
59 {
60 return "CHOOSE";
61 }
62
63 @Override
64 protected char separator()
65 {
66 return '|';
67 }
68
69 protected ParseResult parseTokenWithSeparator(LoadContext context, ReferenceManufacturer<Ability> rm,
70 CDOMSingleRef<AbilityCategory> acRef, CDOMObject obj, String value)
71 {
72 int pipeLoc = value.lastIndexOf('|');
73 String activeValue;
74 String title;
75 if (pipeLoc == -1)
76 {
77 activeValue = value;
78 title = getDefaultTitle();
79 }
80 else
81 {
82 String titleString = value.substring(pipeLoc + 1);
83 if (titleString.startsWith("TITLE="))
84 {
85 title = titleString.substring(6);
86 if (title.startsWith("\""))
87 {
88 title = title.substring(1, title.length() - 1);
89 }
90 activeValue = value.substring(0, pipeLoc);
91 if (title.isEmpty())
92 {
93 return new ParseResult.Fail(
94 getParentToken() + Constants.COLON + getTokenName() + " had TITLE= but no title: " + value);
95 }
96 }
97 else
98 {
99 activeValue = value;
100 title = getDefaultTitle();
101 }
102 }
103
104 PrimitiveCollection<Ability> coll = context.getChoiceSet(rm, activeValue);
105 if (coll == null)
106 {
107 return ParseResult.INTERNAL_ERROR;
108 }
109 if (!coll.getGroupingState().isValid())

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected