eu4-text-file-to-json-parser-js
This is a TypeScript library which contains a function which converts the types of text files used for modding the game Europa Universalis 4 to a JSON format for easier use.
Installation and Usage
$ npm install --save-dev @sean_kenny/eu4-text-file-to-json-parser-js
# or
$ yarn add -D @sean_kenny/eu4-text-file-to-json-parser-js
An output can then be generated by calling the parseEu4TextFileToJson
function, which is the only function in the library.
const { outputJSONData } = await parseEu4TextFileToJson({
inputFilePath: '/path/to/your/file/your_file.txt'
})
Some sample inputs and outputs
The following are some examples of data that can be contained in your_file.txt
and the JSON they will parse to.
#Cannor
damesneck_sea_area = {
1293 1276 1275 1274 1269 1270 1272 1271
}
dameshead_sea_area = {
1268 1928 1253 1266 1257 1267 1252 1926 1255 1258
}
bay_of_wines_sea_area = {
1278 1297 1292 1471 1472 1291
}
{
"damesneck_sea_area": [ "1293", "1276", "1275", "1274", "1269", "1270", "1272", "1271" ],
"dameshead_sea_area": [ "1268", "1928", "1253", "1266", "1257", "1267", "1252", "1926", "1255", "1258" ],
"bay_of_wines_sea_area": ["1278", "1297", "1292", "1471", "1472", "1291"]
}
# province id = rotation in degrees, 0 is pointing right, then ccw)
# can be reloaded ingame by cmd: reloadtradewinds
1473 = 180
1568 = 200
1565 = 180
1583 = 190
1480 = 170
1484 = 190
1571 = 175
1498 = 250
1585 = 220
1599 = 220
1590 = 250
1589 = 190
{
"1473": "180",
"1480": "170",
"1484": "190",
"1498": "250",
"1565": "180",
"1568": "200",
"1571": "175",
"1583": "190",
"1585": "220",
"1589": "190",
"1590": "250",
"1599": "220"
}
leechdens_region = {
areas = {
serpenthome_area
spider_coast_area
screaming_jungle_area
middans_area
edgewoods_area
ungoths_trail_area
red_isle_area
leechdens_maw_area
}
monsoon = {
00.12.01
00.12.30
}
monsoon = {
00.01.01
00.04.30
}
}
{
"leechdens_region": {
"areas": [
"serpenthome_area",
"spider_coast_area",
"screaming_jungle_area",
"middans_area",
"edgewoods_area",
"ungoths_trail_area",
"red_isle_area",
"leechdens_maw_area"
],
"monsoon": ["00.12.01", "00.12.30", "00.01.01", "00.04.30"]
}
}
tree = { 3 4 7 10 }
{
"tree": ["3", "4", "7", "10"]
}
add_core = I43
culture = green_orc
add_core = I34
{
"add_core": ["I43", "I34"],
"culture": "green_orc"
}
is_city = yes
add_permanent_province_modifier = {
name = harimari_minority_coexisting_small
duration = -1
}
add_permanent_province_modifier = {
name = temple_complex
duration = -1
}
{
"is_city": "yes",
"add_permanent_province_modifier": [
{ "name": "harimari_minority_coexisting_small", "duration": "-1" },
{ "name": "temple_complex", "duration": "-1" }
]
}
More full examples are available by perusing the /test/sample-inputs
and /test/expected-outputs
folders in the repository.
Acknowledgements
All sample input files which are used for testing are pulled directly from the ab937cf899b75f74662a17574bd0d46072793beb
version of Anbennar which was published to Bitbucket on August 23rd 2024. All credit for those files goes to their creator.
You're welcome to use this library for anything you'd like. I don't think there's a set spec for the files Paradox Interactive uses for their text files so I wouldn't be surprised if there's some files this doesn't parse correctly. Please reach out if you have a file in the EU4 game files or a particular mod which is not processed properly by this library and I'd be happy to work on something to make it work for you.