-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwriters.py
More file actions
49 lines (35 loc) · 1.66 KB
/
writers.py
File metadata and controls
49 lines (35 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import re
from pathlib import Path
from itemParser import Item
_COLOR_CODE = re.compile(r'\^[0-9a-fA-F]{6}')
_SEPARATOR = '_______________________'
def _strip_color_codes(text: str) -> str:
return _COLOR_CODE.sub('', text)
def write_items(items: list[Item], path: str | Path) -> None:
lines = (f"{item.id}#{item.name}#" for item in items)
Path(path).write_text('\n'.join(lines) + '\n', encoding='utf-8')
print(f"✓ {len(items)} items → {path}")
def write_descriptions(items: list[Item], path: str | Path) -> None:
blocks = []
for item in items:
if not item.description:
continue
lines = []
for line in item.description:
clean = _strip_color_codes(line)
lines.append('--------------------------' if clean.startswith('___') else clean)
blocks.append(f"{item.id}#\n" + '\n'.join(lines) + "\n#")
Path(path).write_text('\n'.join(blocks) + '\n', encoding='utf-8')
print(f"✓ {len(blocks)} descriptions → {path}")
def write_slot_count(items: list[Item], path: str | Path) -> None:
slotted = [item for item in items if item.slot_count > 0]
lines = (f"{item.id}#{item.slot_count}#" for item in slotted)
Path(path).write_text('\n'.join(lines) + '\n', encoding='utf-8')
print(f"✓ {len(slotted)} slotted items → {path}")
def write_skills_sp(skills: list, path: str | Path) -> None:
blocks = []
for handle, sp_values in skills:
lines = [f"{handle}#"] + [f"{v}#" for v in sp_values] + ["@"]
blocks.append('\n'.join(lines))
Path(path).write_text('\n'.join(blocks) + '\n', encoding='utf-8')
print(f"✓ {len(blocks)} skills → {path}")