Metadata-Version: 2.3
Name: wow-pytoc
Version: 0.8.0
Summary: A package for reading and writing World of Warcraft addon TOC files.
Author: Ghostopheles
Author-email: Ghostopheles <ghost@ghst.tools>
License: This is free and unencumbered software released into the public domain.
         
         Anyone is free to copy, modify, publish, use, compile, sell, or
         distribute this software, either in source code form or as a compiled
         binary, for any purpose, commercial or non-commercial, and by any
         means.
         
         In jurisdictions that recognize copyright laws, the author or authors
         of this software dedicate any and all copyright interest in the
         software to the public domain. We make this dedication for the benefit
         of the public at large and to the detriment of our heirs and
         successors. We intend this dedication to be an overt act of
         relinquishment in perpetuity of all present and future rights to this
         software under copyright law.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
         IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
         OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
         ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
         OTHER DEALINGS IN THE SOFTWARE.
         
         For more information, please refer to <https://unlicense.org>
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.12
Project-URL: Homepage, https://github.com/Ghostopheles/pytoc
Project-URL: Repository, https://github.com/Ghostopheles/pytoc.git
Project-URL: Issues, https://github.com/Ghostopheles/pytoc/issues
Project-URL: Changelog, https://github.com/Ghostopheles/pytoc/blob/master/CHANGELOG.md
Description-Content-Type: text/markdown

![Tests](https://github.com/Ghostopheles/pytoc/actions/workflows/tests.yml/badge.svg)

# pytoc

A Python package for reading and writing World of Warcraft addon [TOC](https://warcraft.wiki.gg/wiki/TOC_format) files.

## Installation

```
pip install wow-pytoc 
```

## Usage

### Reading a TOC file

```py
from pytoc import TOCFile, TOCTextLocale

toc = TOCFile("path/to/MyAddon.toc")

print(toc.Interface)          # TOCListValue[int] of all interface versions
print(toc.Title)              # base (enUS) value
print(toc.Title.get_translation(TOCTextLocale.frFR))
print(toc.ExtendedDirectives.get("X-Website"))
print(toc.UnknownDirectives.get("SomeUnknownField"))

for dep in toc.Dependencies:
    print(f"Required: {dep}")
for dep in toc.OptionalDeps:
    print(f"Optional: {dep}")

for file_line in toc.Files:
    entry = file_line.FileEntry
    print(entry.export())
```

### Writing a TOC file

```py
from pytoc import TOCFile, TOCLocalizedDirectiveValue, TOCListValue, TOCTextLocale

toc = TOCFile()
toc.Interface = TOCListValue("110000", [110000])
toc.Author = TOCLocalizedDirectiveValue("Ghost")
toc.Title = TOCLocalizedDirectiveValue(
    "MyAddon",
    {TOCTextLocale.frFR: "MonAddon", TOCTextLocale.deDE: "MeinAddon"},
)

toc.add_file("MyAddon.lua")
toc.add_file("MyAddon.xml")
toc.add_dependency("totalRP3", required=False)

toc.export("path/to/MyAddon.toc", overwrite=True)
```

### Round-trip

Reading and exporting an existing file produces byte-identical output.

```py
toc = TOCFile("MyAddon.toc")
toc.Author = TOCLocalizedDirectiveValue("NewAuthor")
toc.export("MyAddon.toc", overwrite=True)
# Every line unchanged except ## Author:
```

### Load condition simulation

`TOCEvaluationContext` lets you simulate whether an addon (or a specific file entry) would load under given game conditions.

```py
from pytoc import (
    TOCFile, TOCEvaluationContext, TOCAllowLoadGameType,
    TOCGameType, TOCEnvironment, TOCTextLocale,
)

ctx = TOCEvaluationContext(TOCGameType.Mainline, TOCEnvironment.Global, TOCTextLocale.enUS)

toc = TOCFile("MyAddon.toc")
can_load, err = toc.can_load_addon(ctx)

# Per-file entry
for file_line in toc.Files:
    if file_line.FileEntry.should_load(ctx):
        print(file_line.FileEntry.resolve_path(ctx))
```

## Notes/Quirks

> [!NOTE]
> - `Dependencies` and `OptionalDeps` are `TOCListValue[str]`; use `add_dependency(name, required=True/False)` to append safely.
> - `X-` prefixed fields are available via `toc.ExtendedDirectives` (a `dict[str, str]`).
> - Unrecognised directives (non-`X-`, not in the known list) land in `toc.UnknownDirectives` and are **not** exported.
> - Multiple occurrences of the same directive are merged - last value wins for scalars, values are combined for list fields.
> - Comments and blank lines are preserved on round-trip.
