michael-buschbeck / mychs-macro-magic

A simple, sane, and friendly little scripting language for your Roll20 macros.
MIT License
1 stars 1 forks source link

Provide access to table scale #15

Closed michael-buschbeck closed 3 years ago

michael-buschbeck commented 3 years ago

The left and top attributes are given in (unzoomed) pixels, but sometimes (or even most often?), in-game are of greater interest.

Provide a way to convert between pixels and in-game dimensions.

michael-buschbeck commented 3 years ago

Table scale is available through the page object API (see docs) as these two properties:

I was thinking to provide conversion support (e.g. "give me these dimensions in meters" even if the page is measured in feet), but given the availability of under- and undefined units that may not be possible. (But I can still convert from pixels to "map units" and back and also provide access to the map unit name itself.)

phylll commented 3 years ago

Thanks! I think it makes sense to assume that the page is measured in the unit we need for whatever the macros do that are executed on that page -- if we're fighting according to Midgard rules which work in meters, the GM will scale the page in meters since otherwise we won't be able to use the Roll20 measurement tool to understand distances correctly. These might vary within the same game, e.g. meters for combat and kilometers for overland travel. So if MMM gave me access to the conversion factor between pixels and the current scale_unit, that would seem completely sufficient!

phylll commented 3 years ago

There appears to be also a page property called snapping_increment which seems to be useful in this regard, see https://app.roll20.net/forum/post/9007178/help-getting-token-coordinates-using-selected-and-target/?pageforid=9007685#post-9007685

michael-buschbeck commented 3 years ago

Interesting… so the scale properties are in units of snapping_increment (times grid unit = 70 pixels)?

Gotta play around with those settings to get a grip on this.

michael-buschbeck commented 3 years ago

So if MMM gave me access to the conversion factor between pixels and the current scale_unit, that would seem completely sufficient!

Yeah, that makes sense.

I'll do that and provide the unit separately for good measure – if anyone wants to convert feet to meters, they can do it themselves.

michael-buschbeck commented 3 years ago

Playing around yields this insight (consistent with the forum posting linked above):

So:

The docs are significantly confused about what constitutes a "[grid] unit" and what a "grid cell" – the interpretation that matches observation is that a "[grid] unit" is fixed at 70px, which however makes the documentation of scale_number wrong ("distance of one [grid] unit" – no, of one grid cell).

michael-buschbeck commented 3 years ago

Slight twist: If the GM disables snapping, snapping_increment gets set to zero, but distances act as if it was 1.