Skip to content

Commit

Permalink
Change copyToken options to tokenHandout, tokenPortrait
Browse files Browse the repository at this point in the history
- Change handoutImage update field to tokenHandout
- Change portraitImage update field to tokenPortrait
- Legacy: old values still work
- Fix null pointer exception to propert error message if the image token cannot be found
- Solve issues raised by @Phergus in RPTools#814
  • Loading branch information
Merudo committed Oct 18, 2019
1 parent a300e5b commit 968d7c8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,21 +287,29 @@ private void setTokenValues(Token token, JSONObject vals, Zone zone, MapToolVari
}
}

// legacy use, from pre 1.5.7.
if (!newVals.containsKey("tokenHandout") && newVals.containsKey("handoutImage")) {
// handoutImage -> tokenHandout
newVals.put("tokenHandout", newVals.get("handoutImage"));
}
if (!newVals.containsKey("tokenPortrait") && newVals.containsKey("portraitImage")) {
// portraitImage -> tokenPortrait
newVals.put("tokenPortrait", newVals.get("portraitImage"));
}

// tokenImage
if (newVals.containsKey("tokenImage")) {
MD5Key md5key = TokenImage.getMD5Key(newVals.getString("tokenImage"), TokenImage.SET_IMAGE);
MD5Key md5key = TokenImage.getMD5Key(newVals.getString("tokenImage"), COPY_FUNC);
token.setImageAsset(null, md5key);
}
// handoutImage
if (newVals.containsKey("handoutImage")) {
MD5Key md5key =
TokenImage.getMD5Key(newVals.getString("handoutImage"), TokenImage.SET_HANDOUT);
if (newVals.containsKey("tokenHandout")) {
MD5Key md5key = TokenImage.getMD5Key(newVals.getString("tokenHandout"), COPY_FUNC);
token.setCharsheetImage(md5key);
}
// portraitImage
if (newVals.containsKey("portraitImage")) {
MD5Key md5key =
TokenImage.getMD5Key(newVals.getString("portraitImage"), TokenImage.SET_PORTRAIT);
if (newVals.containsKey("tokenPortrait")) {
MD5Key md5key = TokenImage.getMD5Key(newVals.getString("tokenPortrait"), COPY_FUNC);
token.setPortraitImage(md5key);
}
}
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/net/rptools/maptool/client/functions/TokenImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,30 @@ private String typeOf(Object ob) {
return null;
}

public static MD5Key getMD5Key(String assetName, String func) throws ParserException {
/**
* Get the MD5Key corresponding to an asset.
*
* @param assetName either an assetId or the name of an image token.
* @param functionName the name of the function, to display the exception message.
* @return the MD5Key associated with the asset.
* @throws ParserException if assetName not found or assetName doesn't
*/
public static MD5Key getMD5Key(String assetName, String functionName) throws ParserException {
Matcher m = assetRE.matcher(assetName);

String assetId;
if (m.matches()) {
assetId = m.group(1);
} else if (assetName.toLowerCase().startsWith("image:")) {
assetId = findImageToken(assetName, func).getImageAssetId().toString();
Token imageToken = findImageToken(assetName, functionName);
if (imageToken == null) {
throw new ParserException(
I18N.getText("macro.function.general.unknownToken", functionName, assetName));
}
assetId = imageToken.getImageAssetId().toString();
} else {
throw new ParserException(
I18N.getText("macro.function.general.argumentTypeInvalid", func, 1, assetName));
I18N.getText("macro.function.general.argumentTypeInvalid", functionName, 1, assetName));
}
return new MD5Key(assetId);
}
Expand Down

0 comments on commit 968d7c8

Please sign in to comment.