Skip to content

Commit 9541b0e

Browse files
committed
Resolve global scope correctly in SolverManagerFacet
When MODIFY is parsed inside a non-global scope (e.g., MODIFY:Face on a SIZE object), VarModifier.getLegalScope() reports the parsing scope, not the variable's actual scope. Following that path produced a ScopeInstance that did not match the one used when reading the variable, so modifiers were applied to a different VariableID than channels read from. Routine the scope through resolveScope(): if the parsed scope is global, or if the variable is legally defined at the global scope, use the global ScopeInstance. Otherwise fall back to the local scope as before. Fixes the Pathfinder FACE tests (which use MODIFY:Face on SIZE objects to set the global Face variable to "5,5") and the GlobalModifyTest identity-mismatch failures.
1 parent 2ace84f commit 9541b0e

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

code/src/java/pcgen/cdom/facet/SolverManagerFacet.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import pcgen.cdom.content.VarModifier;
2929
import pcgen.cdom.enumeration.CharID;
3030
import pcgen.cdom.facet.base.AbstractItemFacet;
31+
import pcgen.rules.context.VariableContext;
3132

3233
/**
3334
* This stores the SolverManager for each PlayerCharacter.
@@ -49,11 +50,9 @@ public <T> List<ProcessStep<T>> diagnose(CharID id, VariableID<T> varID)
4950
public <T> boolean addModifier(CharID id, VarModifier<T> vm, VarScoped thisValue, Modifier<T> modifier,
5051
ScopeInstance source)
5152
{
52-
ScopeInstance scope = vm.getLegalScope().isGlobal()
53-
? scopeFacet.getGlobalScope(id)
54-
: scopeFacet.get(id, vm.getFullLegalScopeName(), thisValue);
55-
VariableID<T> varID = (VariableID<T>) loadContextFacet.get(id.getDatasetID()).get().getVariableContext()
56-
.getVariableID(scope, vm.getVarName());
53+
VariableContext varContext = loadContextFacet.get(id.getDatasetID()).get().getVariableContext();
54+
ScopeInstance scope = resolveScope(id, vm, thisValue, varContext);
55+
VariableID<T> varID = (VariableID<T>) varContext.getVariableID(scope, vm.getVarName());
5756
SolverManager sm = get(id);
5857
sm.addModifier(varID, modifier, source);
5958
sm.processSolver(varID);
@@ -66,16 +65,25 @@ public <T> boolean addModifier(CharID id, VarModifier<T> vm, VarScoped thisValue
6665
public <T> void removeModifier(CharID id, VarModifier<T> vm, VarScoped thisValue, Modifier<T> modifier,
6766
ScopeInstance source)
6867
{
69-
ScopeInstance scope = vm.getLegalScope().isGlobal()
70-
? scopeFacet.getGlobalScope(id)
71-
: scopeFacet.get(id, vm.getFullLegalScopeName(), thisValue);
72-
VariableID<T> varID = (VariableID<T>) loadContextFacet.get(id.getDatasetID()).get().getVariableContext()
73-
.getVariableID(scope, vm.getVarName());
68+
VariableContext varContext = loadContextFacet.get(id.getDatasetID()).get().getVariableContext();
69+
ScopeInstance scope = resolveScope(id, vm, thisValue, varContext);
70+
VariableID<T> varID = (VariableID<T>) varContext.getVariableID(scope, vm.getVarName());
7471
SolverManager sm = get(id);
7572
sm.removeModifier(varID, modifier, source);
7673
sm.processSolver(varID);
7774
}
7875

76+
private <T> ScopeInstance resolveScope(CharID id, VarModifier<T> vm, VarScoped thisValue,
77+
VariableContext varContext)
78+
{
79+
if (vm.getLegalScope().isGlobal()
80+
|| varContext.isLegalVariableID(scopeFacet.getGlobalScope(id).getImplementedScope(), vm.getVarName()))
81+
{
82+
return scopeFacet.getGlobalScope(id);
83+
}
84+
return scopeFacet.get(id, vm.getFullLegalScopeName(), thisValue);
85+
}
86+
7987
public void setScopeFacet(ScopeFacet scopeFacet)
8088
{
8189
this.scopeFacet = scopeFacet;

0 commit comments

Comments
 (0)