Comparing version 0.1.0 to 1.0.0
'use strict'; | ||
var fs = require('q-io/fs'), | ||
moment = require('moment'), | ||
R = require('ramda'); | ||
var iconv = require('iconv-lite'), | ||
fs = require('q-io/fs'), | ||
parser = require('./parser'); | ||
iconv.extendNodeEncodings(); | ||
module.exports = function (file) { | ||
var getCharBlock = R.compose(R.head, R.match(/(?:\t\bcharacter=\n\t\{\n)([\S\s]+?\n\t\})/gm)); | ||
// Get individual chars from a char block; | ||
var getIndividualChars = R.match(/(?:\t{2}\d+?=[^]+?)(?=\n\t{2}\})/gm); | ||
var getLivingChars = R.forEach(function (char) { | ||
if (!char.match(/\bdeath_date/gm)) return char; | ||
}); | ||
var getChars = R.compose(getLivingChars, | ||
getIndividualChars, | ||
getCharBlock); | ||
var extractCurrentDate = /(\n\tdate=")(.+)(?=")/g; | ||
function splitString(obj, string) { | ||
if (obj[string]) { | ||
obj[string] = obj[string].split(' '); | ||
} | ||
} | ||
return fs.read(file) | ||
.then(function (data) { | ||
// Get current date and pass it to moment.js | ||
var currentDate = moment(new Date(extractCurrentDate.exec(data)[2])), | ||
chars = getChars(data); | ||
return chars.map(function (char) { | ||
char = char | ||
.replace(/=/g, ': ') // Replace = with : | ||
.replace(/\byes(?=\n)/g, true) // Convert all yes to true | ||
.replace(/\bno(?=\n)/g, false) // Convert all no to false | ||
.replace(/\t\t(?!\t\s)/g, '') // Clean up pre tabs | ||
.replace(/\n\t\b[a-z]+?:\s\n\t\{(\n\t[^]*?\n\t\}|\n\t[^]*?\})/g, '') // Remove unused blocks for now (demesne/ledger) | ||
.replace(/[\s\S]+?\n\{\n/g, '') // Remove CharID and trailing { | ||
.replace(/\n\t\{\n/g, '{') // Make the {} go on the same line | ||
.replace(/\t/g, '') // Remove Tabs | ||
.replace(/"|{| }/g,'') // Remove unused chars | ||
.split('\n') // Finally some pretty lines ready to be split... | ||
.map(function (line) { // Convert arrarys to objects | ||
return line.split(': '); | ||
}); | ||
char = R.fromPairs(char); | ||
splitString(char, 'attributes'); | ||
splitString(char, 'traits'); | ||
char.age = currentDate.diff(new Date(char.birth_date), 'years'); | ||
return char; | ||
}); | ||
}) | ||
return fs.read(file, {charset: 'iso-8859-1' }) | ||
.then(parser.checkIfCK2SaveFile) | ||
.then(parser.everything) | ||
.catch(function (error) { | ||
@@ -63,0 +14,0 @@ throw error; |
{ | ||
"name": "ck2parser", | ||
"version": "0.1.0", | ||
"description": "Crusader Kings 2 Savegame Parser. Extracts all characters from a savefile and outputs it as json", | ||
"version": "1.0.0", | ||
"description": "Crusader Kings 2 Savegame to JSON Parser.", | ||
"author": "Chris Kjær Sørensen", | ||
@@ -29,5 +29,6 @@ "homepage": "https://github.com/chriskjaer/ck2parser", | ||
"dependencies": { | ||
"moment": "^2.8.1", | ||
"q-io": "^1.11.3", | ||
"ramda": "^0.4.3" | ||
"iconv-lite": "^0.4.4", | ||
"moment": "^2.8.3", | ||
"q-io": "^1.11.5", | ||
"ramda": "^0.5.0" | ||
}, | ||
@@ -34,0 +35,0 @@ "devDependencies": { |
@@ -0,2 +1,23 @@ | ||
# [ Crusader Kings 2 Savegame Parser ](https://github.com/chriskjaer/ck2parser) | ||
> A CK2 Savegame to JSON parser for the Paradox Game: [Crusader Kings 2](http://www.crusaderkings.com/). | ||
## Features | ||
Takes the path to an uncompressed savegame and returns a promise which resolves | ||
to a json object. | ||
## Usage | ||
Install package with npm. `npm install ck2parser --save` | ||
``` | ||
var parse = require('ck2parser'); | ||
var SAVEGAME = '../path/to/you/savefile.ck2'; | ||
parse(SAVEGAME) | ||
.then(console.log) | ||
.catch(console.error) | ||
``` | ||
## Author | ||
@@ -11,4 +32,4 @@ | ||
## Copyright and license | ||
Copyright Chris Kjær Sørensen | ||
Copyright Chris Kjær Sørensen | ||
[MIT License](LICENSE-MIT) | ||
[LICENSE MIT](LICENSE.md) |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
35
4652
4
60
+ Addediconv-lite@^0.4.4
+ Addediconv-lite@0.4.24(transitive)
+ Addedramda@0.5.0(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
- Removedramda@0.4.3(transitive)
Updatedmoment@^2.8.3
Updatedq-io@^1.11.5
Updatedramda@^0.5.0