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

Method unparse

code/src/java/plugin/lsttokens/add/AbilityToken.java:274–339  ·  view source on GitHub ↗
(LoadContext context, CDOMObject obj)

Source from the content-addressed store, hash-verified

272 }
273
274 @Override
275 public String[] unparse(LoadContext context, CDOMObject obj)
276 {
277 Changes<PersistentTransitionChoice<?>> grantChanges =
278 context.getObjectContext().getListChanges(obj, ListKey.ADD);
279 Collection<PersistentTransitionChoice<?>> addedItems = grantChanges.getAdded();
280 if ((addedItems == null) || addedItems.isEmpty())
281 {
282 // Zero indicates no Token
283 return null;
284 }
285 List<String> addStrings = new ArrayList<>();
286 for (TransitionChoice<?> container : addedItems)
287 {
288 SelectableSet<?> cs = container.getChoices();
289 if (getTokenName().equals(cs.getName()) && CAT_ABILITY_SELECTION_CLASS.equals(cs.getChoiceClass()))
290 {
291 AbilityChoiceSet ascs = (AbilityChoiceSet) cs;
292 Formula f = container.getCount();
293 if (f == null)
294 {
295 context.addWriteMessage("Unable to find " + getFullName() + " Count");
296 return null;
297 }
298 if (f.isStatic() && (f.resolveStatic().doubleValue() <= 0))
299 {
300 context.addWriteMessage("Count in " + getFullName() + " must be > 0");
301 return null;
302 }
303 if (!cs.getGroupingState().isValid())
304 {
305 context.addWriteMessage("Non-sensical " + getFullName()
306 + ": Contains ANY and a specific reference: " + cs.getLSTformat());
307 return null;
308 }
309 StringBuilder sb = new StringBuilder();
310 if (!FormulaFactory.ONE.equals(f))
311 {
312 sb.append(f).append(Constants.PIPE);
313 }
314 sb.append(ascs.getCategory().getLSTformat(false));
315 sb.append(Constants.PIPE);
316 sb.append(ascs.getNature());
317 sb.append(Constants.PIPE);
318 if (container.allowsStacking())
319 {
320 sb.append("STACKS");
321 Integer stackLimit = container.getStackLimit();
322 if (stackLimit != null)
323 {
324 if (stackLimit <= 0)
325 {
326 context.addWriteMessage("Stack Limit in " + getFullName() + " must be > 0");
327 return null;
328 }
329 sb.append(Constants.EQUALS);
330 sb.append(stackLimit.intValue());
331 }

Callers

nothing calls this directly

Calls 15

getTokenNameMethod · 0.95
getFullNameMethod · 0.95
isStaticMethod · 0.95
resolveStaticMethod · 0.95
getCategoryMethod · 0.95
getNatureMethod · 0.95
doubleValueMethod · 0.80
intValueMethod · 0.80
getListChangesMethod · 0.65
getObjectContextMethod · 0.65
getAddedMethod · 0.65
isEmptyMethod · 0.65

Tested by

no test coverage detected