Created
December 30, 2023 21:37
-
-
Save keipes/fa72b2700d5802366d6bf2ff84750462 to your computer and use it in GitHub Desktop.
Sorrow's Scribbles AppsScript export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myFunction() { | |
const ss = SpreadsheetApp.getActiveSpreadsheet(); | |
const sheets = ss.getSheets(); | |
const data = {}; | |
for (let i = 7; i < sheets.length; i++) { //sheets.length | |
const sheet = sheets[i]; | |
const colorObject = sheet.getTabColorObject(); | |
const tabColorHex = colorObject.asRgbColor().asHexString(); | |
switch (tabColorHex) { | |
case '#ffffff': | |
// title page | |
// console.log('skip'); | |
break; | |
case '#000000': | |
// non-weapon data | |
// console.log('skip'); | |
break; | |
case '#ffff00': | |
processSheet(data, 'Sidearms', sheet); | |
break; | |
case '#00ff00': | |
processSheet(data, 'SMG', sheet); | |
break; | |
case '#ff0000': | |
processSheet(data, 'Assault Rifles', sheet); | |
break; | |
case '#0000ff': | |
processSheet(data, 'LMG', sheet); | |
break; | |
case '#ff9900': | |
processSheet(data, 'DMR', sheet); | |
break; | |
case '#9900ff': | |
processSheet(data, 'Bolt Action', sheet); | |
break; | |
case '#00ffff': | |
processSheet(data, 'Shotgun/Utility', sheet); | |
break; | |
default: | |
console.warn('Unrecognized tab color: ' + tabColorHex); | |
break; | |
} | |
} | |
console.log(data); | |
displayText(JSON.stringify(data)); | |
} | |
function processSheet(data, category, sheet) { | |
if (!data[category]) { | |
data[category] = []; | |
} | |
const weaponData = { | |
name: sheet.getName(), | |
stats: [] | |
}; | |
data[category].push(weaponData); | |
const damageValues = {}; | |
let currentAmmoType = ''; | |
let currentBarrelType = ''; | |
const range = sheet.getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn()); | |
const values = range.getValues(); | |
const mergedRanges = range.getMergedRanges(); | |
const mergedRows = {}; | |
for (let i = 0; i < mergedRanges.length; i++) { | |
if (mergedRanges[i].getColumn() == 4) { | |
mergedRows[mergedRanges[i].getRow()] = mergedRanges[i].getEndRow(); | |
} | |
} | |
for (let i in values) { | |
const ammoType = values[i][1].toString(); | |
if (ammoType && ammoType != 'x' && ammoType != currentAmmoType) { | |
if (ammoType == 'x' || ammoType == 'CellImage') { | |
// skip these | |
} else if (ammoType.search(/ST/) > -1) { | |
currentAmmoType = 'Standard'; | |
} else if (ammoType.search(/DEF/) > -1) { | |
currentAmmoType = 'Default'; | |
} else if (ammoType.search(/CC/) > -1) { | |
currentAmmoType = 'Close Combat'; | |
} else if (ammoType.search(/SS/) > -1) { | |
currentAmmoType = 'Subsonic'; | |
} else if (ammoType.search(/AM/) > -1) { | |
currentAmmoType = 'Anti-Material'; | |
} else if (ammoType.search(/AMHP/) > -1) { | |
currentAmmoType = 'Anti-Material High Powerr'; | |
} else if (ammoType.search(/HP/) > -1) { | |
currentAmmoType = 'High Power'; | |
} else if (ammoType.search(/AP/) > -1) { | |
currentAmmoType = 'Armor Piercing'; | |
} else if (ammoType.search(/FL/) > -1) { | |
currentAmmoType = 'Flechette'; | |
} else if (ammoType.search(/#01/) > -1) { | |
currentAmmoType = '#01 Buckshot'; | |
} else if (ammoType.search(/#00/) > -1) { | |
currentAmmoType = '#00 Buckshot'; | |
} else if (ammoType.search(/#4/) > -1) { | |
currentAmmoType = '#4 Buckshot'; | |
} else if (ammoType.search(/SL/) > -1) { | |
currentAmmoType = 'Slug'; | |
} else if (ammoType.search(/BR/) > -1) { | |
currentAmmoType = 'Bolt Rack'; | |
} else if (ammoType.search(/SB/) > -1) { | |
currentAmmoType = 'Standard Bolts'; | |
} else if (ammoType.search(/EB/) > -1) { | |
currentAmmoType = 'Explosive Bolts'; | |
} else { | |
// console.warn("Unrecognized ammo type for " + sheet.getName() + " : " + ammoType); | |
currentAmmoType = ''; | |
} | |
} | |
const barrelType = values[i][2].toString(); | |
if (barrelType && barrelType != 'Comparison Tool' && barrelType != 'Barrel (Damage Modifier)') { | |
if (barrelType.search(/Factory/) > -1 || barrelType.search(/Default/) > -1 || barrelType.search(/CCN/) > -1) { | |
currentBarrelType = 'Factory'; | |
} else if (barrelType.search(/Extended/) > -1) { | |
currentBarrelType = 'Extended'; | |
} else if (barrelType.search(/Shortened/) > -1) { | |
currentBarrelType = 'Shortened'; | |
} else if (barrelType.search(/GAR45/) > -1) { | |
currentBarrelType = 'GAR45'; | |
} else if (barrelType.search(/Spook Y/) > -1) { | |
currentBarrelType = 'Spook Y'; | |
} else if (barrelType.search(/NVK-SHH/) > -1) { | |
currentBarrelType = 'NVK-SHH'; | |
} else if (barrelType.search(/NVK-BOX/) > -1) { | |
currentBarrelType = 'NVK-BOX'; | |
} else if (barrelType.search(/6KU/) > -1) { | |
currentBarrelType = '6KU'; | |
} else if (barrelType.search(/PB/) > -1) { | |
currentBarrelType = 'PB'; | |
} else if (barrelType.search(/Type 4/) > -1) { | |
currentBarrelType = 'Type 4'; | |
} else { | |
console.warn("Unrecognized barrel type for " + sheet.getName() + " : " + barrelType); | |
currentBarrelType = ''; | |
} | |
} | |
// if ((currentBarrelType == 'Factory' || currentBarrelType == 'Extended' || currentBarrelType == 'Shortened') && currentAmmoType != '') { | |
if (currentBarrelType != '' && currentAmmoType != '') { | |
const startRow = parseInt(i) + 1; | |
const endRow = mergedRows[startRow]; | |
if (endRow && currentAmmoType != '') { | |
const stats = {}; | |
stats.barrelType = currentBarrelType; | |
stats.ammoType = currentAmmoType; | |
stats.dropoffs = processDropoff(values, startRow - 1, endRow + 1); | |
// weaponData[currentAmmoType][currentBarrelType]['dropoff'] = processDropoff(values, startRow - 1, endRow + 1); | |
const velocity = matchInt(values[i][3]); | |
if (velocity) { | |
stats.velocity = velocity; | |
} | |
const rpmSingle = matchInt(values[i][10]); | |
if (rpmSingle) { | |
stats.rpmSingle = rpmSingle; | |
} | |
const rpmBurst = matchInt(values[i][11]); | |
if (rpmBurst) { | |
stats.rpmBurst = rpmBurst; | |
} | |
const rpmAuto = matchInt(values[i][12]); | |
if (rpmAuto) { | |
stats.rpmAuto = rpmAuto; | |
} | |
for (const stat of weaponData.stats) { | |
if (stat.barrelType == stats.barrelType) { | |
} | |
} | |
// weaponData.stats = weaponData.stats.filter(stat => { | |
// if (stat.barrelType == stats.barrelType && stat.ammoType == stats.barrelType) { | |
// console.error('pruning duplicate stats!') | |
// } | |
// return !(stat.barrelType == stats.barrelType && stat.ammoType == stats.barrelType); | |
// }); | |
weaponData.stats.push(stats); | |
} | |
} | |
// if (!weaponData[currentAmmoType]) { | |
// weaponData[currentAmmoType] = {}; | |
// } | |
// if (!weaponData[currentAmmoType][currentBarrelType]) { | |
// weaponData[currentAmmoType][currentBarrelType] = {}; | |
// } | |
// if (currentBarrelType == 'Factory' && currentAmmoType != '') { | |
// if (!weaponData[currentAmmoType]) { | |
// weaponData[currentAmmoType] = {}; | |
// } | |
// if (!weaponData[currentAmmoType][currentBarrelType]) { | |
// weaponData[currentAmmoType][currentBarrelType] = {}; | |
// } | |
// const velocity = matchInt(values[i][3]); | |
// if (velocity) { | |
// weaponData[currentAmmoType][currentBarrelType]['velocity'] = velocity; | |
// } | |
// const rpmSingle = matchInt(values[i][10]); | |
// if (rpmSingle) { | |
// weaponData[currentAmmoType][currentBarrelType]['rpmSingle'] = rpmSingle; | |
// } | |
// const rpmBurst = matchInt(values[i][11]); | |
// if (rpmBurst) { | |
// weaponData[currentAmmoType][currentBarrelType]['rpmBurst'] = rpmBurst; | |
// } | |
// const rpmAuto = matchInt(values[i][12]); | |
// if (rpmAuto) { | |
// weaponData[currentAmmoType][currentBarrelType]['rpmAuto'] = rpmAuto; | |
// } | |
// } | |
} | |
} | |
function processDropoff(values, startRow, endRow) { | |
const dropoffs = []; | |
for (let i = startRow; i < endRow - 1; i++) { | |
const damage = matchInt(values[i][4]); | |
const distance = matchInt(values[i][5]); | |
if (typeof damage != 'undefined' && typeof distance != 'undefined') { | |
dropoffs.push({ | |
'damage': damage, | |
'range': distance | |
}); | |
} | |
} | |
return dropoffs; | |
} | |
function matchInt(value) { | |
if (typeof value == 'number') { | |
return value; | |
} else if (typeof value == 'string') { | |
const m = value.match(/[\d^ ]+/); | |
if (m && m.length > 0) { | |
return parseInt(m[0]); | |
} | |
} | |
} | |
function displayText(text) { | |
var output = HtmlService.createHtmlOutput("<textarea style='width:100%;' rows='20'>" + text + "</textarea>"); | |
output.setWidth(800) | |
output.setHeight(400); | |
SpreadsheetApp.getUi() | |
.showModalDialog(output, 'Exported JSON'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment