Current state of Javascript in maptool 1.4.1.x?

Developer discussion regarding MapTool 1.4

Moderators: dorpond, trevor, Azhrei

Forum rules
Posting now open to all registered forum users.
Post Reply
FreeLuna
Kobold
Posts: 18
Joined: Wed Mar 16, 2011 9:38 am

Current state of Javascript in maptool 1.4.1.x?

Post by FreeLuna »

So, I'm trying to find answers on the forums, and I don't see much in terms of specific documentation....

how well does Javascript work in the current development version? Is there a manual anywhere on what it can and can't do, or how to use it?

For example... do I need to use Javascript only as code occuring within a HTML webpage? Can Javascript and Maptool Script Language reference the same libraries and JSON objects?

And in particular... do we have the capability to use javascript to conduct simple time functions, like a webpage clock...

And do we have the capability to use javascript to save and load CSV files to/from disk?

Looking for documentation on what Javascript can or can't do in the current development version, or how to get started with testing it.... and I can't find much.

Does anyone have answers to my questions, or links to documentation and discussions I may have missed seeing?

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: Current state of Javascript in maptool 1.4.1.x?

Post by Azhrei »

I'm sure someone has answers, but it's not me. ;)

Seriously, the JS that's in there now (1.4.1.8) is very, very, VERY beta. Probably more like early alpha.

There are a LOT of decisions to make regarding the questions you asked, and every one of them requires a Java class be created to act as a facade. It's possible that existing code might be flexible enough to be that facade, but that's something that needs to be evaluated for each individual point.

For example, should JS have file access? If so, what kind of access? Should it be restricted to specific directories (perhaps only locations under ~/.maptool or under ~/.maptool/javascript)? Should files being written have a maximum size limit imposed? Should writing to files even be allowed? If there are going to be limits to directories or file sizes, should they be changeable by the user in Preferences; perhaps with some large upper limit that's hard-coded?

Once those questions are answered, with consideration given to security, performance, space requirements, and usefulness, then we can start designing the facade. And we probably will find that we don't have existing code that matches what we want that functionality to be.

Fortunately, the JS engine can pretty much convert back and forth from JS data types to Java data types, which will make the actual implementation of the code much simpler, but all of the rest of it is the hard part!

While the devs are excited to get this going, there are a couple of other things being worked on right now that need to happen first. If we're going to create this code to act as a layer between JS and the rest of the MT engine, we need MT's design to be a little cleaner. Otherwise, when we change MT's internal architecture, there could be a massive set of changes needed to keep JS working the same way. And one goal is to build the facade code with enough forethought that JS code wouldn't have to change even if the internals of MT did change.

FreeLuna
Kobold
Posts: 18
Joined: Wed Mar 16, 2011 9:38 am

Re: Current state of Javascript in maptool 1.4.1.x?

Post by FreeLuna »

Azhrei wrote:I'm sure someone has answers, but it's not me. ;)

Seriously, the JS that's in there now (1.4.1.8) is very, very, VERY beta. Probably more like early alpha.

There are a LOT of decisions to make regarding the questions you asked, and every one of them requires a Java class be created to act as a facade. It's possible that existing code might be flexible enough to be that facade, but that's something that needs to be evaluated for each individual point.

For example, should JS have file access? If so, what kind of access? Should it be restricted to specific directories (perhaps only locations under ~/.maptool or under ~/.maptool/javascript)? Should files being written have a maximum size limit imposed? Should writing to files even be allowed? If there are going to be limits to directories or file sizes, should they be changeable by the user in Preferences; perhaps with some large upper limit that's hard-coded?

Once those questions are answered, with consideration given to security, performance, space requirements, and usefulness, then we can start designing the facade. And we probably will find that we don't have existing code that matches what we want that functionality to be.

Fortunately, the JS engine can pretty much convert back and forth from JS data types to Java data types, which will make the actual implementation of the code much simpler, but all of the rest of it is the hard part!

While the devs are excited to get this going, there are a couple of other things being worked on right now that need to happen first. If we're going to create this code to act as a layer between JS and the rest of the MT engine, we need MT's design to be a little cleaner. Otherwise, when we change MT's internal architecture, there could be a massive set of changes needed to keep JS working the same way. And one goal is to build the facade code with enough forethought that JS code wouldn't have to change even if the internals of MT did change.
Is there a UML or other code documentation anywhere about how all the maptool java classes are linked together? I think I know enough Java now, and I need the feature badly enough....

If I could figure out how Maptool classes are linked together, I might just add a set of CSV functions in myself, either as a fork, or as a proposed patch.

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Current state of Javascript in maptool 1.4.1.x?

Post by Full Bleed »

Can't answer most of your questions, but...
FreeLuna wrote:And in particular... do we have the capability to use javascript to conduct simple time functions, like a webpage clock...
Depending on what and how you want to use a clock, you may be able to do something with macroscript. For example, I've added a timer to my rounds using Wiki: getInfo(). You can retrieve "timeDate" from the "client".
And do we have the capability to use javascript to save and load CSV files to/from disk?
As above, knowing what you were trying to do with CSV data might open some doors with regard to what you can do with existing macroscript. For example, there are many examples of people building statblock importers with macroscript... usually includes opening a form/input/dialog, pasting the statblock, and then have it parse the data as needed for your game. You could certainly do the same with raw CSV data.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

FreeLuna
Kobold
Posts: 18
Joined: Wed Mar 16, 2011 9:38 am

Re: Current state of Javascript in maptool 1.4.1.x?

Post by FreeLuna »

For the clock, I basically want to run an arbitrarily manipulated stopwatch...

Show the current real-world time, updated every 10 seconds or so.
Then manipulate that data, so that an in-universe clock runs faster or slower than the real-world clock, so that 10 seconds real-world equals about 10 minutes in-universe, and that second clock updates every time the first one does.

I could also play games with calendar dates, stopwatches for player actions, alarm clocks, things of that nature. But the simplest way to do that would probably be using javascript inside of HTML forms.... or to code a new "clock_interval" event function in macroscript, that pinged every 10 seconds or so.

As for CSV, what I basically want is the ability to seamlessly load and save an arbitrary number of complex CSV files, in order to, say, save the name, XY location, and properties of all tokens on a map to CSV, edit those details at-will using a spreadsheet I email to people, then re-upload all that data into maptools at will, whenever the users email back a spreadsheet...

And hypothethetically, I could be doing that with several different TYPES of spreadsheets, at will....

I really think the simplest way at this point is to code it myself... I've wanted this function for years, but I've only learned enough Java to do it myself recently.

What IDE do the maptools developers generally use? Is there any documentation lying around for getting started in editing the maptools backend? I think someone posted a fork once, allowing for plugins....


Full Bleed wrote:Can't answer most of your questions, but...
FreeLuna wrote:And in particular... do we have the capability to use javascript to conduct simple time functions, like a webpage clock...
Depending on what and how you want to use a clock, you may be able to do something with macroscript. For example, I've added a timer to my rounds using Wiki: getInfo(). You can retrieve "timeDate" from the "client".
And do we have the capability to use javascript to save and load CSV files to/from disk?
As above, knowing what you were trying to do with CSV data might open some doors with regard to what you can do with existing macroscript. For example, there are many examples of people building statblock importers with macroscript... usually includes opening a form/input/dialog, pasting the statblock, and then have it parse the data as needed for your game. You could certainly do the same with raw CSV data.

User avatar
Jagged
Great Wyrm
Posts: 1306
Joined: Mon Sep 15, 2008 9:27 am
Location: Bristol, UK

Re: Current state of Javascript in maptool 1.4.1.x?

Post by Jagged »

FreeLuna wrote:
Wed Mar 28, 2018 4:16 pm
What IDE do the maptools developers generally use? Is there any documentation lying around for getting started in editing the maptools backend? I think someone posted a fork once, allowing for plugins....
NetBeans and IntelliJ are what all the cool kids are using these days. Hence we all us old skool Eclipse :shock:

Really doesn't matter what you want to use, or even none at all. There is some documentation to help people get started with an Eclipse install, but I would hold off until the next version is released (thats 1.4.1.9) as we are expecting it to remove the use of sub-projects. Which makes the whole install process simpler, but invalidates the current instructions in the Forum.

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: Current state of Javascript in maptool 1.4.1.x?

Post by JamzTheMan »

My fork does have a sendURL(url, payload) macro function you can try out.

Using that you "post" a json payload somewhere, manipulate the data, respond back with a payload.

Not sure what capabilities you have like if you have a server and php or what not.
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

Post Reply

Return to “MapTool 1.4”