use of pcgen.base.formula.base.VarScoped in project pcgen by PCGen.
the class RemoteModifierFacet method dataAdded.
@Override
public void dataAdded(DataFacetChangeEvent<CharID, VarScoped> dfce) {
CharID id = dfce.getCharID();
VarScoped vs = dfce.getCDOMObject();
/*
* If this can have local variables, find what may have been modified by
* previous objects
*/
for (RemoteModifier<?> rm : getSet(id)) {
VarScoped src = get(id, rm);
ScopeInstance inst = scopeFacet.get(id, src);
processAdd(id, rm, vs, inst);
if (vs instanceof Equipment) {
Equipment e = (Equipment) vs;
for (EquipmentHead head : e.getEquipmentHeads()) {
processAdd(id, rm, head, inst);
}
}
}
/*
* Look at what newly added object can modify on others
*/
if (vs instanceof CDOMObject) {
ScopeInstance inst = scopeFacet.get(id, vs);
List<RemoteModifier<?>> list = ((CDOMObject) vs).getListFor(ListKey.REMOTE_MODIFIER);
if (list != null) {
Set<? extends VarScoped> targets = varScopedFacet.getSet(id);
for (RemoteModifier<?> rm : list) {
set(id, rm, vs);
//Apply to existing as necessary
for (VarScoped obj : targets) {
processAdd(id, rm, obj, inst);
if (obj instanceof Equipment) {
Equipment e = (Equipment) obj;
for (EquipmentHead head : e.getEquipmentHeads()) {
processAdd(id, rm, head, inst);
}
}
}
}
}
}
}
use of pcgen.base.formula.base.VarScoped in project pcgen by PCGen.
the class RemoteModifierFacet method dataRemoved.
@Override
public void dataRemoved(DataFacetChangeEvent<CharID, VarScoped> dfce) {
CharID id = dfce.getCharID();
VarScoped vs = dfce.getCDOMObject();
/*
* If this can have local variables, find what had been modified by
* previous objects
*/
for (RemoteModifier<?> rm : getSet(id)) {
VarScoped src = get(id, rm);
ScopeInstance inst = scopeFacet.get(id, src);
processRemove(id, rm, vs, inst);
if (vs instanceof Equipment) {
Equipment e = (Equipment) vs;
for (EquipmentHead head : e.getEquipmentHeads()) {
processRemove(id, rm, head, inst);
}
}
}
/*
* Look at what newly added object can modify on others
*/
if (vs instanceof CDOMObject) {
ScopeInstance inst = scopeFacet.get(id, vs);
List<RemoteModifier<?>> list = ((CDOMObject) vs).getListFor(ListKey.REMOTE_MODIFIER);
if (list != null) {
Set<? extends VarScoped> targets = varScopedFacet.getSet(id);
for (RemoteModifier<?> rm : list) {
remove(id, rm);
//RemoveFrom existing as necessary
for (VarScoped obj : targets) {
processRemove(id, rm, obj, inst);
if (obj instanceof Equipment) {
Equipment e = (Equipment) obj;
for (EquipmentHead head : e.getEquipmentHeads()) {
processRemove(id, rm, head, inst);
}
}
}
}
}
}
}
use of pcgen.base.formula.base.VarScoped in project pcgen by PCGen.
the class SolverViewFrame method updateObjects.
private void updateObjects() {
if (activeIdentifier != null) {
Collection<VarScoped> objects = scopeFacet.getObjectsWithVariables(activeIdentifier);
objectChooser.removeAllItems();
String scopeName = selectedScope.getName();
for (VarScoped cdo : objects) {
if (cdo.getLocalScopeName().equals(scopeName)) {
if (scopeFacet.get(activeIdentifier, selectedScope.getName(), cdo) != null) {
objectChooser.addItem(new ObjectNameDisplayer(cdo));
}
}
}
if (objectChooser.getItemCount() != 0) {
objectChooser.setSelectedIndex(0);
}
}
}
use of pcgen.base.formula.base.VarScoped in project pcgen by PCGen.
the class DropIntoContext method evaluate.
@Override
public Object evaluate(EvaluateVisitor visitor, Node[] args, EvaluationManager manager) {
ASTQuotString qs = (ASTQuotString) args[0];
String legalScopeName = qs.getText();
Object result = args[1].jjtAccept(visitor, manager);
VarScoped vs;
if (result instanceof String) {
Class<? extends Loadable> objClass = StringPClassUtil.getClassFor(legalScopeName);
vs = (VarScoped) manager.get(ManagerKey.CONTEXT).getReferenceContext().silentlyGetConstructedCDOMObject(objClass, (String) result);
} else if (result instanceof VarScoped) {
vs = (VarScoped) result;
} else {
throw new IllegalStateException("result must be String or VarScoped");
}
return evaluateFromObject(visitor, legalScopeName, vs, args[2], manager);
}
use of pcgen.base.formula.base.VarScoped in project pcgen by PCGen.
the class ObjectNameDisplayer method toString.
/**
* Returns an informative String identifying the VarScoped underlying this
* ObjectNameDisplayer
*
*/
@Override
public String toString() {
Class<? extends VarScoped> objClass = obj.getClass();
String suffix = null;
VarScoped object = obj;
if (EquipmentHead.class.equals(objClass)) {
EquipmentHead head = (EquipmentHead) obj;
int index = head.getHeadIndex();
objClass = Equipment.class;
object = (Equipment) head.getOwner();
suffix = "Part: " + index;
}
StringBuilder sb = new StringBuilder();
sb.append(objClass.getSimpleName()).append(" ");
sb.append(object.getKeyName());
if (suffix != null) {
sb.append(" (").append(suffix).append(")");
}
return sb.toString();
}
Aggregations