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));
}
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;
}
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);
}
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());
}
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);
}
Aggregations