xgparse 0.1.2__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {xgparse-0.1.2 → xgparse-0.1.3}/PKG-INFO +1 -1
- {xgparse-0.1.2 → xgparse-0.1.3}/pyproject.toml +1 -1
- xgparse-0.1.3/src/xgparse/__init__.py +3 -0
- xgparse-0.1.2/src/xgparse/convertxg2txt.py → xgparse-0.1.3/src/xgparse/convertxg.py +18 -6
- {xgparse-0.1.2 → xgparse-0.1.3}/src/xgparse/xgstruct.py +10 -2
- xgparse-0.1.2/src/xgparse/__init__.py +0 -2
- {xgparse-0.1.2 → xgparse-0.1.3}/LICENSE +0 -0
- {xgparse-0.1.2 → xgparse-0.1.3}/README.md +0 -0
- {xgparse-0.1.2 → xgparse-0.1.3}/src/xgparse/extractxgdata.py +0 -0
- {xgparse-0.1.2 → xgparse-0.1.3}/src/xgparse/xgimport.py +0 -0
- {xgparse-0.1.2 → xgparse-0.1.3}/src/xgparse/xgutils.py +0 -0
- {xgparse-0.1.2 → xgparse-0.1.3}/src/xgparse/xgzarc.py +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#
|
|
2
|
-
#
|
|
2
|
+
# convertxg.py - XG data to text conversion tool
|
|
3
3
|
# Copyright (C) 2026 Gergely Elias <gergely.elias@gmail.com>
|
|
4
4
|
#
|
|
5
5
|
# This program is free software: you can redistribute it and/or modify
|
|
@@ -19,15 +19,23 @@
|
|
|
19
19
|
from __future__ import annotations
|
|
20
20
|
|
|
21
21
|
import pprint
|
|
22
|
+
from collections.abc import Generator
|
|
22
23
|
|
|
23
24
|
from . import xgimport
|
|
24
25
|
from . import xgstruct
|
|
25
26
|
|
|
26
27
|
|
|
27
|
-
def
|
|
28
|
-
|
|
28
|
+
def convert_xg_to_py_dataclasses(
|
|
29
|
+
path: str,
|
|
30
|
+
) -> Generator[xgstruct.GameRecord | xgstruct.RolloutContextEntry, None, None]:
|
|
31
|
+
"""Yield parsed records from an XG file as dataclass objects.
|
|
32
|
+
|
|
33
|
+
Produces the same sequence as :func:`convert_xg_to_text` but returns
|
|
34
|
+
live dataclass instances instead of a text dump. :class:`~xgstruct.UnimplementedEntry`
|
|
35
|
+
records are skipped (matching the text-dump behaviour). Rollout records
|
|
36
|
+
are yielded after all game records.
|
|
37
|
+
"""
|
|
29
38
|
importer = xgimport.Import(path)
|
|
30
|
-
output = []
|
|
31
39
|
file_version = -1
|
|
32
40
|
|
|
33
41
|
for segment in importer.get_file_segments():
|
|
@@ -40,7 +48,7 @@ def convert_xg_to_text(path: str) -> bytes:
|
|
|
40
48
|
if isinstance(rec, xgstruct.HeaderMatchEntry):
|
|
41
49
|
file_version = rec.version
|
|
42
50
|
if not isinstance(rec, xgstruct.UnimplementedEntry):
|
|
43
|
-
|
|
51
|
+
yield rec
|
|
44
52
|
|
|
45
53
|
elif segment.seg_type is xgimport.SegmentType.XG_ROLLOUTS:
|
|
46
54
|
segment.fd.seek(0)
|
|
@@ -48,6 +56,10 @@ def convert_xg_to_text(path: str) -> bytes:
|
|
|
48
56
|
rec = xgstruct.read_rollout_record(segment.fd)
|
|
49
57
|
if rec is None:
|
|
50
58
|
break
|
|
51
|
-
|
|
59
|
+
yield rec
|
|
52
60
|
|
|
61
|
+
|
|
62
|
+
def convert_xg_to_text(path: str) -> bytes:
|
|
63
|
+
"""Convert XG data to text format, returning the text as bytes."""
|
|
64
|
+
output = [pprint.pformat(rec, width=160) for rec in convert_xg_to_py_dataclasses(path)]
|
|
53
65
|
return "\n".join(output).encode("utf-8")
|
|
@@ -31,12 +31,20 @@ import struct
|
|
|
31
31
|
import uuid
|
|
32
32
|
from dataclasses import dataclass, field
|
|
33
33
|
from enum import IntEnum
|
|
34
|
-
from typing import BinaryIO
|
|
34
|
+
from typing import BinaryIO, TypeAlias
|
|
35
35
|
|
|
36
36
|
from . import xgutils
|
|
37
37
|
|
|
38
38
|
# Convenience alias used throughout: a 26-element signed-byte board position.
|
|
39
|
-
Position = tuple[
|
|
39
|
+
Position: TypeAlias = tuple[
|
|
40
|
+
int, int, int, int, int, int, int, int, int, int,
|
|
41
|
+
int, int, int, int, int, int, int, int, int, int,
|
|
42
|
+
int, int, int, int, int, int
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
# An 8-element move tuple: up to 4 checker moves encoded as (src1, dst1, src2, dst2, ...),
|
|
46
|
+
# padded with -1 sentinels for unused slots.
|
|
47
|
+
MoveTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int]
|
|
40
48
|
|
|
41
49
|
|
|
42
50
|
# ---------------------------------------------------------------------------
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|