mirror of
https://github.com/TheRealOwenRees/pgn_to_tex.git
synced 2026-11-18 04:42:07 +00:00
Feature/variations (#5)
* support diagrams in variations. * Diagram data now carries an optional `path` (the SAN move sequence from the root) alongside the legacy `ply`; diagrams whose `path` resolves inside a variation are rendered inline within the variation. `parse_diagrams_json` returns a `diagram_data` record with `by_ply` and `by_path` maps. * make variation boards slightly smaller than the mainline boards * update changelog v0.0.2
This commit is contained in:
+14
-4
@@ -1,17 +1,27 @@
|
||||
module MoveMap = Ast.MoveMap
|
||||
module PathMap = Ast.PathMap
|
||||
open Yojson.Safe.Util
|
||||
|
||||
let path_key path_moves = String.concat " " path_moves
|
||||
|
||||
let parse_diagrams_json diagrams_json_str =
|
||||
try
|
||||
let json = Yojson.Safe.from_string diagrams_json_str in
|
||||
let diagrams_list = to_list json in
|
||||
List.fold_left
|
||||
(fun acc_map item ->
|
||||
(fun acc item ->
|
||||
let ply = item |> member "ply" |> to_int in
|
||||
let fen = item |> member "fen" |> to_string in
|
||||
MoveMap.add ply fen acc_map)
|
||||
MoveMap.empty diagrams_list
|
||||
with _ -> MoveMap.empty
|
||||
let acc =
|
||||
{ acc with Ast.by_ply = MoveMap.add ply fen acc.Ast.by_ply }
|
||||
in
|
||||
match item |> member "path" with
|
||||
| `List path_items ->
|
||||
let key = path_items |> List.map to_string |> path_key in
|
||||
{ acc with Ast.by_path = PathMap.add key fen acc.Ast.by_path }
|
||||
| _ -> acc)
|
||||
Ast.empty_diagrams diagrams_list
|
||||
with _ -> Ast.empty_diagrams
|
||||
|
||||
let to_tex pgn ~diagram_data ~clock =
|
||||
let game = Parsing.parse_pgn pgn in
|
||||
|
||||
Reference in New Issue
Block a user