@Override protected ParseResult parseTokenWithSeparator( LoadContext context, PCClassLevel obj, String value) { boolean first = true; boolean foundAny = false; boolean foundOther = false; StringTokenizer tok = new StringTokenizer(value, Constants.PIPE); while (tok.hasMoreTokens()) { String tokText = tok.nextToken(); if (Constants.LST_DOT_CLEAR.equals(tokText)) { if (!first) { return new ParseResult.Fail( " Non-sensical " + getTokenName() + ": .CLEAR was not the first list item"); } context.getObjectContext().removeList(obj, ListKey.LOCALCCSKILL); } else if (tokText.startsWith(Constants.LST_DOT_CLEAR_DOT)) { String clearText = tokText.substring(7); if (Constants.LST_ALL.equals(clearText)) { context .getObjectContext() .removeFromList( obj, ListKey.LOCALCCSKILL, context.ref.getCDOMAllReference(SKILL_CLASS)); } else { CDOMReference<Skill> ref = TokenUtilities.getTypeOrPrimitive(context, SKILL_CLASS, clearText); if (ref == null) { return new ParseResult.Fail(" Error was encountered while parsing " + getTokenName()); } context.getObjectContext().removeFromList(obj, ListKey.LOCALCCSKILL, ref); } } else { /* * Note this HAS to be done one-by-one, because the * .clearChildNodeOfClass method above does NOT recognize the * C/CC Skill object and therefore doesn't know how to search * the sublists */ if (Constants.LST_ALL.equals(tokText)) { foundAny = true; context .getObjectContext() .addToList(obj, ListKey.LOCALCCSKILL, context.ref.getCDOMAllReference(SKILL_CLASS)); } else { foundOther = true; CDOMReference<Skill> ref = getSkillReference(context, tokText); if (ref == null) { return new ParseResult.Fail(" Error was encountered while parsing " + getTokenName()); } context.getObjectContext().addToList(obj, ListKey.LOCALCCSKILL, ref); } } first = false; } if (foundAny && foundOther) { return new ParseResult.Fail( "Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value); } return ParseResult.SUCCESS; }
@Override protected ParseResult parseTokenWithSeparator(LoadContext context, PCTemplate pct, String value) { context.getObjectContext().removeList(pct, ListKey.FEAT_TOKEN_LIST); StringTokenizer tok = new StringTokenizer(value, Constants.PIPE); boolean first = true; ReferenceManufacturer<Ability> rm = context.ref.getManufacturer(ABILITY_CLASS, AbilityCategory.FEAT); while (tok.hasMoreTokens()) { String token = tok.nextToken(); if (Constants.LST_DOT_CLEAR.equals(token)) { if (!first) { return new ParseResult.Fail( " Non-sensical " + getTokenName() + ": .CLEAR was not the first list item: " + value, context); } } else { CDOMReference<Ability> ability = TokenUtilities.getTypeOrPrimitive(rm, token); if (ability == null) { return ParseResult.INTERNAL_ERROR; } context.getObjectContext().addToList(pct, ListKey.FEAT_TOKEN_LIST, ability); } first = false; } return ParseResult.SUCCESS; }
@Override protected ParseResult parseTokenWithSeparator(LoadContext context, Spell spell, String value) { StringTokenizer aTok = new StringTokenizer(value, Constants.PIPE); boolean first = true; while (aTok.hasMoreTokens()) { String tok = aTok.nextToken(); if (Constants.LST_DOT_CLEAR.equals(tok)) { if (!first) { return new ParseResult.Fail( "Non-sensical use of .CLEAR in " + getTokenName() + ": " + value, context); } context.getObjectContext().removeList(spell, ListKey.RANGE); } else { if (!StringUtil.hasBalancedParens(value)) { return new ParseResult.Fail( "Unbalanced parentheses in " + getTokenName() + " '" + value + "' used in spell " + spell, context); } context.getObjectContext().addToList(spell, ListKey.RANGE, tok); Globals.addSpellRangesSet(tok); } first = false; } return ParseResult.SUCCESS; }
@Override protected ParseResult parseTokenWithSeparator(LoadContext context, Race race, String value) { StringTokenizer tok = new StringTokenizer(value, Constants.PIPE); boolean first = true; while (tok.hasMoreTokens()) { String tokString = tok.nextToken(); 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.obj.removeList(race, ListKey.RACESUBTYPE); } else if (tokString.startsWith(Constants.LST_DOT_CLEAR_DOT)) { String clearText = tokString.substring(7); context .getObjectContext() .removeFromList(race, ListKey.RACESUBTYPE, RaceSubType.getConstant(clearText)); } else { context .getObjectContext() .addToList(race, ListKey.RACESUBTYPE, RaceSubType.getConstant(tokString)); } first = false; } return ParseResult.SUCCESS; }
/** * Report where an issue was encountered. * * @param context the LoadContext containing the resource */ public static void reportSource(final Level lvl, final LoadContext context) { Logger l = getLogger(); if (l.isLoggable(lvl)) { if (context != null && context.getObjectContext() != null && context.getObjectContext().getSourceURI() != null) { l.log(lvl, " (Source: " + context.getObjectContext().getSourceURI() + " )"); } else { l.log(lvl, " (Source unknown)"); } } }
@Override protected ParseResult parseTokenWithSeparator( LoadContext context, EquipmentModifier mod, String value) { if (Constants.LST_DOT_CLEAR.equals(value)) { context.getObjectContext().removeList(mod, ListKey.SPECIAL_PROPERTIES); return ParseResult.SUCCESS; } SpecialProperty sa = SpecialProperty.createFromLst(value); if (sa == null) { return ParseResult.INTERNAL_ERROR; } context.getObjectContext().addToList(mod, ListKey.SPECIAL_PROPERTIES, sa); return ParseResult.SUCCESS; }
public String[] unparse(LoadContext context, PCClassLevel obj) { Changes<CDOMReference<Skill>> changes = context.getObjectContext().getListChanges(obj, ListKey.LOCALCCSKILL); List<String> list = new ArrayList<String>(); 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); } Collection<CDOMReference<Skill>> added = changes.getAdded(); if (added != null && !added.isEmpty()) { list.add(ReferenceUtilities.joinLstFormat(added, Constants.PIPE)); } if (list.isEmpty()) { return null; } return list.toArray(new String[list.size()]); }
public String[] unparse(LoadContext context, EquipmentModifier mod) { Changes<SpecialProperty> changes = context.getObjectContext().getListChanges(mod, ListKey.SPECIAL_PROPERTIES); if (changes == null || changes.isEmpty()) { return null; } List<String> list = new ArrayList<String>(); Collection<SpecialProperty> added = changes.getAdded(); boolean globalClear = changes.includesGlobalClear(); if (globalClear) { list.add(Constants.LST_DOT_CLEAR); } if (added != null && !added.isEmpty()) { for (SpecialProperty sp : added) { StringBuilder sb = new StringBuilder(); sb.append(sp.getDisplayName()); if (sp.hasPrerequisites()) { sb.append(Constants.PIPE); sb.append(getPrerequisiteString(context, sp.getPrerequisiteList())); } list.add(sb.toString()); } } if (list.isEmpty()) { context.addWriteMessage( getTokenName() + " was expecting non-empty changes to include " + "added items or global clear"); return null; } return list.toArray(new String[list.size()]); }
@Override public String[] unparse(LoadContext context, CDOMObject obj) { Changes<PersistentTransitionChoice<?>> grantChanges = context.getObjectContext().getListChanges(obj, ListKey.REMOVE); Collection<PersistentTransitionChoice<?>> addedItems = grantChanges.getAdded(); if (addedItems == null || addedItems.isEmpty()) { // Zero indicates no Token return null; } List<String> addStrings = new ArrayList<String>(); for (TransitionChoice<?> container : addedItems) { SelectableSet<?> cs = container.getChoices(); if (getTokenName().equals(cs.getName()) && CAT_ABILITY_SELECTION_CLASS.equals(cs.getChoiceClass())) { Formula f = container.getCount(); if (f == null) { context.addWriteMessage("Unable to find " + getFullName() + " Count"); return null; } StringBuilder sb = new StringBuilder(); if (!FormulaFactory.ONE.equals(f)) { sb.append(f).append(Constants.PIPE); } sb.append(cs.getLSTformat()); addStrings.add(sb.toString()); } } return addStrings.toArray(new String[addStrings.size()]); }
public String[] unparse(LoadContext context, Campaign campaign) { String title = context.getObjectContext().getString(campaign, StringKey.PUB_NAME_WEB); if (title == null) { return null; } return new String[] {title}; }
@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); } ObjectContainer<F> indirect = fmtManager.convertObjectContainer(token); objContext.addToSet(obj, fsk, indirect); } return ParseResult.SUCCESS; }
@Override public String[] unparse(LoadContext context, T obj) { FactSetKey<F> fk = def.getFactSetKey(); Changes<ObjectContainer<F>> changes = context.getObjectContext().getSetChanges(obj, fk); Collection<ObjectContainer<F>> removedItems = changes.getRemoved(); List<String> results = new ArrayList<String>(2); if (changes.includesGlobalClear()) { results.add(Constants.LST_DOT_CLEAR_ALL); } if (removedItems != null && !removedItems.isEmpty()) { context.addWriteMessage(getTokenName() + " does not support " + Constants.LST_DOT_CLEAR_DOT); return null; } Collection<ObjectContainer<F>> added = changes.getAdded(); if (added != null && added.size() > 0) { StringBuilder sb = new StringBuilder(); boolean needsPipe = false; for (ObjectContainer<F> oc : added) { if (needsPipe) { sb.append(Constants.PIPE); } sb.append(oc.getLSTformat(false)); needsPipe = true; } results.add(sb.toString()); } return results.toArray(new String[results.size()]); }
public String[] unparse(LoadContext context, EquipmentModifier mod) { Formula f = context.getObjectContext().getFormula(mod, FormulaKey.BASECOST); if (f == null) { return null; } return new String[] {f.toString()}; }
@Override public String[] unparse(LoadContext context, CDOMObject cdo) { ChooseInformation<?> tc = context.getObjectContext().getObject(cdo, ObjectKey.CHOOSE_INFO); if (tc == null) { return null; } if (!tc.getName().equals(getTokenName())) { // Don't unparse anything that isn't owned by this SecondaryToken /* * TODO Either this really needs to be a check against the subtoken * (which thus needs to be stored in the ChooseInfo) or there needs * to be a loadtime check that no more than once CHOOSE subtoken * uses the same AssociationListKey... :P */ return null; } if (!tc.getGroupingState().isValid()) { context.addWriteMessage( "Invalid combination of objects" + " was used in: " + getParentToken() + ":" + getTokenName()); return null; } StringBuilder sb = new StringBuilder(); sb.append(tc.getLSTformat()); String title = tc.getTitle(); if (!title.equals(getDefaultTitle())) { sb.append("|TITLE="); sb.append(title); } return new String[] {sb.toString()}; }
public String[] unparse(LoadContext context, Race race) { Changes<RaceSubType> changes = context.getObjectContext().getListChanges(race, ListKey.RACESUBTYPE); if (changes == null || changes.isEmpty()) { return null; } List<String> list = new ArrayList<String>(); Collection<RaceSubType> 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 + StringUtil.join(removedItems, "|.CLEAR.")); } Collection<RaceSubType> added = changes.getAdded(); if (added != null && !added.isEmpty()) { list.add(StringUtil.join(added, Constants.PIPE)); } if (list.isEmpty()) { return null; } return list.toArray(new String[list.size()]); }
private <CC extends BaseKit> boolean subParse( LoadContext context, Kit kit, CDOMSubLineLoader<CC> loader, String line) throws PersistenceLayerException { CC obj = loader.getCDOMObject(); context.getObjectContext().addToList(kit, ListKey.KIT_TASKS, obj); return loader.parseLine(context, obj, line); }
/** * Beep and print error message if PCGen is debugging. * * @param s String error message * @param context the LoadContext containing the deprecated resource */ public static void errorPrint(final String s, final LoadContext context) { if (isDebugMode()) { s_TOOLKIT.beep(); } Logger l = getLogger(); if (l.isLoggable(ERROR)) { if (context != null && context.getObjectContext() != null && context.getObjectContext().getSourceURI() != null) { l.log(ERROR, s + " (Source: " + context.getObjectContext().getSourceURI() + " )"); } else { l.log(ERROR, s); } } }
/** * Beep and print error message if PCGen is debugging. * * @param s String error message * @param context the LoadContext containing the deprecated resource */ public static void deprecationPrint(final String s, final LoadContext context) { if (isDebugMode()) { s_TOOLKIT.beep(); } Logger l = getLogger(); if (l.isLoggable(LST_WARNING) && SettingsHandler.outputDeprecationMessages()) { if (context != null && context.getObjectContext() != null && context.getObjectContext().getSourceURI() != null) { l.log(LST_WARNING, s + " (Source: " + context.getObjectContext().getSourceURI() + " )"); } else { l.log(LST_WARNING, s); } } }
@Override public String[] unparse(LoadContext context, PCTemplate pct) { Changes<CDOMReference<Ability>> changes = context.getObjectContext().getListChanges(pct, ListKey.FEAT_TOKEN_LIST); Collection<CDOMReference<Ability>> added = changes.getAdded(); Collection<CDOMReference<Ability>> removedItems = changes.getRemoved(); String returnVal = null; if (changes.includesGlobalClear()) { if (removedItems != null && !removedItems.isEmpty()) { context.addWriteMessage( "Non-sensical relationship in " + getTokenName() + ": global .CLEAR and local .CLEAR. performed"); return null; } returnVal = Constants.LST_DOT_CLEAR; } else if (removedItems != null && !removedItems.isEmpty()) { context.addWriteMessage(getTokenName() + " does not support " + Constants.LST_DOT_CLEAR_DOT); return null; } if (added != null && !added.isEmpty()) { returnVal = ReferenceUtilities.joinLstFormat(added, Constants.PIPE); } if (returnVal == null) { return null; } return new String[] {returnVal}; }
@Override public String[] unparse(LoadContext context, PCClass obj) { Changes<BonusObj> changes = context.getObjectContext().getListChanges(obj, ListKey.BONUS); if (changes == null || changes.isEmpty()) { // Empty indicates no token present return null; } // CONSIDER need to deal with removed... Collection<BonusObj> added = changes.getAdded(); String tokenName = getTokenName(); Set<String> bonusSet = new TreeSet<String>(); for (BonusObj bonus : added) { if (tokenName.equals(bonus.getTokenSource())) { StringBuilder sb = new StringBuilder(); sb.append(bonus.getValue()); List<Prerequisite> prereqList = new ArrayList<Prerequisite>(bonus.getPrerequisiteList()); Prerequisite prereq = getPrerequisite("PRELEVELMAX:1"); prereqList.remove(prereq); if (!prereqList.isEmpty()) { sb.append('|'); sb.append(getPrerequisiteString(context, prereqList)); } bonusSet.add(sb.toString()); } } if (bonusSet.isEmpty()) { // This is okay - just no BONUSes from this token return null; } return bonusSet.toArray(new String[bonusSet.size()]); }
@Override public String[] unparse(LoadContext context, CDOMObject cdo) { Changes<Type> changes = context.getObjectContext().getListChanges(cdo, ListKey.TYPE); if (changes == null || changes.isEmpty()) { return null; } StringBuilder sb = new StringBuilder(); Collection<?> added = changes.getAdded(); boolean globalClear = changes.includesGlobalClear(); if (globalClear) { sb.append(Constants.LST_DOT_CLEAR); } if (added != null && !added.isEmpty()) { if (globalClear) { sb.append(Constants.DOT); } sb.append(StringUtil.join(added, Constants.DOT)); } Collection<Type> removed = changes.getRemoved(); if (removed != null && !removed.isEmpty()) { if (sb.length() > 0) { sb.append(Constants.DOT); } sb.append("REMOVE."); sb.append(StringUtil.join(removed, Constants.DOT)); } if (sb.length() == 0) { context.addWriteMessage( getTokenName() + " was expecting non-empty changes to include " + "added items or global clear"); return null; } return new String[] {sb.toString()}; }
@Override public String[] unparse(LoadContext context, CDOMObject obj) { String descr = context.getObjectContext().getString(obj, StringKey.TEMP_DESCRIPTION); if (descr == null) { return null; } return new String[] {EntityEncoder.encode(descr)}; }
@Override protected ParseResult parseNonEmptyToken(LoadContext context, Campaign campaign, String value) { ParseResult pr = checkForInvalidXMLChars(value); if (pr.passed()) { context.getObjectContext().put(campaign, StringKey.DESCRIPTION, value); } return pr; }
@Override public String[] unparse(LoadContext context, Campaign campaign) { String title = context.getObjectContext().getString(campaign, StringKey.DESCRIPTION); if (title == null) { return null; } return new String[] {title}; }
@Override public String[] unparse(LoadContext context, Spell spell) { String target = context.getObjectContext().getString(spell, StringKey.TARGET_AREA); if (target == null) { return null; } return new String[] {target}; }
@Override public String[] unparse(LoadContext context, Campaign campaign) { Boolean isM = context.getObjectContext().getObject(campaign, ObjectKey.IS_D20); if (isM == null) { return null; } return new String[] {isM.booleanValue() ? "YES" : "NO"}; }
@Override protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) { ParsingSeparator sep = new ParsingSeparator(value, '|'); String activeValue = sep.next(); Formula count; if (!sep.hasNext()) { count = FormulaFactory.ONE; } else { count = FormulaFactory.getFormulaFor(activeValue); if (!count.isValid()) { return new ParseResult.Fail( "Count in " + getTokenName() + " was not valid: " + count.toString()); } if (count.isStatic() && count.resolve(null, "").doubleValue() <= 0) { return new ParseResult.Fail("Count in " + getFullName() + " must be > 0"); } activeValue = sep.next(); } if (sep.hasNext()) { return new ParseResult.Fail(getFullName() + " had too many pipe separated items: " + value); } ParseResult pr = checkSeparatorsAndNonEmpty(',', activeValue); if (!pr.passed()) { return pr; } List<CDOMReference<Language>> refs = new ArrayList<CDOMReference<Language>>(); StringTokenizer tok = new StringTokenizer(activeValue, Constants.COMMA); while (tok.hasMoreTokens()) { String tokText = tok.nextToken(); CDOMReference<Language> lang = TokenUtilities.getReference(context, LANGUAGE_CLASS, tokText); if (lang == null) { return new ParseResult.Fail( " Error was encountered while parsing " + getFullName() + ": " + value + " had an invalid reference: " + tokText); } refs.add(lang); } ReferenceChoiceSet<Language> rcs = new ReferenceChoiceSet<Language>(refs); if (!rcs.getGroupingState().isValid()) { return new ParseResult.Fail( "Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value); } ChoiceSet<Language> cs = new ChoiceSet<Language>(getTokenName(), rcs); cs.setTitle("Language Choice"); PersistentTransitionChoice<Language> tc = new ConcretePersistentTransitionChoice<Language>(cs, count); context.getObjectContext().addToList(obj, ListKey.ADD, tc); tc.setChoiceActor(this); return ParseResult.SUCCESS; }
@Override public ParseResult parseToken(LoadContext context, EquipmentModifier obj, String value) { if (value == null) { // No args - legal context.getObjectContext().put(obj, StringKey.CHOICE_STRING, getTokenName()); return ParseResult.SUCCESS; } return new ParseResult.Fail( "CHOOSE:" + getTokenName() + " must not have arguments: " + value, context); }
@Override public String[] unparse(LoadContext context, CDOMObject obj) { Changes<FollowerOption> changes = context.getObjectContext().getListChanges(obj, ListKey.COMPANIONLIST); Collection<FollowerOption> removedItems = changes.getRemoved(); if (removedItems != null && !removedItems.isEmpty() || changes.includesGlobalClear()) { context.addWriteMessage(getTokenName() + " does not support .CLEAR"); return null; } Collection<FollowerOption> added = changes.getAdded(); if (added == null || added.isEmpty()) { // Zero indicates no Token (and no global clear, so nothing to do) return null; } TripleKeyMapToList< Set<Prerequisite>, CDOMReference<? extends CDOMList<?>>, Integer, CDOMReference<Race>> m = new TripleKeyMapToList<>(); for (FollowerOption fo : added) { m.addToListFor( new HashSet<>(fo.getPrerequisiteList()), fo.getListRef(), fo.getAdjustment(), fo.getRaceRef()); } Set<String> set = new TreeSet<>(); StringBuilder sb = new StringBuilder(); for (Set<Prerequisite> prereqs : m.getKeySet()) { String prereqString = null; if (prereqs != null && !prereqs.isEmpty()) { prereqString = getPrerequisiteString(context, prereqs); } for (CDOMReference<? extends CDOMList<?>> cl : m.getSecondaryKeySet(prereqs)) { for (Integer fa : m.getTertiaryKeySet(prereqs, cl)) { sb.setLength(0); sb.append(cl.getLSTformat(false)); sb.append(Constants.PIPE); Set<CDOMReference<Race>> raceSet = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER); raceSet.addAll(m.getListFor(prereqs, cl, fa)); sb.append(ReferenceUtilities.joinLstFormat(raceSet, Constants.COMMA, true)); if (fa != null && fa != 0) { sb.append(Constants.PIPE); sb.append("FOLLOWERADJUSTMENT:"); sb.append(fa); } if (prereqString != null) { sb.append(Constants.PIPE); sb.append(prereqString); } set.add(sb.toString()); } } } return set.toArray(new String[set.size()]); }
@Override public String[] unparse(LoadContext context, PCTemplate pct) { Changes<CDOMReference<WeaponProf>> changes = context.getObjectContext().getListChanges(pct, ListKey.WEAPONBONUS); Collection<CDOMReference<WeaponProf>> added = changes.getAdded(); if (added == null || added.isEmpty()) { // Zero indicates no add return null; } return new String[] {ReferenceUtilities.joinLstFormat(added, Constants.PIPE)}; }