yochaigal / Cairn-FoundryVTT

Cairn for FoundryVTT!
MIT License
27 stars 24 forks source link

"ITEMS" tab omits slots with long values due to floating point math #38

Closed tuirgin closed 2 years ago

tuirgin commented 2 years ago

Observed Behavior

Items (X|Y) will omitted if the display of the slotsUsed takes up more horizontal space than is provided by the current window width.

image image

Root Cause

This comes up due to un-rounded floating point math. As the images provided in the observed behavior section illustrate, it is possible to have unexpectedly long values even when all item slot values are limited to single decimal place resolution.

Possible Solutions

Use case

I prefer some granularity over the inventory items and frequently set items at 0.01 (100 per slot—useful for coins and gems), 0.1 (10 per slot—torches and rations if I'm being generous, otherwise things like chalk), and 0.5.

Possible enhancement: For the purpose of bundles, it would be easier to indicate count per slot than some fraction of a slot. Players and GMs coming from B/X are used to bundles of 6 torches, 7 rations, or 12 iron spikes, for example.

ascendsauce commented 2 years ago

I propose to support up to .001 per slot, and work from that precision. Then just do a "millislot" if you will, or 1/1000th of a slot, so multiply the slots per by 1000 and then divide by 1000 once the calculation is complete.

Then add some validation so anything that is not 0 and less than 0.001 is updated to 0.001?

yochaigal commented 2 years ago

In general I only allow players to split an inventory slot in half (e.g. 2 small scrolls), but if this resolves the floating-point issue I'm fine with it.