RPTools / maptool

Virtual Tabletop for playing roleplaying games with remote players or face to face.
http://rptools.net
GNU Affero General Public License v3.0
802 stars 262 forks source link

[Bug]: createMap does not accept add-on URIs #4626

Closed Tdue21 closed 10 months ago

Tdue21 commented 10 months ago

Describe the Bug

It is not possible to use the new createMap function with an image from an add-on. When I attempt to use the function with e.g. these parameters:

[h:lobbyImage = "lib://net.dovesoft.trinity-continuum/images/LobbyBackground.png"]
[h: lobbyId = createMap("01. Lobby", 
    json.set("{}",
        "player visible", json.true,
        "vision type", "Off",
        "vision distance", 1000,
        "lighting style", "OVERTOP",
        "has fog", json.false,
        "ai rounding", "None",
        "map asset", lobbyImage
    )
)]

I get the following exception:

20:41:53.233 DEBUG net.rptools.maptool.client.MapToolLineParser - net.rptools.parser.ParserException: createMap: "lib://net.dovesoft.trinity-continuum/images/StoryGuideScreen.png" is not a valid asset ID or URL
20:41:53.233 ERROR net.rptools.maptool.client.swing.MapToolEventQueue - java.util.concurrent.CompletionException: net.rptools.parser.ParserException: createMap: "lib://net.dovesoft.trinity-continuum/images/LobbyBackground.png" is not a valid asset ID or URL
java.util.concurrent.CompletionException: net.rptools.parser.ParserException: createMap: "lib://net.dovesoft.trinity-continuum/images/LobbyBackground.png" is not a valid asset ID or URL
    at net.rptools.maptool.model.library.addon.AddOnLibrary.lambda$callMTSFunction$15(AddOnLibrary.java:653) ~[MapTool.jar:1.14.3]
    at java.awt.event.InvocationEvent.dispatch(Unknown Source) [?:?]
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source) [?:?]

The image url is known to work, as I have tested it with [h:broadcast("<img src='" + lobbyImage + "'></img>")], which showed the image nicely in the chat window.

To Reproduce

  1. Create an add-on
  2. Add an image in the public folder and an onInit.mts file to the mtscript folder.
  3. In the onInit.mts add this:
    [h:lobbyImage = "lib://test-library-namespace/LobbyBackground.png"]
    [h: lobbyId = createMap("01. Lobby", 
    json.set("{}",
        "player visible", json.true,
        "vision type", "Off",
        "vision distance", 1000,
        "lighting style", "OVERTOP",
        "has fog", json.false,
        "ai rounding", "None",
        "map asset", lobbyImage
    )
    )]

    Where the lobbyImage variable points to the correct image with the correct namespace.

  4. Import the add-on
  5. Observe the exception.

Expected Behaviour

I expect the lib:// URI to be treated exactly as an asset:// URI. Even more so, as the ´createMap` function is so newly added.

Screenshots

No response

MapTool Info

1.14.3

Desktop

Windows 11

Additional Context

No response

bubblobill commented 10 months ago

Looks like multiple places in the code might suffer from hard coded assetId instead of URIs.