foundryvtt-blades-in-the-dark icon indicating copy to clipboard operation
foundryvtt-blades-in-the-dark copied to clipboard

Setting all the radiobuttons with the proper data-dtype

Open quadur opened this issue 2 years ago • 2 comments

I'm hacking through with making a Brinkwood system based on this one and found that using radio buttons for numerical values saves them as strings of those numerals ("1" instead of 1) into the Actors data. This makes all kinds of things problematic, i.e., it is impossible to use Active Effects for adding (not overriding) skill dots when choosing classes.

After some searching and a few questions on Discord I was pointed to a simple solution setting data-dtype="Number" on a radio button forces Foundry to interpret them as true numerals.

So, a simple fix for attributes would be to change this: templates/parts/attributes.html:37

      <input type="radio" id="attributes-{{../../../actor._id}}-{{skill_name}}-{{this}}"
               name="data.attributes.{{attribute_name}}.skills.{{skill_name}}.value" value="{{this}}">

to this:

      <input type="radio" id="attributes-{{../../../actor._id}}-{{skill_name}}-{{this}}" 
               name="data.attributes.{{attribute_name}}.skills.{{skill_name}}.value" data-dtype="Number" value="{{this}}">

Edit after tests:

This requires and edit in the getAttributeDiceToThrow() in module/blades-actor.js:47 to simply load the value from the workaround:

dice_amount[skill_name] = parseInt(this.data.data.attributes[attribute_name].skills[skill_name]['value'][0])

to this:

dice_amount[skill_name] = this.data.data.attributes[attribute_name].skills[skill_name]['value'];

since the value is a number already

quadur avatar Aug 26 '22 10:08 quadur

Hello @quadur , thanks for pointing that out :) The system was written 2 years ago and I didn't have a clue about JS and Foundry itself as there was a lack of documentation :D I wish I could just change that one to use the proper format, however I'm a bit concerned that it would affect the saved data for people, who already have the system installed. I'll need some time to take a look at this.

megastruktur avatar Aug 29 '22 06:08 megastruktur

I wish I could just change that one to use the proper format, however I'm a bit concerned that it would affect the saved data for people, who already have the system installed. I'll need some time to take a look at this.

I've tested it, unfortunately, you're right I would require a migration update looping through existing actors and parseInt-ing all values (skills, exp, coins ...). If I'm done with the base Brinkwood update before you'll have a moment to address this I'll whip up a pull request.

quadur avatar Aug 29 '22 08:08 quadur