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 8530689854..95e682c209 100644 --- a/src/main/java/net/rptools/maptool/client/functions/InputFunction.java +++ b/src/main/java/net/rptools/maptool/client/functions/InputFunction.java @@ -66,7 +66,6 @@ import javax.swing.border.EmptyBorder; import javax.swing.border.EtchedBorder; import javax.swing.border.TitledBorder; -import net.rptools.lib.MD5Key; import net.rptools.maptool.client.MapTool; import net.rptools.maptool.client.MapToolVariableResolver; import net.rptools.maptool.client.functions.InputFunction.InputType.OptionException; @@ -74,7 +73,7 @@ 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.FunctionUtil; import net.rptools.maptool.util.ImageManager; import net.rptools.maptool.util.StringUtil; import net.rptools.parser.Parser; @@ -130,7 +129,7 @@ public class InputFunction extends AbstractFunction { private static final Pattern ASSET_PATTERN = - Pattern.compile("^(.*)((?:asset|lib)://[0-9a-z-A-Z ./]+)"); + Pattern.compile("^(.*)((?:asset|lib|Image):(//)?[0-9a-z-A-Z ./]+)"); /** The singleton instance. */ private static final InputFunction instance = new InputFunction(); @@ -1276,17 +1275,7 @@ private ImageIcon getIcon(String id, int size, ImageObserver io) { if (id == null) { return null; } - 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); - } + var assetMD5 = FunctionUtil.getAssetKeyFromString(id); // Get the base image && find the new size for the icon BufferedImage assetImage = ImageManager.getImage(assetMD5, io); diff --git a/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java b/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java index 8c21c2c9fd..1575a63630 100644 --- a/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java +++ b/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java @@ -285,7 +285,6 @@ public Object childEvaluate( throw new ParserException( I18N.getText("macro.function.map.invalidAsset", functionName, mapAssetId)); } - final var mapAsset = AssetManager.getAsset(mapAssetKey); if (mapAsset != null) { AssetManager.putAsset(mapAsset); diff --git a/src/main/java/net/rptools/maptool/util/FunctionUtil.java b/src/main/java/net/rptools/maptool/util/FunctionUtil.java index 8932040a07..e2ab99ea21 100644 --- a/src/main/java/net/rptools/maptool/util/FunctionUtil.java +++ b/src/main/java/net/rptools/maptool/util/FunctionUtil.java @@ -519,16 +519,31 @@ public static DrawablePaint getPaintFromString(String paint) { /** * Parses a string as an asset URL. * - * @param assetUrlOrId String containing the asset ID or asset URL. + * @param assetUrlOrId String containing the asset ID (ID), asset URL (asset://ID), or addon + * URL(lib://PATH). * @return The MD5 key present in {@code assetUrlOrId}, or null. */ public static @Nullable MD5Key getAssetKeyFromString(String assetUrlOrId) { - final String id; + String id = null; if (assetUrlOrId.toLowerCase().startsWith("asset://")) { id = assetUrlOrId.substring("asset://".length()); + } else if (assetUrlOrId.toLowerCase().startsWith("lib://")) { + var assetKey = new AssetResolver().getAssetKey(assetUrlOrId); + if (assetKey.isPresent()) { + id = assetKey.get().toString(); + } + } else if (assetUrlOrId.toLowerCase().startsWith("image:")) { + for (ZoneRenderer z : MapTool.getFrame().getZoneRenderers()) { + Token t = z.getZone().getTokenByName(assetUrlOrId); + if (t != null) { + id = t.getImageAssetId().toString(); + } + } } else if (assetUrlOrId.length() == 32) { id = assetUrlOrId; - } else { + } + + if (id == null) { return null; }