-
Notifications
You must be signed in to change notification settings - Fork 259
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
Macro functions to execute javascript on a frame/dialog #1362
Comments
Hm, so the frame becomes persistent. I like that. :) I can see two ways something like this could be implemented.
Normally, the
There are sure to be concurrency problems. (Order of parameters chosen to mimic how an OO call would look: Because of how ugly the quoting issues are with MTscript currently, perhaps the Sounds like a fun project! |
I don't have any problem brainstorming the approach, though. And if @Merudo wants to give it a shot, I'd be happy to checkout his fork and see a potential solution. 🙂 (It would be trivial to change the source of the JS from one location to another at some future point.) The concurrency issues could be worked out in parallel with any development that might happen on the asset manager code. |
1 is sort of what I had in mind - although we don't have to limit ourselves to
There is currently no way to access token properties from javascript. Implementing it would require building a new api. It's a good idea, but I think the
By using
I was thinking just passing the whole javascript as a string. It's still possible to store the javascript in the token property (or other places), for example by using
|
I was thinking more that this new function would use the tokenID to make an immutable version of the token and pass a reference to the JS code (or set it as The script engine API allows objects to be passed into the context of the page and uses Reflection to determine availability of methods and properties. What's not clear from the Oracle scripting engine programmers guide (available here for Java 7) is whether we could build an This means we'd need to copy the values into a new object and pass that to the JS. We could start by adding a When we're ready to make the Token mutable, a lot of other issues come up (like keeping clients synced when changes are made), so we might need to create a layer to handle that. I can see an annotation that automatically makes
Yeah, getting rid of parser limitations was my main goal, and embedding JS inside MTscript strings is ugly. Pasting the code into a property means bypassing the parser completely. However, I'm learning more and more towards embedding the JS within the HTML page and just invoking it by name. That also makes it easier to debug in a real browser, since a small test harness can load the HTML (with JS embedded) and allow the use of the debugger and other browser tools... |
JSR-223 API is not useable by JavaFX Web View. Also the current token get/set methods would make a pretty poor API which is guaranteed to break in the future when token split occurs. |
"I didn't mean that literally. I meant the manufacturers of any dairy product." We can use the
It's not JSR-223, but it provides identical functionality. (I'm not really concerned about specific APIs at this point. If the functionality exists somewhere, that's good enough to continue the discussion.)
Yep. If you'll read it again, you'll see that I suggested a separate object with properties copied into it. But I have no problem changing it if/when the token split ever happens. (Waiting on token split seems... ill-advised.) |
You linked to a document about the scripting API detailing what you would have to do to make it work, as a way of saying "I dont mean use the scripting API I mean use the other thing we can"? This makes no sense
I did read it, you mention using the get/set methods of existing token, and there is nothing in your make a copy comment that suggests a different API. If that is what you mean you should detail what you mean rather than detail what you don't want and assume we some how know its not what you want. |
It's called a "concept". I can say, "I'd like to get something to eat, like maybe a burger", without meaning that I actually want a burger. If you don't know what similes are, unsubscribe. No one is forcing you to read this, y'know. |
I guess after that you would complain if someone informs you the burger shop is closed? All I did was point out that the API you were talking about is not being used, I am sorry that I didn't know you only wanted us to read the last few lines of a document you linked to when it wasn't mentioned anywhere.
Someone has to make sure the bigger picture is looked at, because it seems like only small picture is being thought of here at the moment. Its better to have it worked out up front then wait until a PR has to be rejected. |
@Merudo I have no knowledge of WebView other than some reading. I'll work to allocate some time to play around with it. I have to admit, it looks pretty exciting when I read about what it's capable of. Particularly, the ability to attach an event listener to DOM events (like onClick)... |
Edit: My mistake. This is the SO question that you replied to saying "me too". Oops. Take a look at this SO question since the author of the answer claims it works. (I haven't tried it myself yet, but I thought I'd pass it along first.) He calls |
Agreed, we should wait until javascript can be stored properly before implementing functions that can execute javascript code. However, what about the function
that can run a javascript function on a frame from MapTool. In this case all that is supplied is a function name, so no javascript is stored on tokens. An optional object can be passed, which could be a string, a number, a JsonObject or a JsonArray. |
That will work as there will be no need to alter the function as there is no dependancy on how things are stored. |
I suggest the following functions be added:
These functions could be implemented by using the json script
|
Do they need to be 3 different functions? Could it not be one function that first checks what the type is? |
I'd much rather have a single function as well. The issue is that a frame, a dialog and an overlay could all share the same name, in which case it not clear which component is the target. |
If you want to have one function and you are ok to introduce another (potentially optional) parameter you could add some constants to MTScript like html5.frame, html5.dialog, html5.overlay... maptool/src/main/java/net/rptools/maptool/client/MapToolVariableResolver.java Lines 163 to 175 in 6d193e3
|
Should we add three extra MTScript constants for a single function? |
That probably should have been prevented. But alternatively the function could check all three categories and if the name only shows up in one, run against that one. If the name is used in two+ places, it could return an error about that the name being ambiguous and used more than once. Or it could execute in a priority order such as overlay -> frame. Craig's suggestion of an optional parameter could be a tie-breaker also. |
Or use a prefix on the name, such as That makes it part of the string, which is easier to manage in script code, and removes the need for the additional parameter. If no prefix is given, then use Phergus' suggestion of picking the only one by that name. Sounds like there are a lot of options. Tackling it from the perspective of the script writer, the extra option might be best since it makes the code more explicit...? |
A prefix wouldn't be bad though I wonder how many folks have named their frames/overlays with colons in them. Either that or the extra parameter makes it more explicit as you say. A good thing for those who might be trying to understand some macro code. |
- Add function runJsFunction to run javascript on an existing frame5, dialog5 or overlay - runJsFunction has the following parameters: name (for name of frame/dialog/overlay), type (either "frame", "dialog", or "overlay"), func (the name of the javascript function to run), thisArg (the value of "this" provided the call to func, and argsArray (json array specifying the arguments with which func should be called) - Close RPTools#1362
PR #2071 adds functon
Example:
Then, to update the frame if the character loses 7 HP:
|
- Add function runJsFunction to run javascript on an existing frame5, dialog5 or overlay - runJsFunction has the following parameters: name (for name of frame/dialog/overlay), type (either "frame", "dialog", or "overlay"), func (the name of the javascript function to run), thisArg (the value of "this" provided the call to func, and argsArray (json array specifying the arguments with which func should be called) - Close RPTools#1362
What are the requirements for For ease of use, I could see using variadic parameters for the fifth argument and later, so that users don't have to create an array — MTscript would just create one for them from all remaining arguments. However, anyone writing MTscript knows well enough how to create a JSON array, and this definition does match the function signature for JS's |
The argument Example:
which can then be called with
to show the alert message "John Smith". |
Tested. Calling JS functions on Frames, Dialogs and Overlays working as expected. |
Is your feature request related to a problem? Please describe.
Frames can display data. For example, a frame may be a character sheet, displaying the character's level, HP, skills, etc.
If the data is modified by a macro, the information displayed by the frame becomes outdated. The current solution is to rebuild the entire frame with the new information.
This has at least three downsides:
With the HTML5 frame and dialog, it becomes unnecessary to rebuild the entire frame to update it; instead, a frame can be updated on the fly. We should take advantage of that.
Describe the solution you'd like
A macro function, for example
runJsOnFrame(frameName, javascript)
that can run Javascript on the frame. This would allow us to run a script updating the frame to new values, for example updating the displayed HP of a token after it has been damaged.
A similar function could then be implemented for dialogs.
The text was updated successfully, but these errors were encountered: