Metadata-Version: 2.4
Name: entity_data_format
Version: 1.0.0
Summary: Entity Data Format (EDF) parser and serializer
Author-email: Josef Vanzura <gindar@zamraky.cz>
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# EDF Parser

Entity Data Format (EDF) parser and serializer.

## Installation

```bash
pip install entity_data_format
```

## Usage

### Loading

#### Load from file
```python
import entity_data_format as edf

with open('path/to/file.edf', 'r', encoding='utf-8') as fp:
    data = edf.load(fp)
```

#### Load from string
```python
import entity_data_format as edf

data_str = '''
[entity = player]
speed = 10.0
inventory = sword shield
'''
data = edf.loads(data_str)

# Incremental loading into existing dictionary
extra_str = '[entity = enemy]\nspeed = 5'
edf.loads(extra_str, data=data)
```

#### Load all entities (merging)
```python
import entity_data_format as edf

# Recursively load all .edf files and merge them
# Files are processed in alphabetical order
data = edf.load_all_entities('assets/**/*.edf')
```

### Serialization

#### Dump to file
```python
import entity_data_format as edf

data = {
    'car': {
        'car1': {'speed': 100, 'acceleration': 1.0}
    }
}

with open('output.edf', 'w', encoding='utf-8') as fp:
    edf.dump(data, fp)
```

#### Dump to string
```python
import entity_data_format as edf

data = {
    'weapon': {
        'sword': {'damage': 15, 'weight': 2.5}
    }
}
s = edf.dumps(data)
```

## Data Types

EDF is primarily string-based, but `serialize_value` handles several Python types:

- **bool**: `True` -> `1`, `False` -> `0`
- **float**: Formatted using `%f`
- **list / tuple**: Space-separated values. Spaces within elements are replaced by `_`.
- **other**: Converted to `str()`

**Note**: All values are returned as strings when loading.

## Modding support (merging entities)

`cars.edf`:
```ini
[car = car1]
speed = 100
acceleration = 1.0

[car = car2]
speed = 80
acceleration = 1.2
```

`cars_mod.edf`:
```ini
[car = car1]
speed = 120
```

```python
import entity_data_format as edf

# Files are loaded in alphabetical order, so cars_mod.edf will overwrite values from cars.edf
data = edf.load_all_entities('*.edf')

# data['car']['car1']['speed'] == '120'
# data['car']['car1']['acceleration'] == '1.0'
```
