Roll20 Sheet Import Field

So I’ve wanted to be able to have something like the roll20 compendium for In Which We Live And Breathe but one that would be community expandable, creating a growing world of corps, gear, and contacts. As a result I’ve ended up developing some data import functionality that should be able to be plugged into just about any roll20 sheet to allow JSON users to paste JSON formatted data into their character sheet directly.

Video Demo

Code:


<label>IMPORT:<textarea name="attr_import"></textarea></label>
<script type="text/worker">
on("change:import", function() {
getAttrs(["import"], function(values) {
var text = values.import.replace(/(?:\r\n|\r|\n)/g, '');
var vals = JSON.parse(text);
var truevals = {};
for (var property in vals) {
if (vals.hasOwnProperty(property)) {
if(typeof vals[property] === "string" || typeof vals[property] === "number"){
truevals[property] = vals[property];
}
if(vals[property] instanceof Array){
for (i = 0; i < vals[property].length; ++i) {
var currentRow = vals[property][i];
var currentRowId = generateRowID();
for (valProp in currentRow) {
if (currentRow.hasOwnProperty(valProp)) {
truevals["repeating_"+property+"_"+currentRowId+"_"+valProp] = currentRow[valProp];
}
}
}
}
}
}
setAttrs(truevals);
setAttrs({import:""});
});
});
</script>

Responses


Reposts

Leave a Reply

Your email address will not be published. Required fields are marked *