Skip to content

Instantly share code, notes, and snippets.

@phoenixlzx phoenixlzx/ess_worth.js
Last active Jan 31, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.