Open Zalmute opened 1 year ago
You can automatically create a talent by using this macro and spreadsheet. https://docs.google.com/spreadsheets/d/1oQsMntqBt8HcQRAqZdQOjYqKPaMvidcVF7_Z9fJ1ek8/edit#gid=0
After copying the sheet, change the permissions and insert the ID at the address into the macro below. For sample url, 1oQsMntqBt8HcQRAqZdQOjYqKPaMvidcVF7_Z9fJ1ek8
let sheetId = "1oQsMntqBt8HcQRAqZdQOjYqKPaMvidcVF7_Z9fJ1ek8";
let url = `https://docs.google.com/spreadsheets/d/${sheetId}/gviz/tq?tq=SELECT+A%2cB%2cC%2cD%2cE%2cF%2cG%2cH%2cI%2cJ%2cK&sheet=Sheet1`
var folder = {};
let parentFolder = await Folder.create({
name: "Talents",
type: "Item"
});
var callback = async function(d) {
for (var i = 0; i < d.length; ++i) {
var item = d[i].c;
if (item[0] == null)
continue;
var talentType = (item[1] == null) ? "COMMON" : item[1].v;
if (talentType == "Facet") {
talentType = "STYLE";
} else if (talentType == "Ancestry") {
talentType = "RACE";
}
var condition = (item[2] == null) ? "-" : item[2].v;
if (condition == "○")
condition = "◎";
let className = (item[3] == null) ? "" : item[3].v;
let classType = "";
if (item[4] != null) {
className += " " + item[4].v;
classType = item[4].v;
}
var data = {
condition: condition,
talentType: talentType,
class: (item[3] == null) ? "" : item[3].v,
classType: classType,
timing: (item[5] == null) ? "" : item[5].v,
range: (item[6] == null) ? "" : item[6].v,
target: (item[7] == null) ? "" : item[7].v,
cost: (item[8] == null) ? "" : item[8].v,
description: `
<p>${(item[9] == null) ? "" : item[9].v}</p>
<p>${(item[10] == null) ? "" : item[10].v}</p>`
}
let folderName = item[1].v;
if (!folder.hasOwnProperty(folderName))
folder[folderName] = await Folder.create({name: folderName, type: "Item", parent: parentFolder.id, sorting: "m"});
if (className != "" && !folder[folderName].hasOwnProperty(className))
folder[folderName][className] = await Folder.create({name: className, type: "Item", parent: folder[folderName]._id, sorting: "m"});
let folderId = (className != "") ? folder[folderName][className]._id : folder[folderName]._id;
const name = item[0].v;
const itemData = {
name: name,
type: 'talent',
data: data,
folder: folderId,
permission: { default: 2 }
};
console.log(itemData);
await Item.create(itemData);
}
}
$.ajax({
type: "GET",
url: url,
success: function(resp) {
resp = resp.split("google.visualization.Query.setResponse(")[1];
resp = resp.split("});")[0];
resp += "}";
var data = JSON.parse(resp);
data = data.table.rows;
callback(data);
}
});
Hello, when I run this...it appears to simply create a folder named talents. Nothing else seems to import. I checked my file and I dont appear to have any permissions set on it. I am not sure where to go from here.
Does it work well when I just run the macro I made? If it is not possible to create a new spreadsheet, please change the authority of the spreadsheet to viewer through the guide below.
If I just run your sheet without changing anything it seems to work. I cant add anything to your current sheet though since yours is view only.
I am pretty sure I figured it out. I think my number of items to import was too big. Once I started deleting talents out it imported. I will have to import these slowly over time rather than all at once. I did notice that it did not seem to import everything together. Rather, even though items were all named with their own categories, it seemed to dump them outside of their named folder.
Please copy the spreadsheet and use it. This function only supports Talent, so you need to create a new macro to get other items.
So to be clear when I mean items, in this case I am talking about talents. The talents are in the item category. So what I am saying is that your code sets up folders and attempts to put talents into those categories but I have found that new talents do not go directly into the folders that are created by your process. Instead they are put in the root and requires lots of manual movement into the folders created by your progress rather than directly inserting them into the folders you create.
Now that I got this one working... Is there a way... we can create another few of these importers? It would be nice to have one for Facets, Ancestries and Facades?
Is there a good way to import talents from a. Json file? It would reduce the manual work a GM would need to do to get their players talents into the system if there was a plug in or just some documentation to help guide them.