Skip to content

Commit

Permalink
Merge pull request #310 from oliver-szymanski/amend-transferVBL-189
Browse files Browse the repository at this point in the history
Fix #189 amend transferVBL function to really transfer
  • Loading branch information
cwisniew authored Mar 22, 2019
2 parents 8670808 + e0ea5a8 commit 7cf4f93
Showing 1 changed file with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@
* in VBL
*
* <p>getVBL(jsonArray) :: Get the VBL for a given area and return as array of points
*
* <p>transferVBL(direction[, delete][, tokenId] :: move or copy VBL between token and VBL layer
*/
public class VBL_Functions extends AbstractFunction {
private static final VBL_Functions instance = new VBL_Functions();
private static final String[] paramTranslate = new String[] {"tx", "ty"};
private static final String[] paramScale = new String[] {"sx", "sy"};

private VBL_Functions() {
super(0, 2, "drawVBL", "eraseVBL", "getVBL", "getTokenVBL", "setTokenVBL", "transferVBL");
super(0, 3, "drawVBL", "eraseVBL", "getVBL", "getTokenVBL", "setTokenVBL", "transferVBL");
}

public static VBL_Functions getInstance() {
Expand Down Expand Up @@ -286,7 +288,7 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par
if (functionName.equals("transferVBL")) {
Token token = null;

if (parameters.size() > 2)
if (parameters.size() > 3)
throw new ParserException(
I18N.getText(
"macro.function.general.tooManyParam", functionName, 1, parameters.size()));
Expand All @@ -299,8 +301,11 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par
if (!MapTool.getParser().isMacroPathTrusted())
throw new ParserException(I18N.getText("macro.function.general.noPerm", functionName));

if (parameters.size() == 2) {
token = FindTokenFunctions.findToken(parameters.get(1).toString(), null);
// make sure only to check the last parameter as token if it is not the BigDecimal for delete
if (parameters.size() >= 2
&& (!(parameters.get(parameters.size() - 1) instanceof BigDecimal))) {
token =
FindTokenFunctions.findToken(parameters.get(parameters.size() - 1).toString(), null);

if (token == null) {
throw new ParserException(
Expand All @@ -309,15 +314,20 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par
"getTokenVBL",
parameters.get(0).toString()));
}
} else if (parameters.size() == 1) {
} else {
MapToolVariableResolver res = (MapToolVariableResolver) parser.getVariableResolver();
token = res.getTokenInContext();
if (token == null) {
throw new ParserException(
I18N.getText("macro.function.general.noImpersonated", "getTokenVBL"));
I18N.getText("macro.function.general.noImpersonated", "transferVBL"));
}
}

boolean delete = false;
if (parameters.size() >= 2 && BigDecimal.ONE.equals(parameters.get(1))) {
delete = true;
}

Object val = parameters.get(0);
boolean vblFromToken;

Expand All @@ -335,8 +345,15 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par

if (vblFromToken) {
TokenVBL.renderVBL(renderer, token.getTransformedVBL(), false);
if (delete) {
token.setVBL(null);
}
} else {
Area vbl = TokenVBL.getVBL_underToken(renderer, token);
token.setVBL(TokenVBL.getMapVBL_transformed(renderer, token));
if (delete) {
TokenVBL.renderVBL(renderer, vbl, true);
}
}
}

Expand Down

0 comments on commit 7cf4f93

Please sign in to comment.