https://github.com/mbugert/anno1602-script-parser
Grammar and Parser Generator for Anno 1602 Scripts
https://github.com/mbugert/anno1602-script-parser
1602-ad anno anno-1602 anno1602 mdcii-engine
Last synced: 23 days ago
JSON representation
Grammar and Parser Generator for Anno 1602 Scripts
- Host: GitHub
- URL: https://github.com/mbugert/anno1602-script-parser
- Owner: mbugert
- License: mit
- Created: 2023-07-07T08:49:18.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-07T11:19:44.000Z (about 2 years ago)
- Last Synced: 2025-02-28T11:02:25.111Z (7 months ago)
- Topics: 1602-ad, anno, anno-1602, anno1602, mdcii-engine
- Language: Python
- Homepage:
- Size: 11.7 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Grammar and Parser Generator for Anno 1602 Scripts
This repo contains:
* a [grammar](parser/io/script/grammar.lark) that accepts all COD and GAD files in Anno 1602 KE (Königs-Edition)
* a feature-complete [interpreter](parser/io/script/interpreter.py) for `HAEUSER.COD`, `FIGUREN.COD` that spits out plain python objectsParser generation uses the [lark parsing toolkit](https://github.com/lark-parser/lark).
The resulting parser is LALR, despite the chaotic script language. Parsing is still relatively slow (4 seconds for all of the game's files, see below), but at least the code is maintainable.For more details on the script language format, see https://github.com/Green-Sky/anno16_docs/blob/master/file_formats/script.md
## Usage
Needs python>=3.9.
```bash
git clone https://github.com/mbugert/anno1602-script-parser
cd anno1602-script-parser
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt# in line 7, enter the root directory of your 1602 KE install
nano parser/test/base.py# interpret all HAEUSER.COD, FIGUREN.COD, parse all GAD/INC files
python -m unittest discover parser/test
```Sample output:
```commandline
❯ python -m unittest discover parser/testfiguren.cod:
{'FIGUR': {0: {'Gfx': 0,
'Id': 0,
'Kind': ,
'Speedtyp': 0,
'Stirbtime': 2.5},
: {'ANIM': {0: {'AnimAdd': 1,
'AnimAnz': 8,
'AnimOffs': 0,
'AnimSpeed': 80,
'Kind': : {'BGruppe': 1,
'Minwohn': 100},
: {'BGruppe': 1,
'Minwohn': 50},
: {'BGruppe': 2,
'Minwohn': 150},
: {'BGruppe': 2,
...
..
----------------------------------------------------------------------
Ran 3 tests in 4.064sOK
```
## Todos for the future
- [ ] implement `include_ref` in [interpreter.py](parser/io/script/interpreter.py) to support interpreting most GAD files
- [ ] implement `property_index_ref` in [interpreter.py](parser/io/script/interpreter.py) to support `CTRL.GAD`## License
MIT license