use of pcgen.util.enumeration.Visibility in project pcgen by PCGen.
the class BasePCCountAbilitiesTermEvaluator method countVisibleAbility.
/**
* Count the number of times the character has the ability. This can be
* limited to either hidden or visible Abilities, and can be limited to only
* counting once per ability rather than once per time taken (e.g.
* Weapon Specialisation in two weapons would count as 2 unless the onceOnly
* flag was true).
*
* @param pc the Character with the abilities
* @param cna The feat to be counted.
* @param visible Should it be counted if it is visible?
* @param hidden Should it be counted if it is hidden?
* @param onceOnly Should it be counted as one if was taken multiple times?
* @return The number of occurrences of the ability.
*/
protected Float countVisibleAbility(PlayerCharacter pc, final CNAbility cna, final boolean visible, final boolean hidden, final boolean onceOnly) {
Visibility v = cna.getAbility().getSafe(ObjectKey.VISIBILITY);
//TODO This is a bug, it assumes export
boolean abilityInvisibile = v.isVisibleTo(View.HIDDEN_EXPORT);
int count = 0;
if (abilityInvisibile) {
if (hidden) {
count += onceOnly ? 1 : Math.max(1, pc.getSelectCorrectedAssociationCount(cna));
}
} else {
if (visible) {
count += onceOnly ? 1 : Math.max(1, pc.getSelectCorrectedAssociationCount(cna));
}
}
return (float) count;
}
use of pcgen.util.enumeration.Visibility in project pcgen by PCGen.
the class ContentDefinition method activate.
/**
* Activates this ContentDefinition by performing the necessary steps to
* link it to other subsystems.
*
* @param context
* The LoadContext to initialize with tokens, if required
*/
public void activate(LoadContext context) {
activateKey();
Visibility vis = (visibility == null) ? Visibility.HIDDEN : visibility;
if (vis.isVisibleTo(View.VISIBLE_EXPORT)) {
activateOutput(context.getDataSetID());
}
activateTokens(context);
}
use of pcgen.util.enumeration.Visibility in project pcgen by PCGen.
the class Gui2InfoFactory method appendFacts.
private void appendFacts(HtmlInfoBuilder infoText, CDOMObject cdo) {
Class<? extends CDOMObject> cl = cdo.getClass();
LoadContext context = Globals.getContext();
Collection<FactDefinition> defs = context.getReferenceContext().getConstructedCDOMObjects(FactDefinition.class);
for (FactDefinition<?, ?> def : defs) {
if (def.getUsableLocation().isAssignableFrom(cl)) {
Visibility visibility = def.getVisibility();
if (visibility != null && visibility.isVisibleTo(View.VISIBLE_DISPLAY)) {
FactKey<?> fk = def.getFactKey();
Indirect<?> fact = cdo.get(fk);
if (fact != null) {
infoText.appendSpacer();
infoText.append("<b>");
infoText.append(fk.toString());
infoText.append(":</b> ");
infoText.append(fact.getUnconverted());
}
}
}
}
Collection<FactSetDefinition> setdefs = context.getReferenceContext().getConstructedCDOMObjects(FactSetDefinition.class);
for (FactSetDefinition<?, ?> def : setdefs) {
if (def.getUsableLocation().isAssignableFrom(cl)) {
Visibility visibility = def.getVisibility();
if (visibility != null && visibility.isVisibleTo(View.VISIBLE_DISPLAY)) {
FactSetKey<?> fk = def.getFactSetKey();
String s = getSetString(cdo, fk);
if (s != null) {
infoText.appendSpacer();
infoText.append("<b>");
infoText.append(fk.toString());
infoText.append(":</b> ");
infoText.append(s);
}
}
}
}
}
use of pcgen.util.enumeration.Visibility in project pcgen by PCGen.
the class VisibleToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, PCClass pcc, String value) {
Visibility vis;
if (value.equals("NO")) {
vis = Visibility.HIDDEN;
} else if (value.equalsIgnoreCase("Y") || value.equals("YES")) {
vis = Visibility.DEFAULT;
} else {
return new ParseResult.Fail("Can't understand Visibility: " + value, context);
}
context.getObjectContext().put(pcc, ObjectKey.VISIBILITY, vis);
return ParseResult.SUCCESS;
}
use of pcgen.util.enumeration.Visibility in project pcgen by PCGen.
the class VisibleToken method unparse.
@Override
public String[] unparse(LoadContext context, Ability ability) {
Visibility vis = context.getObjectContext().getObject(ability, ObjectKey.VISIBILITY);
if (vis == null) {
return null;
}
String visString;
if (vis.equals(Visibility.DEFAULT)) {
visString = "YES";
} else if (vis.equals(Visibility.DISPLAY_ONLY)) {
visString = "DISPLAY";
} else if (vis.equals(Visibility.OUTPUT_ONLY)) {
visString = "EXPORT";
} else if (vis.equals(Visibility.HIDDEN)) {
visString = "NO";
} else {
context.addWriteMessage("Visibility " + vis + " is not a valid Visibility for an Ability");
return null;
}
return new String[] { visString };
}
Aggregations