Advertisement
Guest User

Export JSON script

a guest
Oct 18th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * @OnlyCurrentDoc
  3.  */
  4.  
  5. function exportToAvrae() {
  6.   var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  7.  
  8.   var locations = {
  9.     "Weapons": {
  10.       "Rows": [3, 1034],
  11.       "Columns": [0, 12],
  12.       "Title": 0, // Name
  13.       "Body": {
  14.         "Base": {
  15.           "Unique": 12,
  16.           "Class": 1,
  17.           "Cost": 11,
  18.         },
  19.         "Meta": {
  20.           "Crit Range": 2,
  21.           "Multiplier": 3,
  22.           "Attack Modifier": {
  23.             "Melee": 4,
  24.             "Range": 5,
  25.           },
  26.           "Damage Roll": {
  27.             "Melee": 6,
  28.             "Range": 7,
  29.           },
  30.           "Max Range": 8,
  31.           "Attachments": 9,
  32.         },
  33.       },
  34.       "Description": 10, // Function
  35.     },
  36.     "Light Houses": {
  37.       "Rows": [2, 1005],
  38.       "Columns": [0, 10],
  39.       "Title": 0, // Name
  40.       "Body": {
  41.         "Base": {
  42.           "Unique": 10,
  43.           "Class": 1,
  44.           "Cost": 9,
  45.         },
  46.         "Meta": {
  47.           "QP": 2,
  48.           "Range": 3,
  49.         },
  50.       },
  51.       "Description": 4,
  52.     },
  53.     "Reels": {
  54.       "Rows": [2, 1001],
  55.       "Columns": [0, 10],
  56.       "Title": 0, // Name
  57.       "Body": {
  58.         "Base": {
  59.           "Unique": 10,
  60.           "Class": 1,
  61.           "Cost": 9,
  62.         },
  63.         "Meta": {
  64.           "QP": 2,
  65.           "Range": 3,
  66.         },
  67.       },
  68.       "Description": 5,
  69.     },
  70.     "Observers": {
  71.       "Rows": [2, 1001],
  72.       "Columns": [0, 14],
  73.       "Title": 0, // Name
  74.       "Body": {
  75.         "Base": {
  76.           "Unique": 10,
  77.           "Class": 1,
  78.           "Cost": 14,
  79.         },
  80.         "Meta": {
  81.           "QP": 2,
  82.           "Attachment 1": 7,
  83.           "Attachment 2": 9,
  84.           "Attachment 3": 11,
  85.         }
  86.       },
  87.       "Description": 3,
  88.     },
  89.     "Armor Inventories": {
  90.       "Rows": [2, 1007],
  91.       "Columns": [0, 13],
  92.       "Title": 0, // Name
  93.       "Body": {
  94.         "Base": {
  95.           "Unique": 13,
  96.           "Class": 1,
  97.           "Cost": 12,
  98.         },
  99.         "Meta": {
  100.           "PR Bonus": 2,
  101.           "SR Bonus": 3,
  102.           "Movement Penalty": 4,
  103.           "Physical Reduction": 5,
  104.           "Shinsoo Reduction": 6,
  105.         },
  106.       },
  107.       "Description": 7,
  108.     },
  109.     "Pockets": {
  110.       "Rows": [2, 1000],
  111.       "Columns": [0, 4],
  112.       "Title": 0,
  113.       "Body": {
  114.         "Base": {
  115.           "Unique": 4,
  116.           "Class": 1,
  117.           "Cost": 3,
  118.         },
  119.         "Meta": {
  120.           "Floors": 2,
  121.         },
  122.       }
  123.     },
  124.     "Armor Inventories": {
  125.       "Rows": [2, 1004],
  126.       "Columns": [0, 5],
  127.       "Title": 0, // Name
  128.       "Body": {
  129.         "Base": {
  130.           "Unique": 5,
  131.           "Class": 1,
  132.           "Cost": 4,
  133.         },
  134.         "Meta": {
  135.           "Slots": 2,
  136.         },
  137.       },
  138.       "Description": 7,
  139.     },
  140.     "Misc Items": {
  141.       "Rows": [2, 999],
  142.       "Columns": [0, 11],
  143.       "Title": 0, // Name
  144.       "Body": {
  145.         "Base": {
  146.           "Unique": 11,
  147.           "Class": 1,
  148.           "Cost": 10,
  149.         },
  150.       },
  151.       "Description": 2,
  152.     },
  153.   }
  154.  
  155.   var rows = [];
  156.   for (var key in locations) {
  157.     var sheet = spreadsheet.getSheetByName(key);
  158.     var data = locations[key];
  159.    
  160.     var startRow = data["Rows"][0];
  161.     var endRow = data["Rows"][1];
  162.    
  163.     var startColumn = data["Columns"][0];
  164.     var endColumn = data["Columns"][1];
  165.    
  166.     var dataRange = sheet.getRange(startRow, startColumn + 1, endRow - startRow + 1, endColumn - startColumn + 1);
  167.    
  168.     var values = dataRange.getValues();
  169.     for (var i = 0; i < dataRange.getNumRows(); i++) {
  170.       var row = values[i];
  171.      
  172.       var title = row[data["Title"] - startColumn];
  173.       if (title == "" || row[1] === "") {
  174.         continue;
  175.       }
  176.      
  177.       var description = row[data["Description"] - startColumn];
  178.       description = isEmpty(description) ? "" : description;
  179.      
  180.       var body = data["Body"];
  181.       var base = body["Base"];
  182.       var bodyMeta = body["Meta"];
  183.      
  184.       var unique = row[base["Unique"] - startColumn];
  185.       var class = row[base["Class"] - startColumn];
  186.       var cost = row[base["Cost"] - startColumn];
  187.      
  188.       var bodyText = "";
  189.      
  190.       if (unique === "y") {
  191.         bodyText += "**Unique Item**\n"
  192.       }
  193.      
  194.       if (!isEmpty(class)) {
  195.         bodyText += "**Class:** " + class + "\n";
  196.       }
  197.      
  198.       if (!isEmpty(String(cost))) {
  199.         bodyText += "**Cost:** " + cost + "\n";
  200.       }
  201.      
  202.       if (base != null) {
  203.         for (var key in bodyMeta) {
  204.           var item = String(row[bodyMeta[key] - startColumn]);
  205.           if (!isEmpty(item)) {
  206.             bodyText += "**" + key + ":** " + item + "\n";
  207.           }
  208.         }
  209.       }
  210.      
  211.       rows.push({"name": title, "meta": bodyText, "desc": description});
  212.     }
  213.   }
  214.  
  215.   var ui = SpreadsheetApp.getUi();
  216.   ui.alert("Exported Items", JSON.stringify(rows), ui.ButtonSet.OK);
  217. }
  218.  
  219. function isEmpty(text) {
  220.   if (text == null) {
  221.     return true;
  222.   }
  223.   text = text.trim().toLowerCase();
  224.   return text == "undefined" || text === "null"  || text == null || text === "" || text === "-" || text === "none" || text === "n/a" || text === "tbd" || text === "n/a | tbd";
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement