use of pcgen.base.formula.base.ScopeInstance 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.base.ScopeInstance in project pcgen by PCGen.
the class FaceToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Race race, String value) {
if (ControlUtilities.hasControlToken(context, CControl.FACE)) {
return new ParseResult.Fail("FACE: LST Token is disabled when FACE: control is used", context);
}
if (value.indexOf(',') == -1) {
value = value + ',' + 0;
}
FormatManager<OrderedPair> formatManager = (FormatManager<OrderedPair>) context.getReferenceContext().getFormatManager("ORDEREDPAIR");
ScopeInstance scopeInst = context.getActiveScope();
LegalScope scope = scopeInst.getLegalScope();
PCGenModifier<OrderedPair> modifier;
try {
modifier = context.getVariableContext().getModifier(MOD_IDENTIFICATION, value, MOD_PRIORITY, scope, formatManager);
} catch (IllegalArgumentException iae) {
return new ParseResult.Fail(getTokenName() + " Modifier " + MOD_IDENTIFICATION + " had value " + value + " but it was not valid: " + iae.getMessage(), context);
}
OrderedPair pair = modifier.process(null);
if (pair.getPreciseX().doubleValue() < 0.0) {
return new ParseResult.Fail(getTokenName() + " had value " + value + " but first item cannot be negative", context);
}
if (pair.getPreciseY().doubleValue() < 0.0) {
return new ParseResult.Fail(getTokenName() + " had value " + value + " but second item cannot be negative", context);
}
if (!context.getVariableContext().isLegalVariableID(scope, VAR_NAME)) {
return new ParseResult.Fail(getTokenName() + " internal error: found invalid var name: " + VAR_NAME + ", Modified on " + race.getClass().getSimpleName() + ' ' + race.getKeyName(), context);
}
VarModifier<OrderedPair> vm = new VarModifier<>(VAR_NAME, scope, modifier);
context.getObjectContext().addToList(race, ListKey.MODIFY, vm);
return ParseResult.SUCCESS;
}
use of pcgen.base.formula.base.ScopeInstance in project pcgen by PCGen.
the class ModifyLst method finishProcessing.
private <T> ParseResult finishProcessing(LoadContext context, CDOMObject obj, FormatManager<T> formatManager, String varName, String modIdentification, String modInstructions, int priorityNumber) {
ScopeInstance scopeInst = context.getActiveScope();
LegalScope scope = scopeInst.getLegalScope();
PCGenModifier<T> modifier;
try {
modifier = context.getVariableContext().getModifier(modIdentification, modInstructions, priorityNumber, scope, formatManager);
} catch (IllegalArgumentException iae) {
return new ParseResult.Fail(getTokenName() + " Modifier " + modIdentification + " had value " + modInstructions + " but it was not valid: " + iae.getMessage(), context);
}
VarModifier<T> vm = new VarModifier<>(varName, scope, modifier);
context.getObjectContext().addToList(obj, ListKey.MODIFY, vm);
return ParseResult.SUCCESS;
}
use of pcgen.base.formula.base.ScopeInstance in project pcgen by PCGen.
the class FaceToken method parseFace.
protected ParseResult parseFace(LoadContext context, PCTemplate fObj, String value) {
if (ControlUtilities.hasControlToken(context, CControl.FACE)) {
return new ParseResult.Fail("FACE: LST Token is disabled when FACE: control is used", context);
}
if (value.indexOf(',') == -1) {
value = value + ',' + 0;
}
@SuppressWarnings("unchecked") FormatManager<OrderedPair> formatManager = (FormatManager<OrderedPair>) context.getReferenceContext().getFormatManager("ORDEREDPAIR");
ScopeInstance scopeInst = context.getActiveScope();
LegalScope scope = scopeInst.getLegalScope();
PCGenModifier<OrderedPair> modifier;
try {
modifier = context.getVariableContext().getModifier(MOD_IDENTIFICATION, value, MOD_PRIORITY, scope, formatManager);
} catch (IllegalArgumentException iae) {
return new ParseResult.Fail(getTokenName() + " Modifier SET had value " + value + " but it was not valid: " + iae.getMessage(), context);
}
OrderedPair pair = modifier.process(null);
if (pair.getPreciseX().doubleValue() < 0.0) {
return new ParseResult.Fail(getTokenName() + " had value " + value + " but first item cannot be negative", context);
}
if (pair.getPreciseY().doubleValue() < 0.0) {
return new ParseResult.Fail(getTokenName() + " had value " + value + " but second item cannot be negative", context);
}
String varName = VAR_NAME;
if (!context.getVariableContext().isLegalVariableID(scope, varName)) {
return new ParseResult.Fail(getTokenName() + " internal error: found invalid fact name: " + varName + ", Modified on " + fObj.getClass().getSimpleName() + ' ' + fObj.getKeyName(), context);
}
VarModifier<OrderedPair> vm = new VarModifier<>(varName, scope, modifier);
context.getObjectContext().addToList(fObj, ListKey.MODIFY, vm);
return ParseResult.SUCCESS;
}
use of pcgen.base.formula.base.ScopeInstance in project pcgen by PCGen.
the class SetSolverManagerTest method testProcessDependentSet.
@Test
public void testProcessDependentSet() {
sl.assertLegalVariableID("Regions", globalScope, arrayManager);
ScopeInstance scopeInst = siFactory.getGlobalInstance(globalScope.getName());
VariableID<String[]> regions = (VariableID<String[]>) sl.getVariableID(scopeInst, "Regions");
manager.createChannel(regions);
Object[] array = vc.get(regions);
List<Object> list = Arrays.asList(array);
assertEquals(0, array.length);
assertTrue(vc.set.contains(regions));
assertEquals(1, vc.set.size());
vc.reset();
ModifierFactory am1 = new plugin.modifier.set.AddModifierFactory<>();
PCGenModifier mod = am1.getModifier(2000, "France,England", new ManagerFactory() {
}, null, globalScope, arrayManager);
manager.addModifier(regions, mod, scopeInst);
array = vc.get(regions);
assertThat(2, is(array.length));
list = Arrays.asList(array);
assertTrue(list.contains("England"));
assertTrue(list.contains("France"));
assertTrue(vc.set.contains(regions));
assertEquals(1, vc.set.size());
vc.reset();
ModifierFactory am2 = new plugin.modifier.set.AddModifierFactory<>();
mod = am2.getModifier(3000, "Greece,England", new ManagerFactory() {
}, null, globalScope, arrayManager);
manager.addModifier(regions, mod, scopeInst);
array = vc.get(regions);
assertThat(3, is(array.length));
list = Arrays.asList(array);
assertTrue(list.contains("England"));
assertTrue(list.contains("France"));
assertTrue(list.contains("Greece"));
assertTrue(vc.set.contains(regions));
assertEquals(1, vc.set.size());
vc.reset();
}
Aggregations