155 lines
4.8 KiB
Markdown
155 lines
4.8 KiB
Markdown
---
|
|
id: wiki-2026-0508-ndf-parse-패키지
|
|
title: ndf-parse 패키지
|
|
category: 10_Wiki/Topics
|
|
status: verified
|
|
canonical_id: self
|
|
aliases: [ndf-parse, NDF parser, Eugen NDF]
|
|
duplicate_of: none
|
|
source_trust_level: B
|
|
confidence_score: 0.85
|
|
verification_status: applied
|
|
tags: [python, parser, modding, wargame, ndf]
|
|
raw_sources: []
|
|
last_reinforced: 2026-05-10
|
|
github_commit: pending
|
|
tech_stack:
|
|
language: Python
|
|
framework: ndf-parse (PyPI)
|
|
---
|
|
|
|
# ndf-parse 패키지
|
|
|
|
## 매 한 줄
|
|
> **"매 Eugen Systems 의 NDF (Niche Definition Files) format 의 Python parser/serializer"**. 매 Wargame: Red Dragon, Steel Division, WARNO 의 mod 작성에 사용. 매 lossless round-trip + AST manipulation 을 제공.
|
|
|
|
## 매 핵심
|
|
|
|
### 매 NDF format 이란
|
|
- Eugen 의 game data 정의 언어 — 매 unit stats, weapon, sound, UI binding 의 declarative description.
|
|
- Lua-like syntax + GUID reference + template instantiation. 매 plain text but very large (수만 lines).
|
|
|
|
### 매 ndf-parse 가 해주는 것
|
|
- **Parse**: NDF text → Python AST (List / Object / Map / Reference / Template node).
|
|
- **Walk**: tree traversal + by-name lookup.
|
|
- **Mutate**: in-place edit, insert, delete.
|
|
- **Serialize**: AST → NDF text, 매 formatting 의 보존 (whitespace, comments).
|
|
|
|
### 매 응용
|
|
1. WARNO / Steel Division mod 의 unit balancing.
|
|
2. Bulk find-replace (e.g. all small-arms 의 damage +10%).
|
|
3. Mod merge tool — 매 multiple mod 의 conflict-free combination.
|
|
4. CI validation — 매 NDF schema 의 lint.
|
|
|
|
## 💻 패턴
|
|
|
|
### Install + 매 first parse
|
|
```python
|
|
# pip install ndf-parse
|
|
import ndf_parse as ndf
|
|
|
|
with open("GameData/Generated/Gameplay/Gfx/UniteDescriptor.ndf", "r", encoding="utf-8") as f:
|
|
source = ndf.load(f) # returns ndf.model.List
|
|
print(type(source), len(source))
|
|
```
|
|
|
|
### 매 unit lookup by name
|
|
```python
|
|
unit = source.by_name("Descriptor_Unit_M1A2_Abrams_US").value
|
|
# unit is an Object node
|
|
```
|
|
|
|
### 매 module 안의 specific value 변경
|
|
```python
|
|
modules = unit.by_name("ModulesDescriptors").value
|
|
for module in modules:
|
|
if module.value.type == "TBaseDamageModuleDescriptor":
|
|
hp_row = module.value.by_name("MaxPhysicalDamages")
|
|
hp_row.value = "12" # was "10"
|
|
break
|
|
```
|
|
|
|
### 매 weapon damage 의 bulk +10%
|
|
```python
|
|
def bump_damage(node):
|
|
for member in node:
|
|
if member.member == "PhysicalDamages":
|
|
try:
|
|
old = float(member.value)
|
|
member.value = f"{old * 1.10:.2f}"
|
|
except ValueError:
|
|
pass
|
|
if hasattr(member.value, "__iter__"):
|
|
bump_damage(member.value)
|
|
|
|
bump_damage(source)
|
|
```
|
|
|
|
### 매 serialize back
|
|
```python
|
|
with open("Mod/UniteDescriptor.ndf", "w", encoding="utf-8") as f:
|
|
ndf.write(source, f)
|
|
# 매 round-trip: comments / whitespace 의 가능한 한 보존
|
|
```
|
|
|
|
### 매 새 unit 의 clone + rename
|
|
```python
|
|
import copy
|
|
template = source.by_name("Descriptor_Unit_M1A2_Abrams_US")
|
|
clone = copy.deepcopy(template)
|
|
clone.name = "Descriptor_Unit_M1A3_Abrams_Custom"
|
|
source.add(clone)
|
|
```
|
|
|
|
### CLI mod build pipeline
|
|
```python
|
|
# build_mod.py
|
|
from pathlib import Path
|
|
import ndf_parse as ndf
|
|
|
|
for src_path in Path("GameData").rglob("*.ndf"):
|
|
with src_path.open(encoding="utf-8") as f:
|
|
tree = ndf.load(f)
|
|
apply_patches(tree, src_path.name)
|
|
out = Path("Mod") / src_path.relative_to("GameData")
|
|
out.parent.mkdir(parents=True, exist_ok=True)
|
|
with out.open("w", encoding="utf-8") as f:
|
|
ndf.write(tree, f)
|
|
```
|
|
|
|
## 매 결정 기준
|
|
| 상황 | Approach |
|
|
|---|---|
|
|
| 매 single field 변경 | by_name + value 직접 assign |
|
|
| 매 bulk pattern 변경 | recursive walker function |
|
|
| 매 새 unit 추가 | deepcopy + rename + add |
|
|
| 매 cross-file reference | 매 파일별 parse + cross-link by GUID |
|
|
| 매 schema validation | custom walker + assertion |
|
|
|
|
**기본값**: 매 ndf-parse + Python script + git for version control. 매 manual NDF text edit 의 X.
|
|
|
|
## 🔗 Graph
|
|
- 부모: [[Game Modding]] · [[Domain-Specific Parser]]
|
|
- 변형: [[Lark Parser]] · [[Tree-sitter]]
|
|
- 응용: [[WARNO Modding]] · [[Steel Division Modding]]
|
|
- Adjacent: [[AST Manipulation]] · [[Source-to-Source Transformation]]
|
|
|
|
## 🤖 LLM 활용
|
|
**언제**: NDF mod 작성 + LLM 의 patch generation, schema 추론, balance tweak suggestion.
|
|
**언제 X**: 매 binary game asset (DDS, BANK) — 매 NDF X.
|
|
|
|
## ❌ 안티패턴
|
|
- **매 raw regex 의 NDF edit**: 매 nested template 의 corruption 위험.
|
|
- **encoding 누락**: NDF 는 UTF-8 (BOM 가능) — 매 default open() 의 fail.
|
|
- **매 reference name 의 typo**: silent — 매 by_name() 의 None return.
|
|
|
|
## 🧪 검증 / 중복
|
|
- Verified (ndf-parse PyPI docs, Eugen modding wiki 2024).
|
|
- 신뢰도 B (community-maintained).
|
|
|
|
## 🕓 Changelog
|
|
| 날짜 | 변경 |
|
|
|---|---|
|
|
| 2026-05-08 | Phase 1 |
|
|
| 2026-05-10 | Manual cleanup — ndf-parse API + WARNO mod patterns |
|