Search in sources :

Example 1 with ScopeInstanceFactory

use of pcgen.base.formula.inst.ScopeInstanceFactory in project pcgen by PCGen.

the class DropIntoContext method evaluateFromObject.

private Object evaluateFromObject(EvaluateVisitor visitor, String legalScopeName, VarScoped vs, Node node, EvaluationManager manager) {
    FormulaManager fm = manager.get(EvaluationManager.FMANAGER);
    ScopeInstanceFactory siFactory = fm.getScopeInstanceFactory();
    ScopeInstance scopeInst = siFactory.get(legalScopeName, vs);
    //Rest of Equation
    return node.jjtAccept(visitor, manager.getWith(EvaluationManager.INSTANCE, scopeInst));
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) FormulaManager(pcgen.base.formula.base.FormulaManager) ScopeInstanceFactory(pcgen.base.formula.inst.ScopeInstanceFactory)

Example 2 with ScopeInstanceFactory

use of pcgen.base.formula.inst.ScopeInstanceFactory in project pcgen by PCGen.

the class DropIntoContext method allowFromScopeName.

private FormatManager<?> allowFromScopeName(SemanticsVisitor visitor, FormulaSemantics semantics, String legalScopeName, Node node) {
    FormulaManager fm = semantics.get(FormulaSemantics.FMANAGER);
    ScopeInstanceFactory siFactory = fm.getScopeInstanceFactory();
    LegalScope legalScope = siFactory.getScope(legalScopeName);
    if (legalScope == null) {
        semantics.setInvalid("Parse Error: Invalid Scope Name: " + legalScopeName + " is not a valid scope name");
        return null;
    }
    //Rest of Equation
    semantics = semantics.getWith(FormulaSemantics.FMANAGER, fm);
    semantics = semantics.getWith(FormulaSemantics.SCOPE, legalScope);
    FormatManager<?> format = (FormatManager<?>) node.jjtAccept(visitor, semantics);
    return format;
}
Also used : FormulaManager(pcgen.base.formula.base.FormulaManager) LegalScope(pcgen.base.formula.base.LegalScope) FormatManager(pcgen.base.util.FormatManager) ScopeInstanceFactory(pcgen.base.formula.inst.ScopeInstanceFactory)

Example 3 with ScopeInstanceFactory

use of pcgen.base.formula.inst.ScopeInstanceFactory in project pcgen by PCGen.

the class SetSolverManagerTest method setUp.

@Before
public void setUp() throws Exception {
    FunctionLibrary fl = new SimpleFunctionLibrary();
    fl.addFunction(new DropIntoContext());
    OperatorLibrary ol = new SimpleOperatorLibrary();
    vc = new TrackingVariableCache();
    vsLib = new LegalScopeLibrary();
    EquipmentScope equipScope = new EquipmentScope();
    equipScope.setParent(globalScope);
    vsLib.registerScope(equipScope);
    sl = new VariableLibrary(vsLib);
    arrayManager = new ArrayFormatManager<>(stringManager, ',');
    ManagerFactory managerFactory = new ManagerFactory() {
    };
    siFactory = new ScopeInstanceFactory(vsLib);
    fm = new SimpleFormulaManager(ol, sl, siFactory, vc, new SolverFactory());
    fm = fm.getWith(FormulaManager.FUNCTION, fl);
    SolverFactory solverFactory = new SolverFactory();
    ModifierFactory am1 = new plugin.modifier.set.SetModifierFactory<>();
    PCGenModifier emptyArrayMod = am1.getModifier(0, "", managerFactory, null, globalScope, arrayManager);
    solverFactory.addSolverFormat(arrayManager.getManagedClass(), emptyArrayMod);
    NEPCalculation calc = new ProcessCalculation<>(new Equipment(), new BasicSet(), equipmentManager);
    CalculationModifier em = new CalculationModifier<>(calc, 0);
    solverFactory.addSolverFormat(Equipment.class, em);
    manager = new DynamicSolverManager(fm, managerFactory, solverFactory, vc);
    ModifierFactory mfn = new plugin.modifier.number.SetModifierFactory();
    Modifier mod = mfn.getModifier(0, "0", managerFactory, null, globalScope, numberManager);
    solverFactory.addSolverFormat(numberManager.getManagedClass(), mod);
    ModifierFactory mfs = new plugin.modifier.string.SetModifierFactory();
    Modifier mods = mfs.getModifier(0, "", managerFactory, null, globalScope, stringManager);
    solverFactory.addSolverFormat(stringManager.getManagedClass(), mods);
}
Also used : CalculationModifier(pcgen.base.calculation.CalculationModifier) ProcessCalculation(pcgen.cdom.content.ProcessCalculation) FunctionLibrary(pcgen.base.formula.base.FunctionLibrary) SimpleFunctionLibrary(pcgen.base.formula.inst.SimpleFunctionLibrary) NEPCalculation(pcgen.base.calculation.NEPCalculation) DropIntoContext(plugin.function.DropIntoContext) SimpleFormulaManager(pcgen.base.formula.inst.SimpleFormulaManager) ModifierFactory(pcgen.rules.persistence.token.ModifierFactory) EquipmentScope(pcgen.cdom.formula.scope.EquipmentScope) TrackingVariableCache(pcgen.base.solver.testsupport.TrackingVariableCache) OperatorLibrary(pcgen.base.formula.base.OperatorLibrary) SimpleOperatorLibrary(pcgen.base.formula.inst.SimpleOperatorLibrary) LegalScopeLibrary(pcgen.base.formula.base.LegalScopeLibrary) CalculationModifier(pcgen.base.calculation.CalculationModifier) PCGenModifier(pcgen.base.calculation.PCGenModifier) SimpleOperatorLibrary(pcgen.base.formula.inst.SimpleOperatorLibrary) SimpleFunctionLibrary(pcgen.base.formula.inst.SimpleFunctionLibrary) VariableLibrary(pcgen.base.formula.base.VariableLibrary) ManagerFactory(pcgen.base.formula.base.ManagerFactory) Equipment(pcgen.core.Equipment) ScopeInstanceFactory(pcgen.base.formula.inst.ScopeInstanceFactory) PCGenModifier(pcgen.base.calculation.PCGenModifier) Before(org.junit.Before)

Example 4 with ScopeInstanceFactory

use of pcgen.base.formula.inst.ScopeInstanceFactory in project pcgen by PCGen.

the class InputFunctionTest method testGlobalChannelStrength.

@Test
public void testGlobalChannelStrength() {
    VariableLibrary varLib = variableLibraryFacet.get(id.getDatasetID());
    ScopeInstanceFactory instFactory = scopeFacet.get(id);
    ScopeInstance globalInstance = instFactory.getGlobalInstance("Global");
    varLib.assertLegalVariableID(ChannelUtilities.createVarName("STR"), globalInstance.getLegalScope(), numberManager);
    VariableChannel<Number> strChannel = (VariableChannel<Number>) ChannelUtilities.getGlobalChannel(id, "STR");
    String formula = "input(\"STR\")";
    SimpleNode node = TestUtilities.doParse(formula);
    isValid(formula, node, numberManager, null);
    isStatic(formula, node, false);
    evaluatesTo(formula, node, 0);
    strChannel.set(2);
    evaluatesTo(formula, node, 2);
    Object rv = new ReconstructionVisitor().visit(node, new StringBuilder());
    assertEquals(formula, rv.toString());
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) VariableChannel(pcgen.cdom.formula.VariableChannel) ReconstructionVisitor(pcgen.base.formula.visitor.ReconstructionVisitor) ScopeInstanceFactory(pcgen.base.formula.inst.ScopeInstanceFactory) VariableLibrary(pcgen.base.formula.base.VariableLibrary) SimpleNode(pcgen.base.formula.parse.SimpleNode) Test(org.junit.Test)

Example 5 with ScopeInstanceFactory

use of pcgen.base.formula.inst.ScopeInstanceFactory in project pcgen by PCGen.

the class ChannelUtilities method getChannel.

/**
	 * Retrieves a Channel for the given CharID, owning object, and name of the
	 * channel.
	 * 
	 * @param id
	 *            The CharID identifying the PlayerCharacter on which the
	 *            Channel resides
	 * @param owner
	 *            The owning object of the Channel
	 * @param name
	 *            The name of the channel
	 * @return A Channel for the given CharID, owning object, and name of the
	 *         channel
	 */
public static VariableChannel<?> getChannel(CharID id, VarScoped owner, String name) {
    ScopeInstanceFactory instFactory = SCOPE_FACET.get(id);
    ScopeInstance scopeInst = instFactory.get(owner.getLocalScopeName(), owner);
    return getChannel(id, scopeInst, name);
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) ScopeInstanceFactory(pcgen.base.formula.inst.ScopeInstanceFactory)

Aggregations

ScopeInstanceFactory (pcgen.base.formula.inst.ScopeInstanceFactory)5 ScopeInstance (pcgen.base.formula.base.ScopeInstance)3 FormulaManager (pcgen.base.formula.base.FormulaManager)2 VariableLibrary (pcgen.base.formula.base.VariableLibrary)2 Before (org.junit.Before)1 Test (org.junit.Test)1 CalculationModifier (pcgen.base.calculation.CalculationModifier)1 NEPCalculation (pcgen.base.calculation.NEPCalculation)1 PCGenModifier (pcgen.base.calculation.PCGenModifier)1 FunctionLibrary (pcgen.base.formula.base.FunctionLibrary)1 LegalScope (pcgen.base.formula.base.LegalScope)1 LegalScopeLibrary (pcgen.base.formula.base.LegalScopeLibrary)1 ManagerFactory (pcgen.base.formula.base.ManagerFactory)1 OperatorLibrary (pcgen.base.formula.base.OperatorLibrary)1 SimpleFormulaManager (pcgen.base.formula.inst.SimpleFormulaManager)1 SimpleFunctionLibrary (pcgen.base.formula.inst.SimpleFunctionLibrary)1 SimpleOperatorLibrary (pcgen.base.formula.inst.SimpleOperatorLibrary)1 SimpleNode (pcgen.base.formula.parse.SimpleNode)1 ReconstructionVisitor (pcgen.base.formula.visitor.ReconstructionVisitor)1 TrackingVariableCache (pcgen.base.solver.testsupport.TrackingVariableCache)1