Search in sources :

Example 1 with AspectName

use of pcgen.cdom.enumeration.AspectName in project pcgen by PCGen.

the class AbilityToken method getAspectString.

/**
	 * Gets the aspect string.
	 * 
	 * @param pc
	 *            The character being exported.
	 * @param ability
	 *            The ability
	 * 
	 * @return the aspect string
	 */
private String getAspectString(PlayerCharacter pc, List<CNAbility> abilities) {
    if (abilities.isEmpty()) {
        return "";
    }
    Ability sampleAbilityObject = abilities.get(0).getAbility();
    Set<AspectName> aspectKeys = sampleAbilityObject.getKeysFor(MapKey.ASPECT);
    SortedSet<AspectName> sortedKeys = new TreeSet<>(aspectKeys);
    StringBuilder buff = new StringBuilder();
    for (AspectName key : sortedKeys) {
        if (buff.length() > 0) {
            buff.append(", ");
        }
        buff.append(Aspect.printAspect(pc, key, abilities));
    }
    return buff.toString();
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) AspectName(pcgen.cdom.enumeration.AspectName) TreeSet(java.util.TreeSet)

Example 2 with AspectName

use of pcgen.cdom.enumeration.AspectName in project pcgen by PCGen.

the class AspectToken method unparse.

/*
	 * (non-Javadoc)
	 * 
	 * @see pcgen.rules.persistence.token.CDOMPrimaryParserToken#unparse(pcgen.rules.context.LoadContext,
	 *      java.lang.Object)
	 */
@Override
public String[] unparse(LoadContext context, Ability ability) {
    MapChanges<AspectName, List<Aspect>> changes = context.getObjectContext().getMapChanges(ability, MapKey.ASPECT);
    if (changes == null || changes.isEmpty()) {
        return null;
    }
    Set<String> set = new TreeSet<>();
    Set<AspectName> keys = changes.getAdded().keySet();
    for (AspectName an : keys) {
        List<Aspect> aspects = changes.getAdded().get(an);
        for (int i = 0; i < aspects.size(); i++) {
            Aspect q = aspects.get(i);
            set.add(new StringBuilder().append(q.getName()).append(Constants.PIPE).append(q.getPCCText()).toString());
        }
    }
    return set.toArray(new String[set.size()]);
}
Also used : AspectName(pcgen.cdom.enumeration.AspectName) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List) Aspect(pcgen.cdom.helper.Aspect)

Example 3 with AspectName

use of pcgen.cdom.enumeration.AspectName in project pcgen by PCGen.

the class AbilityToken method getAspectString.

/**
	 * Gets the aspect string for an aspect identified by position or name.
	 * 
	 * @param pc
	 *            The character being exported.
	 * @param ability
	 *            The ability being queried.
	 * @param key
	 *            The key (number or name) of the aspect to retrieve
	 * 
	 * @return the aspect string
	 */
private String getAspectString(PlayerCharacter pc, List<CNAbility> abilities, String key) {
    if (key == null) {
        return "";
    }
    if (abilities.isEmpty()) {
        return "";
    }
    Ability sampleAbilityObject = abilities.get(0).getAbility();
    try {
        int index = Integer.parseInt(key);
        if ((index >= 0) && (index < sampleAbilityObject.getSafeSizeOfMapFor(MapKey.ASPECT))) {
            Set<AspectName> aspectKeys = sampleAbilityObject.getKeysFor(MapKey.ASPECT);
            List<AspectName> sortedKeys = new ArrayList<>(aspectKeys);
            Collections.sort(sortedKeys);
            AspectName aspectName = sortedKeys.get(index);
            return Aspect.printAspect(pc, aspectName, abilities);
        } else {
            return "";
        }
    } catch (NumberFormatException e) {
        // Ignore exception - expect this as we can get a String at this point
        AspectName aspectName = AspectName.getConstant(key);
        return Aspect.printAspectValue(pc, aspectName, abilities);
    }
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) AspectName(pcgen.cdom.enumeration.AspectName) ArrayList(java.util.ArrayList)

Example 4 with AspectName

use of pcgen.cdom.enumeration.AspectName in project pcgen by PCGen.

the class AspectToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Ability ability, String value) {
    int pipeLoc = value.indexOf(Constants.PIPE);
    if (pipeLoc == -1) {
        return new ParseResult.Fail(getTokenName() + " expecting '|', format is: " + "AspectName|Aspect value|Variable|... was: " + value, context);
    }
    String key = value.substring(0, pipeLoc);
    if (key.isEmpty()) {
        return new ParseResult.Fail(getTokenName() + " expecting non-empty type, " + "format is: AspectName|Aspect value|Variable|... was: " + value, context);
    }
    String val = value.substring(pipeLoc + 1);
    if (val.isEmpty()) {
        return new ParseResult.Fail(getTokenName() + " expecting non-empty value, " + "format is: AspectName|Aspect value|Variable|... was: " + value, context);
    }
    if (val.startsWith(Constants.PIPE)) {
        return new ParseResult.Fail(getTokenName() + " expecting non-empty value, " + "format is: AspectName|Aspect value|Variable|... was: " + value, context);
    }
    Aspect a = parseAspect(key, val);
    MapChanges<AspectName, List<Aspect>> mc = context.getObjectContext().getMapChanges(ability, MapKey.ASPECT);
    Map<AspectName, List<Aspect>> fullMap = mc.getAdded();
    List<Aspect> aspects = fullMap.get(a.getKey());
    if (aspects == null) {
        aspects = new ArrayList<>();
    }
    aspects.add(a);
    context.getObjectContext().put(ability, MapKey.ASPECT, a.getKey(), aspects);
    return ParseResult.SUCCESS;
}
Also used : AspectName(pcgen.cdom.enumeration.AspectName) ArrayList(java.util.ArrayList) List(java.util.List) Aspect(pcgen.cdom.helper.Aspect)

Example 5 with AspectName

use of pcgen.cdom.enumeration.AspectName in project pcgen by PCGen.

the class Gui2InfoFactory method getHTMLInfo.

/**
	 * @see pcgen.core.facade.InfoFactory#getHTMLInfo(pcgen.core.facade.AbilityFacade)
	 */
@Override
public String getHTMLInfo(AbilityFacade abilityFacade) {
    if (!(abilityFacade instanceof Ability)) {
        return EMPTY_STRING;
    }
    Ability ability = (Ability) abilityFacade;
    final HtmlInfoBuilder infoText = new HtmlInfoBuilder();
    infoText.appendTitleElement(OutputNameFormatting.piString(ability, false));
    infoText.appendLineBreak();
    //$NON-NLS-1$
    infoText.appendI18nFormattedElement(//$NON-NLS-1$
    "Ability.Info.Type", //$NON-NLS-1$
    StringUtil.join(ability.getTrueTypeList(true), ". "));
    BigDecimal costStr = ability.getSafe(ObjectKey.SELECTION_COST);
    if (//$NON-NLS-1$
    !costStr.equals(BigDecimal.ONE)) {
        //$NON-NLS-1$
        infoText.appendI18nFormattedElement(//$NON-NLS-1$
        "Ability.Info.Cost", COST_FMT.format(costStr));
    }
    if (ability.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
        infoText.appendSpacer();
        //$NON-NLS-1$
        infoText.append(LanguageBundle.getString("Ability.Info.Multiple"));
    }
    if (ability.getSafe(ObjectKey.STACKS)) {
        infoText.appendSpacer();
        //$NON-NLS-1$
        infoText.append(LanguageBundle.getString("Ability.Info.Stacks"));
    }
    appendFacts(infoText, ability);
    final String cString = PrerequisiteUtilities.preReqHTMLStringsForList(pc, null, ability.getPrerequisiteList(), false);
    if (!cString.isEmpty()) {
        //$NON-NLS-1$
        infoText.appendI18nFormattedElement(//$NON-NLS-1$
        "in_InfoRequirements", cString);
    }
    infoText.appendLineBreak();
    //$NON-NLS-1$
    infoText.appendI18nFormattedElement(//$NON-NLS-1$
    "in_InfoDescription", getDescription(abilityFacade));
    List<CNAbility> wrappedAbility = getWrappedAbility(ability);
    if (ability.getSafeSizeOfMapFor(MapKey.ASPECT) > 0) {
        Set<AspectName> aspectKeys = ability.getKeysFor(MapKey.ASPECT);
        StringBuilder buff = new StringBuilder(100);
        for (AspectName key : aspectKeys) {
            if (buff.length() > 0) {
                buff.append(", ");
            }
            //Assert here that the actual text displayed is not critical
            buff.append(Aspect.printAspect(pc, key, wrappedAbility));
        }
        infoText.appendLineBreak();
        //$NON-NLS-1$
        infoText.appendI18nFormattedElement(//$NON-NLS-1$
        "Ability.Info.Aspects", buff.toString());
    }
    final String bene = BenefitFormatting.getBenefits(pc, wrappedAbility);
    if (bene != null && !bene.isEmpty()) {
        infoText.appendLineBreak();
        //$NON-NLS-1$
        infoText.appendI18nFormattedElement(//$NON-NLS-1$
        "Ability.Info.Benefit", BenefitFormatting.getBenefits(pc, wrappedAbility));
    }
    infoText.appendLineBreak();
    //$NON-NLS-1$
    infoText.appendI18nFormattedElement(//$NON-NLS-1$
    "in_InfoSource", ability.getSource());
    return infoText.toString();
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) AspectName(pcgen.cdom.enumeration.AspectName) HtmlInfoBuilder(pcgen.gui2.util.HtmlInfoBuilder) BigDecimal(java.math.BigDecimal)

Aggregations

AspectName (pcgen.cdom.enumeration.AspectName)5 ArrayList (java.util.ArrayList)3 CNAbility (pcgen.cdom.content.CNAbility)3 Ability (pcgen.core.Ability)3 List (java.util.List)2 TreeSet (java.util.TreeSet)2 Aspect (pcgen.cdom.helper.Aspect)2 BigDecimal (java.math.BigDecimal)1 HtmlInfoBuilder (pcgen.gui2.util.HtmlInfoBuilder)1