Search in sources :

Example 1 with VarScoped

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) RemoteModifier(pcgen.cdom.content.RemoteModifier) VarScoped(pcgen.base.formula.base.VarScoped) CharID(pcgen.cdom.enumeration.CharID)

Example 2 with VarScoped

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) RemoteModifier(pcgen.cdom.content.RemoteModifier) VarScoped(pcgen.base.formula.base.VarScoped) CharID(pcgen.cdom.enumeration.CharID)

Example 3 with VarScoped

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);
        }
    }
}
Also used : VarScoped(pcgen.base.formula.base.VarScoped)

Example 4 with VarScoped

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);
}
Also used : ASTQuotString(pcgen.base.formula.parse.ASTQuotString) VarScoped(pcgen.base.formula.base.VarScoped) ASTQuotString(pcgen.base.formula.parse.ASTQuotString)

Example 5 with VarScoped

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();
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) VarScoped(pcgen.base.formula.base.VarScoped)

Aggregations

VarScoped (pcgen.base.formula.base.VarScoped)7 ScopeInstance (pcgen.base.formula.base.ScopeInstance)3 CDOMObject (pcgen.cdom.base.CDOMObject)3 RemoteModifier (pcgen.cdom.content.RemoteModifier)3 EquipmentHead (pcgen.cdom.inst.EquipmentHead)3 CharID (pcgen.cdom.enumeration.CharID)2 Equipment (pcgen.core.Equipment)2 LegalScope (pcgen.base.formula.base.LegalScope)1 ASTQuotString (pcgen.base.formula.parse.ASTQuotString)1 ObjectGrouping (pcgen.cdom.base.ObjectGrouping)1 VarModifier (pcgen.cdom.content.VarModifier)1 ParseResult (pcgen.rules.persistence.token.ParseResult)1