Package: d2animdata
d2animdatad2animdata is a command-line program for editingAnimData.D2. AnimData.D2 is a propriety file format used byDiablo 2to store animation metadata for characters and monsters.d2animdata candecompileAnimData.D2 to text-based file formats, such astabbed textandJSON(seeSupported File Formatsfor more info). Modders can edit these files to add new animations or modify existing ones. After editing, d2animdata cancompileit back to a new AnimData.D2 file.d2animdata is written in Python. It supports Python 3.6 and above, and has been tested on Windows 10 and Ubuntu Linux.⚠ This project is very much in Alpha. There may be several bugs. Always back up your AnimData.D2 file before using d2animdata.InstallingTo use d2animdata, you must installPython 3. Then, open a command-line shell (e.g.cmd.exe) and enter:pip install d2animdataThis will install d2animdata on your computer.CommandsTo view help for a command, enter:d2animdata <command> --helpdecompileDecompiles an AnimData.D2 file to tabbed text or JSON file.$d2animdatadecompile--helpusage: d2animdata decompile [-h] [--dedupe] [--sort] (--json | --txt)animdata_d2 targetpositional arguments:animdata_d2  AnimData.D2 file to decompiletarget       JSON or tabbed text file to save tooptional arguments:-h, --help   show this help message and exit--dedupe     Remove records with duplicate COF names--sort       Sort the records alphabetically before saving--json       Decompile to JSON--txt        Decompile to tabbed text (TXT)Example: Decompilepath/to/AnimData.D2to a JSON file.d2animdata decompile --json path/to/AnimData.D2 path/to/my-animdata.jsonExample: Decompilepath/to/AnimData.D2to a tabbed text file.d2animdata decompile --txt path/to/AnimData.D2 path/to/my-animdata.txtcompileCompiles a tabbed text or JSON file to AnimData.D2 file.$d2animdatacompile--helpusage: d2animdata compile [-h] [--dedupe] [--sort] (--json | --txt)source animdata_d2positional arguments:source       JSON or tabbed text file to compileanimdata_d2  AnimData.D2 file to save tooptional arguments:-h, --help   show this help message and exit--dedupe     Remove records with duplicate COF names--sort       Sort the records alphabetically before saving--json       Compile JSON--txt        Compile tabbed text (TXT)Example: Compile a JSON file topath/to/AnimData-result.D2.d2animdata compile --json path/to/my-animdata.json path/to/AnimData-result.D2Example: Compile a tabbed text file topath/to/AnimData-result.D2.d2animdata compile --txt path/to/my-animdata.txt path/to/AnimData-result.D2Supported File Formatsd2animdata supports two file formats:tabbed text(.txt) and JSON (.json).Tabbed textTabbed text files (.txt) can be edited with a spreadsheet program (e.g. Excel, AFJ Sheet Edit). Diablo 2 modders should already be familiar with these files, as Diablo 2 uses tabbed text files extensively to control various aspects of the game.d2animdata is compatible with Paul Siramy's excellentanimdata_editprogram, which is another popular tool for (de)compiling AnimData.D2 to tabbed text.JSONJSON files (.json) can be edited with any text editor (e.g. Notepad), though I recommend using one with syntax highlighting support (e.g. Notepad++, Visual Studio Code).JSON has several advantages over tabbed text:JSON files can be added to aversion control system(VCS), such as Git. This allows you to keep track of changes made to a file. You can compare changes across time and revert unwanted changes.Tabbed text files and AnimData.D2 can also be added to a VCS. However, tabbed text files are tricky to deal with, because they don't produce nice-looking diff logs when compared. Binary files, such as AnimData.D2, cannot be compared at all. On the other hand, JSON files create diff logs that are easy to read.JSON files are easier to handle in several programming languages.Unlike tabbed text, JSON does not suffer from tricky whitespace issues.API Usaged2animdata can also be imported from a Python script to load, edit, and save AnimData.D2.Example:fromd2animdataimportload,dump# Load an AnimData.D2 filewithopen('AnimData.D2',mode='rb')asanimdata_file:animdata=load(animdata_file)# animdata now contains a list of Record objects.# Iterate through each record, printing its informationforrecordinanimdata:print('COF name:',record.cof_name)print('Frames per direction:',record.frames_per_direction)print('Animation speed:',record.animation_speed)print('Trigger frames:',record.triggers)# Let's find a record named '0DNUHTH' and edit itforrecordinanimdata:ifrecord.cof_name=='0DNUHTH':record.animation_speed=192# Erase all trigger frames previously set on this record.record.triggers.clear()# Set the trigger code of frame #10 to 1# Since frame indices begin at 0, we're actually modifying the 11th frame.record.triggers[10]=1break# Save the records to AnimData.D2withopen('AnimData.D2',mode='wb')asanimdata_file:dump(animdata,animdata_file)See theAPI docsfor a complete reference of available functions and classes.DevelopmentTo develop d2animdata, you will want a good Python editor. I recommendVisual Studio Codewith theMicrosoft Python extension.To develop d2animdata, clone this repository and create avirtual environment. Then run the following commands to install the project locally for development:# For Windowspython-mpipinstall-rrequirements-dev.txt
flitinstall--pth-file# For non-Windowspipinstall-rrequirements-dev.txt
flitinstalld2animdata uses:Flitto build source distributions and wheels.Toxto run tests.Blackandisortto format code.Pylintto check code.pydoc-markdown3 to generate API documentation from source code.Runpydoc-markdown -p d2animdata > api.mdto generateapi.md.