Last active
January 31, 2016 14:04
-
-
Save phoenixlzx/050ccc5a1c1e61f8d1da to your computer and use it in GitHub Desktop.
Essentials worth.txt generator from items.csv
This file contains hidden or 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
'use strict'; | |
/* | |
* 2016 Phoenix Nemo <[email protected]> | |
* This script converts Essentials items.csv to worth.txt file | |
* don't forget to edit prices yourself! | |
**/ | |
var fs = require('fs'); | |
var yaml = require('js-yaml'); | |
var itemfile = fs.readFileSync('./items.csv', 'utf8'); | |
var oldworth = yaml.safeLoad(fs.readFileSync('./worth_orig.txt', 'utf8')); | |
var items = { | |
worth: {} | |
}; | |
var have = []; | |
function parseItem(d) { | |
d = d.split('\n'); | |
d.forEach(function(item) { | |
if (item === '' || item.indexOf('#') === 0) { | |
// continue; | |
} else { | |
var i = item.split(','); | |
var id = i[1] + ':' + i[2]; | |
// avoid item duplication | |
if (have.indexOf(id) === -1) { | |
items.worth[i[0]] = oldworth.worth[i[0]] ? oldworth.worth[i[0]] : 0.0; | |
have.push(id); | |
} | |
} | |
}); | |
} | |
parseItem(itemfile); | |
fs.writeFileSync('./worth_new.txt', yaml.safeDump(items), 'utf8'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment