Permalink
Browse files

Merge pull request #1946 from thpr/NEWTAG-596-H

NEWTAG-596 add dropIntoContext function
  • Loading branch information...
2 parents 88d5014 + beb9e35 commit a1af4c911c6aa73913612428ba80fb6ccedde162 @thpr thpr committed on GitHub Jan 9, 2017
View
@@ -44,3 +44,4 @@ data/customsources/*
!data/customsources/readme-customsources.txt
/.nb-gradle/
/jre/
+/.checkstyle
View
@@ -159,7 +159,7 @@ dependencies {
compile group: 'com.incors.plaf', name: 'kunststoff', version:'2.0.2'
compile group: 'net.sourceforge.argparse4j', name: 'argparse4j', version: '0.7.0'
compile group: 'net.sourceforge.pcgen', name: 'PCGen-base', version:'1.0.83'
- compile group: 'net.sourceforge.pcgen', name: 'PCGen-Formula', version:'1.0.95'
+ compile group: 'net.sourceforge.pcgen', name: 'PCGen-Formula', version:'1.0.101'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'
runtime group: 'ch.qos.logback', name: 'logback-classic', version:'1.1.6'
@@ -22,17 +22,17 @@
import pcgen.base.formula.base.ScopeInstance;
import pcgen.base.formula.base.VarScoped;
import pcgen.base.formula.base.VariableID;
-import pcgen.base.solver.AggressiveSolverManager;
import pcgen.base.solver.ProcessStep;
+import pcgen.base.solver.SolverManager;
import pcgen.cdom.content.VarModifier;
import pcgen.cdom.enumeration.CharID;
import pcgen.cdom.facet.base.AbstractItemFacet;
/**
- * This stores the AggressiveSolverManager for each PlayerCharacter.
+ * This stores the SolverManager for each PlayerCharacter.
*/
public class SolverManagerFacet extends
- AbstractItemFacet<CharID, AggressiveSolverManager>
+ AbstractItemFacet<CharID, SolverManager>
{
private VariableLibraryFacet variableLibraryFacet;
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) Thomas Parker, 2016.
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package pcgen.cdom.formula;
+
+import pcgen.base.util.TypedKey;
+import pcgen.rules.context.LoadContext;
+
+public class ManagerKey
+{
+ public static final TypedKey<LoadContext> CONTEXT = new TypedKey<>();
+}
@@ -22,7 +22,7 @@
import javax.swing.event.EventListenerList;
import pcgen.base.formula.base.VariableID;
-import pcgen.base.solver.AggressiveSolverManager;
+import pcgen.base.solver.SolverManager;
import pcgen.facade.util.WriteableReferenceFacade;
import pcgen.facade.util.event.ReferenceEvent;
import pcgen.facade.util.event.ReferenceListener;
@@ -39,9 +39,9 @@
{
/**
- * The underlying AggressiveSolverManager that solves the given VariableID
+ * The underlying SolverManager that solves the given VariableID
*/
- private final AggressiveSolverManager manager;
+ private final SolverManager manager;
/**
* The VariableID indicating to which Variable this VariableChannel is
@@ -51,7 +51,7 @@
/**
* The MonitorableVariableStore that the results of the calculations by the
- * AggressiveSolverManager are placed in.
+ * SolverManager are placed in.
*/
private final MonitorableVariableStore varStore;
@@ -62,21 +62,21 @@
private final EventListenerList listenerList = new EventListenerList();
/**
- * Constructs a new VariableChannel with the given AggressiveSolverManager,
+ * Constructs a new VariableChannel with the given SolverManager,
* MonitorableVariableStore, and VariableID indicating the contents of the
* Channel.
*
* @param manager
- * The underlying AggressiveSolverManager that solves the given
+ * The underlying SolverManager that solves the given
* VariableID
* @param varStore
* The MonitorableVariableStore that the results of the
- * calculations by the AggressiveSolverManager are placed in
+ * calculations by the SolverManager are placed in
* @param varID
* The VariableID indicating to which Variable this
* VariableChannel is providing an interface
*/
- private VariableChannel(AggressiveSolverManager manager,
+ private VariableChannel(SolverManager manager,
MonitorableVariableStore varStore, VariableID<T> varID)
{
this.manager = Objects.requireNonNull(manager);
@@ -163,19 +163,19 @@ private void fireReferenceChangedEvent(Object source, T oldValue, T newValue)
* VariableChannel from the WriteableVariableStore.
*
* @param manager
- * The underlying AggressiveSolverManager that solves the given
+ * The underlying SolverManager that solves the given
* VariableID
* @param varStore
* The MonitorableVariableStore that the results of the
- * calculations by the AggressiveSolverManager are placed in
+ * calculations by the SolverManager are placed in
* @param varID
* The VariableID indicating to which Variable this
* VariableChannel is providing an interface
* @return A new VariableChannel linked as a listener to the given
* MonitorableVariableStore for the given VariableID
*/
public static <T> VariableChannel<T> construct(
- AggressiveSolverManager manager, MonitorableVariableStore varStore,
+ SolverManager manager, MonitorableVariableStore varStore,
VariableID<T> varID)
{
VariableChannel<T> ref =
@@ -39,7 +39,7 @@
import pcgen.base.formula.Formula;
import pcgen.base.formula.base.ScopeInstance;
import pcgen.base.formula.base.VarScoped;
-import pcgen.base.solver.AggressiveSolverManager;
+import pcgen.base.solver.DynamicSolverManager;
import pcgen.base.solver.IndividualSetup;
import pcgen.base.solver.SolverFactory;
import pcgen.base.solver.SplitFormulaSetup;
@@ -618,7 +618,7 @@ private void doFormulaSetup(LoadContext context)
variableStoreFacet.set(id, varStore);
SolverFactory solverFactory = solverFactoryFacet.get(id.getDatasetID());
solverManagerFacet.set(id,
- new AggressiveSolverManager(mySetup.getFormulaManager(),
+ new DynamicSolverManager(mySetup.getFormulaManager(),
context.getVariableContext().getManagerFactory(), solverFactory,
varStore));
}
@@ -3573,7 +3573,7 @@ private Equipment openCustomizer(Equipment aEq)
{
dataSet.addEquipment(newEquip);
}
- //TODO if this is returning null, then the AggressiveSolverManager needs to destroy the unused channels :/
+ //TODO if this is returning null, then the SolverManager needs to destroy the unused channels :/
return result == CustomEquipResult.PURCHASE ? newEquip : null;
}
@@ -25,6 +25,7 @@
import pcgen.base.formula.base.LegalScope;
import pcgen.base.formula.base.ScopeInstance;
+import pcgen.base.formula.base.VarScoped;
import pcgen.base.formula.inst.SimpleScopeInstance;
import pcgen.base.text.ParsingSeparator;
import pcgen.cdom.base.CDOMObject;
@@ -533,7 +534,8 @@ public ScopeInstance getActiveScope()
if (scopeInst == null)
{
LegalScope legalScope = var.getScope("Global");
- scopeInst = new SimpleScopeInstance(null, legalScope, "Global");
+ scopeInst = new SimpleScopeInstance(null, legalScope,
+ new DummyVarScoped(legalScope));
}
return scopeInst;
}
@@ -560,10 +562,40 @@ private LoadContext dropIntoContext(LegalScope lvs)
}
LoadContext parentLC = dropIntoContext(parent);
SimpleScopeInstance localInst = new SimpleScopeInstance(parentLC.getActiveScope(),
- lvs, "Context (during Load)");
+ lvs, new DummyVarScoped(lvs));
return new DerivedLoadContext(parentLC, localInst);
}
+ private static class DummyVarScoped implements VarScoped
+ {
+
+ private LegalScope lvs;
+
+ private DummyVarScoped(LegalScope lvs)
+ {
+ this.lvs = lvs;
+ }
+
+ @Override
+ public String getKeyName()
+ {
+ return "Context (during Load)";
+ }
+
+ @Override
+ public String getLocalScopeName()
+ {
+ return lvs.getName();
+ }
+
+ @Override
+ public VarScoped getVariableParent()
+ {
+ return null;
+ }
+
+ }
+
private class DerivedLoadContext implements LoadContext
{
@@ -818,7 +850,7 @@ else if (toScope.getParentScope().equals(currentScope))
{
//Direct drop from this
SimpleScopeInstance localInst = new SimpleScopeInstance(scopeInst,
- toScope, "Context (during Load)");
+ toScope, new DummyVarScoped(toScope));
return new DerivedLoadContext(this, localInst);
}
//Random jump to somewhere else...
@@ -78,6 +78,11 @@ public String getIdentification()
ManagerFactory managerFactory, FormulaManager ignored, LegalScope varScope,
FormatManager<T> formatManager)
{
+ if (!formatManager.getManagedClass().equals(getVariableFormat()))
+ {
+ throw new IllegalArgumentException(
+ "FormatManager must manage " + getVariableFormat().getName());
+ }
//TODO if this is Skill, fixed doesn't work :/
return getFixedModifier(userPriority, formatManager, instructions);
}
@@ -86,6 +91,11 @@ public String getIdentification()
public PCGenModifier<T> getFixedModifier(int userPriority,
FormatManager<T> fmtManager, String instructions)
{
+ if (!fmtManager.getManagedClass().equals(getVariableFormat()))
+ {
+ throw new IllegalArgumentException(
+ "FormatManager must manage " + getVariableFormat().getName());
+ }
T n = fmtManager.convert(instructions);
NEPCalculation<T> calc = new ProcessCalculation<>(n, this, fmtManager);
return new CalculationModifier<>(calc, userPriority);
Oops, something went wrong.

0 comments on commit a1af4c9

Please sign in to comment.