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

Can we manipulate whether `bar1|2|3` are shown? #200

Closed phylll closed 2 years ago

phylll commented 2 years ago

SpawnDefaultToken looks as if there are properties called showplayers_bar1 etc. that determine if a bar is shown to, well, the players? A simple search for showplayers_bar1 and then for tokenAttributes in the code linked up above seemed to me that was the case. Would be useful to make these properties accessible as token.showplayers_bar1 etc., so we could very quickly provide our GM with a script to fix every selected token's bar visibility settings.

michael-buschbeck commented 2 years ago

MMM even reads those showplayers_barX attributes to determine whether players should have read access to the barX values... and still it never occurred to me to actually make them writable (by GMs).

Seems like a simple oversight that should be easily rectified.

michael-buschbeck commented 2 years ago

Same goes for showplayers_name.

michael-buschbeck commented 2 years ago

For bar1 etc. there's actually several interacting token properties:

michael-buschbeck commented 2 years ago

Looks like that mysterious "something to control whether the bar's numeric value is shown to players on top of the plain bar" setting has been mystifying others as well:

https://app.roll20.net/forum/post/10330024/setting-token-bar-text-overlays-via-api

I suppose exposing something that covers showplayers_barX and playersedit_barX would still be useful for our use case.

I'm not terribly fond of the naming. Maybe bar1_shown and bar1_edit instead?

michael-buschbeck commented 2 years ago

Speaking of showplayers_name... there's actually two properties that sound like much the same thing: showname and showplayers_name. Plus, there's playersedit_name.

Experimentation yields this:

showname showplayers_name editplayers_name GMs controllers others
false
true false false shown
true false true shown shown
true true shown shown shown
phylll commented 2 years ago

Did you have any trouble with tokens updating properly? When I tested this new feature, the bars never behaved they way I expected them to. Sometimes the properties seemed to be updated when I checked through the Roll20 UI, sometimes not immediately. Even logging out of the game and back it did not seem to help. Sometimes one bar disappeared and the other remained, even though I had set them all to false.

This is the code I used:

!mmm script
!mmm   for tokenID in selected
!mmm     do setattr(tokenID, "bar1_shown", false)
!mmm     do setattr(tokenID, "bar2_shown", false)
!mmm     do setattr(tokenID, "bar3_shown", false)
!mmm     chat: ${tokenID.name}'s bars reset.
!mmm   end for
!mmm end script
phylll commented 2 years ago

Ah wait... sorry. All of this is only about what's shown to players, I just realized. So I always have to switch to player mode to see what's happening... oops.

phylll commented 2 years ago

Looks like that mysterious "something to control whether the bar's numeric value is shown to players on top of the plain bar" setting has been mystifying others as well:

https://app.roll20.net/forum/post/10330024/setting-token-bar-text-overlays-via-api

Maybe these folks were confused about the different elements of the UI? Is there some hope remaining that the API actually does expose all the relevant settings?

After some experimentation, I learned that there are two different parts of the token settings UI at play here.

The relevant combinations for me are these:

Token bar options / style Token bars / barX / Player permissions & Text overlay Player result: barX_shown / barX numbers
standard view/edit/hidden visible / hidden
standard view/edit/visible for everyone visible / visible
compact view/edit/(overlay permissions inactive) visible (smaller) / hidden

Ultimately, what would help our GM would be a way for a script to batch-edit NPC tokens into compact view with those two bars visible to everyone.

michael-buschbeck commented 2 years ago

I'll definitely expose the "compact bars" setting (probably as bars_compact) and, while we're at it, the "bars location" setting as well (as bars_location, valid values: "overlap_top", "overlap_bottom", or "bottom").

When I was looking into the settings I've already exposed (bar1_shown etc.) I tried a bit of reverse engineering much like what's described in this thread: Dump values of all token attributes, change something, dump again, compare. Unfortunately I couldn't find anything that changed when I manually changed the "numbers overlay" option in the UI.

This could mean:

phylll commented 2 years ago

Unfortunately I couldn't find anything that changed when I manually changed the "numbers overlay" option in the UI.

Did you find a change when you changed to "compact bars"? Since those override the bar-specific settings, that would be enough for my present (most basic) use case.

michael-buschbeck commented 2 years ago

I didn't check that setting – only the "text overlay" ones. I assume the "compact bars" setting will work fine.

michael-buschbeck commented 2 years ago

I may have spoken to soon: The compact_bar token attribute exists (defaulting to JavaScript null for all existing tokens) and I've reverse-engineered that its valid values are null (standard size) and "compact" (compact size)... but unfortunately even though I can set "compact" in API code, setting it in API code doesn't affect the visuals.

I've read about similar effects with other API object attributes. Sometimes it's possible to work around this issue by setting the attribute to some intermediate value first to trigger an update. Some further experimentation may be warranted.

Arguably good news: bar_location (alias bars_location in MMM) works (though "overlap_bottom" looks more like "obscure most of the token", and "bottom" behaves exactly like "foo" and looks like "vertically centered, horizontally anchored to the token center at the bars' left edge").

michael-buschbeck commented 2 years ago

Ah, looking into TokenMod's source code I'm finding…

michael-buschbeck commented 2 years ago

I may have spoken too soon that I spoke too soon. compact_bar works fine if you feed it the values it expects (i.e. "compact" vs null because why not?).

The "above" and "below" values for bar_location also work fine.

michael-buschbeck commented 2 years ago

Experimental support for the following token properties in our test game:

michael-buschbeck commented 2 years ago

I've slightly renamed the token properties (now available in our test game) – see edited previous comment. Sorry for the noise.

phylll commented 2 years ago

Check out the new %{MacroSheet|fixBars} GM script that resets the token bars the way we want them for all NPCs (filtered by .character_id and not .PC) on the current page. Works fine in our test game, I'll have the GM test it on the main game, as well.

phylll commented 2 years ago

I'll ask the GM once MMM 1.35.0+ is installed in the main game, I meant to say, of course. 😀