Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
If you're having issues creating a character, clear your cookies and log in again. If you continue having issues, contact us.
Create a free account

Sheetworker parsing compendium drag/drop

1556294767

Edited 1556294867
vÍnce
Pro
Sheet Author
So I've been fooling around(my level of javascript) with trying to convert the json data from the PF Bestiary ( npcdrop_data ) into the attributes used on the PF Community sheet.  Chris B. already has an excellent parser in-place on the sheet which works very well with the free PF compendium, however the Bestiary that's available for purchase uses a different attribute schema.  Not sure if it's possible, but I would like to leave the current parser in-tact and simply copy the Bestiary attributes into a format that the parser can handle. Here's an example of what I'm trying <script type="text/worker"> on("change:npcdrop_data", function () { "use strict"; console.log("~~~compendium drop detected~~~"); getAttrs(["npcdrop_category", "npcdrop_name", "npcdrop_uniq", "npcdrop_data", "npcdrop_content"], function (v) { var obj = JSON.parse(v.npcdrop_data); console.log("~~~compendium drop Category: " + v.npcdrop_category); console.log("~~~compendium drop Name: " + v.npcdrop_name); console.log("~~~compendium drop Unique Name: " + v.npcdrop_uniq); console.log("~~~compendium drop raw stat block: " + v.npcdrop_data); console.log("~~~compendium drop Content: " + v.npcdrop_content); setAttrs({ ["Flat-Footed"] : obj["data-AC Flat-Footed"], ["Armor-notes"] : obj["data-AC Notes"], Touch : obj["data-AC Touch"], ac_compendium : obj["data-AC"], ["Acrobatics-note"] : obj["data-Acrobatics Notes"], Acrobatics : obj["data-Acrobatics"], alignment : obj["data-Alignment"] }); }); }); </script> Do you think this approach would work, or would a completely new parser need to be written?  Thoughts? TIA
1556307244

Edited 1556307266
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I might recommend making a translation object. At its simplest this would be an object that has the bestiary compendium attribute names as keys and the attribute that it needs to be stored in as the value. Then you could simply do something like: _.each(_.keys(v.npcdrop_data),(key)=>{     if(transObj[key]){         setObj[transObj[key]]=v.npcdrop_data[key];     }else{         //use the original parser     } }); setAttrs(setObj); Note that this may need to be a bit more complicated to handle things like attributes that need to be parsed or combined.
1556345631
vÍnce
Pro
Sheet Author
Thanks for helping Scott.  So "...making a translation object"  I'm guessing that means I need to create an object ie "transObj" with an array of attribute names used by the sheet's parser?  Excuse my ignorance.  I'm sure this is a basic concept.  Would you mind posting an example?