Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input() to handle lib:// asset paths #4621

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading