Skip to content

Commit

Permalink
Merge pull request #4621 from ColdAnkles/input-img-asset
Browse files Browse the repository at this point in the history
Input() to handle `lib://` asset paths
  • Loading branch information
cwisniew authored Jan 10, 2024
2 parents 0482b44 + ee38bcc commit ea2f0d2
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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.ImageManager;
import net.rptools.maptool.util.StringUtil;
import net.rptools.parser.Parser;
Expand Down Expand Up @@ -128,7 +129,8 @@
// @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();
Expand Down Expand Up @@ -1271,11 +1273,23 @@ public void checkParameters(String functionName, List<Object> 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;
MD5Key assetID = new MD5Key(id);
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);
}

// 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) {
Expand Down

0 comments on commit ea2f0d2

Please sign in to comment.