Skip to content

p2004a/recoil-tdf

Repository files navigation

Recoil RTS TDF parser and serializer

TypeScript parser and serializer of the Recoil/Spring RTS engine TDF format with focus on correctness.

Recoil RTS uses a custom TDF format for some configuration files like start scripts. This small, zero dependencies, library offers a parser and serializer of that format tested against the official Lua parser from the engine. The parser is generated from grammar using tsPEG, and serializer validates all values to make sure that they will always deserialize correctly.

Installation

npm install --save recoil-tdf

Usage

Below is an example of using parser and serializer.

import {parse, serialize} from 'recoil-tdf';

const tdfDoc = `
[SECTION1]
{
	key1 = 1;
	key2 = asd;
	[SUB] {
		x = y;
	}
}
globalKey = "a;b;c;d";
`;
console.log(parse(tdfDoc));
/* Output:
{
  section1: { key1: '1', key2: 'asd', sub: { x: 'y' } },
  globalkey: 'a;b;c;d'
}
*/

const obj = {
	'a': 1,
	'b': true,
	'SEC': {
		'c': 'asd;asd'
	}
};
console.log(serialize(obj));
/* Output:
a = 1;
b = true;
[SEC]
{
	c = "asd;asd";
}
*/

About

Parser and serializer of Recoil/Spring RTS TDF format.

Resources

License

Stars

Watchers

Forks

Packages

No packages published