use of pcgen.util.enumeration.Visibility in project pcgen by PCGen.
the class PCSkillTypeTermEvaluator method resolve.
@Override
public Float resolve(PlayerCharacter pc) {
int count = 0;
Collection<Skill> skills = pc.getDisplay().getSkillSet();
for (Skill sk : skills) {
Visibility skVis = sk.getSafe(ObjectKey.VISIBILITY);
//TODO This is a bug, it assumes export
if (!skVis.isVisibleTo(View.HIDDEN_EXPORT) && sk.isType(type) && sk.qualifies(pc, null)) {
count++;
}
}
return (float) count;
}
use of pcgen.util.enumeration.Visibility in project pcgen by PCGen.
the class VisibleToken method unparse.
@Override
public String[] unparse(LoadContext context, ContentDefinition factDef) {
Visibility vis = factDef.getVisibility();
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 a Fact Definition");
return null;
}
return new String[] { visString };
}
use of pcgen.util.enumeration.Visibility in project pcgen by PCGen.
the class VisibleToken method unparse.
@Override
public String[] unparse(LoadContext context, Skill skill) {
Visibility vis = context.getObjectContext().getObject(skill, ObjectKey.VISIBILITY);
if (vis == null) {
return null;
}
if (!vis.equals(Visibility.DEFAULT) && !vis.equals(Visibility.DISPLAY_ONLY) && !vis.equals(Visibility.OUTPUT_ONLY)) {
context.addWriteMessage("Visibility " + vis + " is not a valid Visibility for a Skill");
return null;
}
StringBuilder sb = new StringBuilder();
sb.append(vis.getLSTFormat());
Boolean readOnly = context.getObjectContext().getObject(skill, ObjectKey.READ_ONLY);
if (readOnly != null) {
if (!vis.equals(Visibility.OUTPUT_ONLY)) {
/*
* Don't barf if OUTPUT and READONLY as .MOD will cause that to
* happen
*/
sb.append('|').append("READONLY");
}
}
return new String[] { sb.toString() };
}
use of pcgen.util.enumeration.Visibility in project pcgen by PCGen.
the class VisibleToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Skill skill, String value) {
String visString = value;
int pipeLoc = value.indexOf(Constants.PIPE);
boolean readOnly = false;
if (pipeLoc != -1) {
if (value.substring(pipeLoc + 1).equals("READONLY")) {
visString = value.substring(0, pipeLoc);
readOnly = true;
} else {
return new ParseResult.Fail("Misunderstood text after pipe on Tag: " + value, context);
}
}
Visibility vis;
if (visString.equals("YES")) {
vis = Visibility.DEFAULT;
} else if (visString.equals("ALWAYS")) {
vis = Visibility.DEFAULT;
} else if (visString.equals("DISPLAY")) {
vis = Visibility.DISPLAY_ONLY;
} else if (visString.equals("GUI")) {
vis = Visibility.DISPLAY_ONLY;
} else if (visString.equals("EXPORT")) {
vis = Visibility.OUTPUT_ONLY;
} else if (visString.equals("CSHEET")) {
vis = Visibility.OUTPUT_ONLY;
} else if (visString.equals("NO")) {
vis = Visibility.HIDDEN;
} else {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Unexpected value used in " + getTokenName() + " in Skill");
cpr.addErrorMessage(" " + value + " is not a valid value for " + getTokenName());
cpr.addErrorMessage(" Valid values in Skill are YES, ALWAYS, NO, DISPLAY, GUI, EXPORT, CSHEET");
return cpr;
}
context.getObjectContext().put(skill, ObjectKey.VISIBILITY, vis);
if (readOnly) {
if (vis.equals(Visibility.OUTPUT_ONLY)) {
return new ParseResult.Fail("|READONLY suffix not valid with " + getTokenName() + " EXPORT or CSHEET", context);
}
context.getObjectContext().put(skill, ObjectKey.READ_ONLY, Boolean.TRUE);
}
return ParseResult.SUCCESS;
}
use of pcgen.util.enumeration.Visibility in project pcgen by PCGen.
the class SkillDisplay method getSkillListInOutputOrder.
/**
* Retrieves a list of the character's skills in output order. This is in
* ascending order of the skill's outputIndex field. If skills have the same
* outputIndex they will be ordered by name. Note hidden skills (outputIndex =
* -1) are not included in this list.
*
* @param skills A list of skills which will be sorted, filtered and returned
*
* @return An ArrayList of the skill objects in output order.
*/
public static List<Skill> getSkillListInOutputOrder(final PlayerCharacter pc, final List<Skill> skills) {
skills.sort(new Comparator<Skill>() {
/**
* Comparator will be specific to Skill objects
*/
@Override
public int compare(final Skill skill1, final Skill skill2) {
Integer obj1Index = pc.getSkillOrder(skill1);
Integer obj2Index = pc.getSkillOrder(skill2);
// Force unset items (index of 0) to appear at the end
if (obj1Index == null || obj1Index == 0) {
obj1Index = Constants.ARBITRARY_END_SKILL_INDEX;
}
if (obj2Index == null || obj2Index == 0) {
obj2Index = Constants.ARBITRARY_END_SKILL_INDEX;
}
if (obj1Index > obj2Index) {
return 1;
} else if (obj1Index < obj2Index) {
return -1;
} else {
return skill1.getOutputName().compareToIgnoreCase(skill2.getOutputName());
}
}
});
// Remove the hidden skills from the list
for (Iterator<Skill> i = skills.iterator(); i.hasNext(); ) {
final Skill bSkill = i.next();
Visibility skVis = bSkill.getSafe(ObjectKey.VISIBILITY);
Integer outputIndex = pc.getSkillOrder(bSkill);
if ((outputIndex != null && outputIndex == -1) || skVis.isVisibleTo(View.HIDDEN_EXPORT) || !bSkill.qualifies(pc, null)) {
i.remove();
}
}
return skills;
}
Aggregations