Advertisement Create a free account
This post has been closed. You can still view previous posts, but you can't post any new replies.

Update 2/18: Bug Fixes, new Sheet Worker functions

1455814315

Edited 1455817741
Riley D.
Roll20 Team
Hey everyone! There's a new update out on Main today which has some bug fixes and some new functionality for the Sheet Workers on Character Sheets. Without further ado: Sheet Worker and Character Sheet Changes The setAttrs() function for Sheet Workers can now take an optional second parameter with options, and an optional callback function as the third parameter. For example, setAttrs({values: "here"}, {quiet: true}, function() {}); Currently the only option is "quiet", which when set to true will not trigger any other Sheet Worker events that would normally be triggered by setting these attributes. The callback will be executed after the attributes have definitely been set on the character, so you can use it to wait to make sure those values are set before doing any further actions. Note that if you want to use the callback function but not any options, you should pass a blank object "{}" as the second parameter. You can now use <span> tags in your Character Sheet HTML templates and add a name="attr_attributename" property to them just like you can for inputs, textareas, etc. For example: <span name="attr_strength"></span> This is useful if you want to display a read-only value on the sheet but want to have more control over how it's presented (especially for multi-line values). Note that span tags are read-only so if you want this attribute to be editable, you'll need to continue using an input, textarea, etc. (or include an input in one spot and a span tag in another, etc.) The value of the attribute will be set as the inner text of the span element. Now if you use a Sheet Worker to set an empty string ("") for an existing field, the default value of that field (either an empty string, or if not an empty string whatever the default is specified as in the Character Sheet template) will be put into the field. Previously this was the behavior you would see after you closed and re-opened the sheet, but now you should see that value put in right away. We've changed the way that repeating section removal works internally. This shouldn't affect anything, but it should be more efficient and cause us to not mis-fire events for rows when they are deleted.  If you modify the name of a Character the entire character sheet will no longer immediately be forced to re-render. Bug Fixes The "Align to Grid" tool was not behaving as expected when used while the grid was disabled, it was deleting tokens. The tool now throws a message if you try to use it while the grid is disabled. Timestamps would all reset to "now" any time you refreshed your game. They now show up correctly on game startup. While chat is in the pop-out window, any chat message from the API would scroll the window all the way to the top. During the tutorial, if you are using a smaller monitor, some things would pop up behind the tutorial menu, making them impossible to click. The tutorial menu is now collapsible. Thanks!
1455815788
Finderski
Pro
Sheet Author
Riley D. said: Sheet Worker and Character Sheet Changes The setAttrs() function for Sheet Workers can now take a second parameter with options, and a callback function as the third parameter. For example, setAttrs({values: "here"}, {quiet: true}, function() {}); Currently the only option is "quiet", which when set to true will not trigger any other Sheet Worker events that would normally be triggered by setting these attributes. The callback will be executed after the attributes have definitely been set on the character, so you can use it to wait to make sure those values are set before doing any further actions. Note that if you want to use the callback function but not any options, you should pass a blank object "{}" as the second parameter. So, does this break existing Sheet Worker scripts that use setAttrs()?
1455817408
Riley D.
Roll20 Team
No. Both parameters are optional. 
1455821500
Kryx
Pro
Sheet Author
API Scripter
Riley D. said: You can now use <span> tags in your Character Sheet HTML templates and add a name="attr_attributename" property to them just like you can for inputs, textareas, etc. For example: <span name="attr_strength"></span> This is useful if you want to display a read-only value on the sheet but want to have more control over how it's presented (especially for multi-line values). Note that span tags are read-only so if you want this attribute to be editable, you'll need to continue using an input, textarea, etc. (or include an input in one spot and a span tag in another, etc.) The value of the attribute will be set as the inner text of the span element. Praise be! Omg.. this solves sooo many problems. Riley D. said: If you modify the name of a Character the entire character sheet will no longer immediately be forced to re-render. Yay, thanks!
Have a request for Compendium drag-n-drop: all inputs with an accept should clear prior to the values being input. This would fix an issue discussed at the end of the last update thread. To see an example using 5e OGL sheet, drag Bless (a Concentration spell) to a spell slot, now drag Acid Arrow (not concentration) to replace it. Currently the Concentration checkbox remains checked.
1455825117
Kryx
Pro
Sheet Author
API Scripter
@Riley: any chance to get that data binding behavior on divs as well?
1455827181
Riley D.
Roll20 Team
Kryx said: @Riley: any chance to get that data binding behavior on divs as well? We decided to just do spans...you can use display: block if you just want a span to look like a div, though. Or is there something else we might not have considered?
1455828000

Edited 1455828653
Kryx
Pro
Sheet Author
API Scripter
Riley D. said: We decided to just do spans...you can use display: block if you just want a span to look like a div, though. Or is there something else we might not have considered? That is indeed an option, though it would be nice to use the DOM element meant for block instead of turning spans to block. Another thing: Quiet seems to work nice until default values are filled in for repeating items. FILLED IN A DEFAULT VALUE FOR repeating_spell_-KAq4g0OMqkx0IO-xu5a_spell_level app.js?1455817642:37 FILLED IN A DEFAULT VALUE FOR repeating_spell_-KAq4g0OMqkx0IO-xu5a_concentration To have quiet work I'd have to remove all default values. Though it seems strange as I have several other inputs/checkboxes/selects, etc that have default values and only these are triggering. Any insights there? EDIT: This seems to happen AFTER the change is triggered so quiet doesn't seem to be working. EDIT2: this is how I'm using it: setAttrs(OBJ_GOES_HERE, {quiet: true}); Your setAttrs seems to have a function?
1455829031
Riley D.
Roll20 Team
I mean the quiet just causes other sheet workers to not be triggered. So like if you modify "Strength" with setAttrs(), and you have an on("change:strength") function someplace else, the Strength will get updated but the change event won't fire. Although honestly I think the best way to handle that situation is to make use of the eventInfo parameter. So if you do on("change:strength", function(eventInfo) {    eventInfo.sourceType == "sheetworker" || eventInfo.sourceType == "player" }); so based on what eventInfo.sourceType is you can choose to do something in your callback or not. We added the quiet thing a while ago internally and so I thought I would make a note of it if it would be helpful, but the sourceType information gives you more fine-grained control over things for sure. And the function in the setAttrs() example is the new callback function you can use to be notified of when the setAttrs has completed.
1456165006
Kryx
Pro
Sheet Author
API Scripter
@Riley spans do not preserve line breaks if the content has them. For example: Title Words Would appear as "Title Words". If that worked it would be nice.
1456414650

Edited 1456414698
chris b.
Pro
Sheet Author
API Scripter
have to say the {quiet:true} is pretty awesome. this is letting me make some shortcuts that bypass the events and just update directly, without having to worry that extra processing time will be taken up by the 2nd return trip to the server due to an update, even though it would just be one extra round trip, that's still slowing the sheets down for the user due to all the calculations going on.
1456449375
Riley D.
Roll20 Team
Kryx said: @Riley spans do not preserve line breaks if the content has them. For example: Title Words Would appear as "Title Words". If that worked it would be nice. That's because by default in HTML line breaks in the source code do not equal breaks on the page. That's what the &lt;br&gt; tag is for. However, if you want line breaks in the source code to equal breaks on the page, just style it with CSS using the white-space property:&nbsp; <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/w" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/CSS/w</a>... So something like: span.worklikeinput { &nbsp; white-space: pre-line; } is probably what you want.
1456473661
Kryx
Pro
Sheet Author
API Scripter
That'll accomplish what I want. Thanks!
1456671704
Stephen L.
Pro
Marketplace Creator
Sheet Author
API Scripter
Could there be a note about the &lt;span&gt; tags for read-only fields on the wiki? It doesn't appear to have been updated for it.
1457457133
Riley D.
Roll20 Team
Stephen L. said: Could there be a note about the &lt;span&gt; tags for read-only fields on the wiki? It doesn't appear to have been updated for it. Yes, I added some notes. Thanks!