stardew_community_checklist icon indicating copy to clipboard operation
stardew_community_checklist copied to clipboard

Ensure data can be decoded and parsed into JSON before loading

Open droidenator opened this issue 5 years ago • 1 comments

This should fix #13

This ensures that the string can be decoded and parsed into JSON. I wasn't sure how to best check for this: "Be in the same form as the initialized data array (i.e. length = static.bundles.length)". I suppose I could assert that the keys are all valid item IDs?

droidenator avatar Oct 27 '19 05:10 droidenator

@droidenator I think that comment was referring to the 1.0 way to store data. The data is store much more simple now. Now it is an object where the properties represent the of the bundle-item relationships that have been redeemed.

For example, if you only redeemed Wild Horseradish from the Spring Foraging Bundle and Sunfish from the Riverfish Bundle, it would look like this-

{
    0: 1
    ​68: 1
}

Note that the ID is not the ID of the item or the bundle, but rather the ID of the relationship between them.

I think then, that to fulfill the intentions of that requirement, it should be more like-

  • [ ] Is a valid JS object
  • [ ] Contains only bundle-items that exist

Also, I think it might be better to do all of this validation in the Vuex store rather than have it in the settings component. The store should just throw an error if the validation fails and then the settings component can catch it and display an error message- like you have now, just moving the assertion to the store.

kihashi avatar Oct 28 '19 14:10 kihashi