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

Updated FunctionUtil to handle lib:// assets via AssetResolver #4629

Merged
merged 3 commits into from
Jan 12, 2024
Merged
Changes from 1 commit
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 @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import net.rptools.lib.MD5Key;
import net.rptools.maptool.client.AppPreferences;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.client.MapToolUtil;
Expand All @@ -32,6 +33,7 @@
import net.rptools.maptool.model.Zone;
import net.rptools.maptool.model.ZoneFactory;
import net.rptools.maptool.model.drawing.DrawablePaint;
import net.rptools.maptool.util.AssetResolver;
import net.rptools.maptool.util.FunctionUtil;
import net.rptools.parser.Parser;
import net.rptools.parser.ParserException;
Expand Down Expand Up @@ -280,21 +282,22 @@ public Object childEvaluate(

if (config.has("map asset")) {
final var mapAssetId = config.getAsJsonPrimitive("map asset").getAsString();
final var mapAssetKey = FunctionUtil.getAssetKeyFromString(mapAssetId);
ColdAnkles marked this conversation as resolved.
Show resolved Hide resolved
if (mapAssetKey == null) {
throw new ParserException(
I18N.getText("macro.function.map.invalidAsset", functionName, mapAssetId));
final var mapAssetKey = new AssetResolver().getAssetKey(mapAssetId);
MD5Key assetMD5 = null;
if (mapAssetKey.isPresent()) {
assetMD5 = new MD5Key(mapAssetKey.get().toString());
} else {
assetMD5 = new MD5Key(mapAssetId);
ColdAnkles marked this conversation as resolved.
Show resolved Hide resolved
}

final var mapAsset = AssetManager.getAsset(mapAssetKey);
final var mapAsset = AssetManager.getAsset(assetMD5);
if (mapAsset != null) {
AssetManager.putAsset(mapAsset);
if (!MapTool.isHostingServer()) {
MapTool.serverCommand().putAsset(mapAsset);
}
}

newMap.setMapAsset(mapAssetKey);
newMap.setMapAsset(assetMD5);
}

MapTool.addZone(newMap, false);
Expand Down
Loading