Skip to content

Instantly share code, notes, and snippets.

@phoenixlzx
Last active January 31, 2016 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phoenixlzx/050ccc5a1c1e61f8d1da to your computer and use it in GitHub Desktop.
Save phoenixlzx/050ccc5a1c1e61f8d1da to your computer and use it in GitHub Desktop.
Essentials worth.txt generator from items.csv
'use strict';
/*
* 2016 Phoenix Nemo <i@phoenixlzx.com>
* 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