Skip to content

Commit

Permalink
Resolves #483
Browse files Browse the repository at this point in the history
  • Loading branch information
Jmr3366 committed Oct 11, 2024
1 parent dd44a05 commit 6222409
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions src/main/java/net/rptools/maptool/client/functions/TokenImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ final int getValue() {

private TokenImage() {
super(
0,
3,
"getTokenImage",
"getTokenPortrait",
"getTokenHandout",
"setTokenImage",
"setTokenPortrait",
"setTokenHandout",
"getImage",
"setTokenOpacity",
"getAssetProperties",
"getTokenOpacity",
"createAsset");
0,
3,
"getTokenImage",
"getTokenPortrait",
"getTokenHandout",
"setTokenImage",
"setTokenPortrait",
"setTokenHandout",
"getImage",
"setTokenOpacity",
"getAssetProperties",
"getTokenOpacity",
"createAsset");
}

/**
Expand All @@ -90,8 +90,8 @@ public static TokenImage getInstance() {

@Override
public Object childEvaluate(
Parser parser, VariableResolver resolver, String functionName, List<Object> args)
throws ParserException {
Parser parser, VariableResolver resolver, String functionName, List<Object> args)
throws ParserException {
Token token;

if (functionName.equalsIgnoreCase("setTokenOpacity")) {
Expand Down Expand Up @@ -161,8 +161,8 @@ public Object childEvaluate(
properties.addProperty("name", asset.getName());

Image img =
ImageManager.getImageAndWait(
asset.getMD5Key()); // wait until loaded, so width/height are correct
ImageManager.getImageAndWait(
asset.getMD5Key()); // wait until loaded, so width/height are correct
String status = "loaded";
if (img == ImageManager.BROKEN_IMAGE) {
status = "broken";
Expand All @@ -183,7 +183,7 @@ public Object childEvaluate(
String imageString = args.get(1).toString();
if (imageName.isEmpty() || imageString.isEmpty()) {
throw new ParserException(
I18N.getText("macro.function.general.paramCannotBeEmpty", functionName));
I18N.getText("macro.function.general.paramCannotBeEmpty", functionName));
} else if (imageString.length() > 8) {
byte[] imageBytes = Base64.decode(imageString);
String imageCheck;
Expand All @@ -193,8 +193,8 @@ public Object childEvaluate(
throw new ParserException(I18N.getText("dragdrop.unsupportedType", functionName));
}
if (imageCheck.equals(FILE_HEADER_WEBP)
|| imageCheck.equals(FILE_HEADER_JPG)
|| imageCheck.equals(FILE_HEADER_PNG)) {
|| imageCheck.equals(FILE_HEADER_JPG)
|| imageCheck.equals(FILE_HEADER_PNG)) {
Asset asset = Asset.createImageAsset(imageName, imageBytes);
AssetManager.putAsset(asset);
assetId.append(asset.getMD5Key().toString());
Expand All @@ -204,7 +204,7 @@ public Object childEvaluate(
}
} else {
throw new ParserException(
I18N.getText("macro.function.general.wrongParamType", functionName));
I18N.getText("macro.function.general.wrongParamType", functionName));
}
}

Expand Down Expand Up @@ -248,18 +248,18 @@ public Object childEvaluate(
}
assetId.append(token.getImageAssetId().toString());
} else if ("getTokenHandout"
.equalsIgnoreCase(functionName)) { // getTokenHandout, or different capitalization
.equalsIgnoreCase(functionName)) { // getTokenHandout, or different capitalization
if (token.getCharsheetImage() == null) {
return "";
}
assetId.append(token.getCharsheetImage().toString());
} else {
throw new ParserException(
I18N.getText("macro.function.general.unknownFunction", functionName));
I18N.getText("macro.function.general.unknownFunction", functionName));
}

if (indexSize >= 0
&& !"".equals(args.get(indexSize).toString())) { // if size parameter entered and not ""
&& !"".equals(args.get(indexSize).toString())) { // if size parameter entered and not ""
if (args.get(indexSize) instanceof BigDecimal) {
assetId.append("-");
BigDecimal size = (BigDecimal) args.get(indexSize);
Expand All @@ -268,11 +268,11 @@ public Object childEvaluate(
assetId.append(i);
} else {
throw new ParserException(
I18N.getText(
"macro.function.general.argumentTypeInvalid",
functionName,
indexSize + 1,
args.get(indexSize).toString()));
I18N.getText(
"macro.function.general.argumentTypeInvalid",
functionName,
indexSize + 1,
args.get(indexSize).toString()));
}
}

Expand All @@ -298,7 +298,7 @@ public static MD5Key getMD5Key(String assetName, String functionName) throws Par
Token imageToken = findImageToken(assetName, functionName);
if (imageToken == null) {
throw new ParserException(
I18N.getText("macro.function.general.unknownToken", functionName, assetName));
I18N.getText("macro.function.general.unknownToken", functionName, assetName));
}
assetId = imageToken.getImageAssetId().toString();
} else {
Expand All @@ -309,7 +309,7 @@ public static MD5Key getMD5Key(String assetName, String functionName) throws Par
}
if (assetId == null) {
throw new ParserException(
I18N.getText("macro.function.general.argumentTypeInvalid", functionName, 1, assetName));
I18N.getText("macro.function.general.argumentTypeInvalid", functionName, 1, assetName));
} else {
return new MD5Key(assetId);
}
Expand All @@ -318,7 +318,7 @@ public static MD5Key getMD5Key(String assetName, String functionName) throws Par
private static void setImage(Token token, String assetName) throws ParserException {
MD5Key md5key = getMD5Key(assetName, SET_IMAGE);
MapTool.serverCommand()
.updateTokenProperty(token, Token.Update.setImageAsset, (String) null, md5key.toString());
.updateTokenProperty(token, Token.Update.setImageAsset, (String) null, md5key.toString());
}

private static void setPortrait(Token token, String assetName) throws ParserException {
Expand All @@ -337,7 +337,7 @@ private static Token findImageToken(final String name, String functionName) {
List<ZoneRenderer> zrenderers = MapTool.getFrame().getZoneRenderers();
for (ZoneRenderer zr : zrenderers) {
List<Token> tokenList =
zr.getZone().getTokensFiltered(t -> t.getName().equalsIgnoreCase(name));
zr.getZone().getTokensFiltered(t -> t.getName().equalsIgnoreCase(name));
for (Token token : tokenList) {
// If we are not the GM and the token is not visible to players then we don't
// let them get functions from it.
Expand All @@ -363,4 +363,4 @@ private static Token findImageToken(final String name, String functionName) {
// throw new ParserException(I18N.getText("macro.function.general.unknownToken", functionName,
// name));
}
}
}

0 comments on commit 6222409

Please sign in to comment.