Example #1
0
 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()]);
 }
Example #2
0
 @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()};
 }
Example #3
0
  @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()]);
  }
Example #4
0
 @Override
 public String[] unparse(LoadContext context, Skill skill) {
   Changes<String> changes = context.getObjectContext().getListChanges(skill, ListKey.SITUATION);
   if (changes == null || changes.isEmpty()) {
     return null;
   }
   List<String> list = new ArrayList<String>();
   Collection<String> removedItems = changes.getRemoved();
   if (removedItems != null && !removedItems.isEmpty()) {
     context.addWriteMessage(".CLEAR. not supported");
     return null;
   }
   if (changes.includesGlobalClear()) {
     list.add(Constants.LST_DOT_CLEAR);
   }
   Collection<String> 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()]);
 }