diff options
| author | Nicolas Paul <n@nc0.fr> | 2024-03-09 21:52:37 +0100 |
|---|---|---|
| committer | Nicolas Paul <n@nc0.fr> | 2024-03-09 21:52:37 +0100 |
| commit | 6c7211f27c6243928d7d008ad8f96ad316e0ca23 (patch) | |
| tree | e3ad57e0845caf4257a3ce4b4cb675b0ddcc6251 /LICENSE | |
| parent | 8f8f649b8a0af56c1fa726b674ac084174ff7032 (diff) | |
format: Add L2TF implementation
(A spec might come later)
The Life2 Text Format (L2TF) is a ASCII-based file format that allows
the sharing of a Life2 board easily. The format is designed to be easy
to parse by both machines and humans, as it is pretty natural,
reprensenting a grid as a set of lines.
As said in the beginning, the format is currently only defined in the
index.js file, however a specification will be done later (probably
during the week), for now, this is enough.
Currently, the format is composed of the following:
CELL KIND CHARACTER UINT8 REPR
EMPTY . 0
TEAM_A a 1
TEAM_B b 2
BARRIER # 3
A grid is supposedly a set of lines composed of the aforementionned
characters, for illustration, a Boad like the following:
const board = [[3, 3, 3, 3, 3, 3, 3, 3, 3],
[3, 0, 1, 0, 0, 0, 0, 2, 3],
[3, 0, 1, 0, 1, 2, 2, 2, 3],
[3, 0, 0, 1, 1, 2, 1, 1, 3],
[3, 0, 0, 0, 2, 2, 2, 0, 3],
[3, 3, 3, 3, 3, 3, 3, 3, 3]]; // 9x6
will be represented in the following file:
(file: //.../board.l2tf)
#########\n
#.a....b#\n
#.a.abbb#\n
#..aabaa#\n
#...bbb.#\n
#########\n
The current implementation, in JavaScript, exposes only three elements:
two functions and a string-based C-like enumeration.
The API is really simple, only being based on the parse() and
stringify() methods. JavaScript experts may recognize a similar pattern
as the standard JSON API available.
A typical user flow of the system may be:
import * as Life2 from '@life2/game';
import * as L2TF from '@life2/format';
const game = new Life2.World(...);
// ... init game
// Save the current board state in a file to share it with others
const curr = game.board.getGrid();
const text = L2TF.stringify(curr);
shareFile(new File(text));
Signed-off-by: Nicolas Paul <n@nc0.fr>
Diffstat (limited to 'LICENSE')
0 files changed, 0 insertions, 0 deletions
