From 3d091e678b0d43663fea7aeb3bc17763361bd798 Mon Sep 17 00:00:00 2001 From: ColdAnkles <13864745+ColdAnkles@users.noreply.github.com> Date: Tue, 9 Jan 2024 09:40:50 +1030 Subject: [PATCH 1/3] Updated Input Function to grab the "asset:" or "lib:" identifier from icon regex and pass through the AssetResolver to handle library assets as well as standard assets. --- .../maptool/client/functions/InputFunction.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/rptools/maptool/client/functions/InputFunction.java b/src/main/java/net/rptools/maptool/client/functions/InputFunction.java index 1fcc6e9b18..8c3f5ca2b7 100644 --- a/src/main/java/net/rptools/maptool/client/functions/InputFunction.java +++ b/src/main/java/net/rptools/maptool/client/functions/InputFunction.java @@ -76,6 +76,7 @@ import net.rptools.maptool.model.Token; import net.rptools.maptool.util.ImageManager; import net.rptools.maptool.util.StringUtil; +import net.rptools.maptool.util.AssetResolver; import net.rptools.parser.Parser; import net.rptools.parser.ParserException; import net.rptools.parser.VariableResolver; @@ -128,7 +129,7 @@ // @formatter:on public class InputFunction extends AbstractFunction { - private static final Pattern ASSET_PATTERN = Pattern.compile("^(.*)asset://(\\w+)"); + private static final Pattern ASSET_PATTERN = Pattern.compile("^(.*)((?:asset|lib)://[0-9a-z-A-Z ./]+)"); /** The singleton instance. */ private static final InputFunction instance = new InputFunction(); @@ -1272,10 +1273,20 @@ public void checkParameters(String functionName, List parameters) private ImageIcon getIcon(String id, int size, ImageObserver io) { // Extract the MD5Key from the URL if (id == null) return null; - MD5Key assetID = new MD5Key(id); + var assetKey = new AssetResolver().getAssetKey(id); + String assetId = null; + if (assetKey.isPresent()) { + assetId = assetKey.get().toString(); + } + MD5Key assetMD5 = null; + if (assetId != null) { + assetMD5 = new MD5Key(assetId); + }else{ + assetMD5 = new MD5Key(id); + } // Get the base image && find the new size for the icon - BufferedImage assetImage = ImageManager.getImage(assetID, io); + BufferedImage assetImage = ImageManager.getImage(assetMD5, io); // Resize if (assetImage.getWidth() > size || assetImage.getHeight() > size) { From af9aeb5e089125bb8992afdd787d76541b4ab44e Mon Sep 17 00:00:00 2001 From: ColdAnkles <13864745+ColdAnkles@users.noreply.github.com> Date: Tue, 9 Jan 2024 09:41:24 +1030 Subject: [PATCH 2/3] Spotless update --- .../rptools/maptool/client/functions/InputFunction.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/rptools/maptool/client/functions/InputFunction.java b/src/main/java/net/rptools/maptool/client/functions/InputFunction.java index 8c3f5ca2b7..553f2f0cc2 100644 --- a/src/main/java/net/rptools/maptool/client/functions/InputFunction.java +++ b/src/main/java/net/rptools/maptool/client/functions/InputFunction.java @@ -74,9 +74,9 @@ import net.rptools.maptool.client.ui.htmlframe.HTMLPane; import net.rptools.maptool.language.I18N; import net.rptools.maptool.model.Token; +import net.rptools.maptool.util.AssetResolver; import net.rptools.maptool.util.ImageManager; import net.rptools.maptool.util.StringUtil; -import net.rptools.maptool.util.AssetResolver; import net.rptools.parser.Parser; import net.rptools.parser.ParserException; import net.rptools.parser.VariableResolver; @@ -129,7 +129,8 @@ // @formatter:on public class InputFunction extends AbstractFunction { - private static final Pattern ASSET_PATTERN = Pattern.compile("^(.*)((?:asset|lib)://[0-9a-z-A-Z ./]+)"); + private static final Pattern ASSET_PATTERN = + Pattern.compile("^(.*)((?:asset|lib)://[0-9a-z-A-Z ./]+)"); /** The singleton instance. */ private static final InputFunction instance = new InputFunction(); @@ -1281,7 +1282,7 @@ private ImageIcon getIcon(String id, int size, ImageObserver io) { MD5Key assetMD5 = null; if (assetId != null) { assetMD5 = new MD5Key(assetId); - }else{ + } else { assetMD5 = new MD5Key(id); } From ee38bccd57b562fe87452bf7b1758a5b58387f05 Mon Sep 17 00:00:00 2001 From: ColdAnkles <13864745+ColdAnkles@users.noreply.github.com> Date: Tue, 9 Jan 2024 09:59:15 +1030 Subject: [PATCH 3/3] Formatting Update --- .../net/rptools/maptool/client/functions/InputFunction.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/rptools/maptool/client/functions/InputFunction.java b/src/main/java/net/rptools/maptool/client/functions/InputFunction.java index 553f2f0cc2..8530689854 100644 --- a/src/main/java/net/rptools/maptool/client/functions/InputFunction.java +++ b/src/main/java/net/rptools/maptool/client/functions/InputFunction.java @@ -1273,7 +1273,9 @@ public void checkParameters(String functionName, List parameters) /** Gets icon from the asset manager. Code copied and modified from EditTokenDialog.java */ private ImageIcon getIcon(String id, int size, ImageObserver io) { // Extract the MD5Key from the URL - if (id == null) return null; + if (id == null) { + return null; + } var assetKey = new AssetResolver().getAssetKey(id); String assetId = null; if (assetKey.isPresent()) {