Draft: 馃悰 Inventory Items Crashing the Sheet Fix
Bug:
Adding any inventory items to the sheet seems to break it. The item does not get added and close and trying to reopen the sheet fails.
Error Message:
TypeError: An error occurred while rendering Tor2eCharacterSheet 34: can't access property "data", item is undefined
getLoad https://assets.forge-vtt.com/bazaar/systems/tor2e/0.1.7/modules/utilities.js:193
getLoad https://assets.forge-vtt.com/bazaar/systems/tor2e/0.1.7/modules/utilities.js:192
shouldBeWeary https://assets.forge-vtt.com/bazaar/systems/tor2e/0.1.7/modules/Tor2eActor.js:501
getData https://assets.forge-vtt.com/bazaar/systems/tor2e/0.1.7/modules/sheets/actors/Tor2eCharacterSheet.js:101
_render https://jurar-lord-of-the-rings.forge-vtt.com/scripts/foundry.js:3059
_render https://jurar-lord-of-the-rings.forge-vtt.com/scripts/foundry.js:3761
render https://jurar-lord-of-the-rings.forge-vtt.com/scripts/foundry.js:3018
render https://jurar-lord-of-the-rings.forge-vtt.com/scripts/foundry.js:4256
_onClickDocumentName https://jurar-lord-of-the-rings.forge-vtt.com/scripts/foundry.js:47243
Solution:
It seems the issue stems from the shouldBeWeary()
function in Tor2eActor.js
It's filling an array with a bunch of undefined values and tossing that off to getLoad
, which blows up when it receives those undefined values.
Looking at the object it seems to be matter of changing this.items.map(i => this.items.get(i._id))
to Array.from(this.items.values())
.
Because items
is a map, the items.values()
function will return an Iterator of the values of the map. So it will return the items. That Iterator needs to be converted into an Array so things like filter
, map
, etc. can be used. Array.from()
does exactly this. The result is an Array of Tor2eItem
objects, which I believe is what we want.
Testing
Tested locally and this fix seems to work fine.