Metadata-Version: 2.4
Name: foxhole-hexes
Version: 1.0.2
Summary: Tool to stitch Foxhole hex maps and generate map tiles.
Author-email: Gudjon Magnusson <gudjon@notbadjon.com>
License: MIT License
        
        Copyright (c) 2026 Gudjon Magnusson
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        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 OR COPYRIGHT HOLDERS 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.
        
Project-URL: Repository, https://github.com/notbadjon/foxhole-hexes
Project-URL: Issues, https://github.com/notbadjon/foxhole-hexes/issues
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Multimedia :: Graphics
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click
Requires-Dist: pillow
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Dynamic: license-file

# Foxhole Hexes

Tool to help stitch and tile the Foxhole game map. Assemble all the individual hex maps into one master map, and then cut the map up into tiles that can be rendered on a map like [Leaflet](https://leafletjs.com/reference.html)

<img width="600" src="https://raw.githubusercontent.com/notbadjon/foxhole-hexes/refs/tags/v1.0.0/docs/master.png" />

## Install

From PyPI:

```
pip install foxhole-hexes
```

From source:

```
pip install -e .
```

## How to run

**hex2tile**

```
Usage: hex2tile [OPTIONS]

Options:
  --hexes FILE         Path to config JSON with format: {<hex_id>: { 'name':
                       <hex_name>, 'file': <hex_png>, 'q': <q>, 'p': <p> } } q
                       and r are axial hexagon coordinates (legacy key 'p' is
                       still accepted)  [required]
  --out DIRECTORY      Output directory for tiles (creates z/x/y.png).
  --max-zoom INTEGER   Max zoom level (master resolution uses ppu =
                       2^maxZoom).  [default: 5]
  --min-zoom INTEGER   Min zoom level  [default: 0]
  --tile-size INTEGER  Tile size in pixels (typically 256).  [default: 256]
  --hex-size INTEGER   Width of the hex map (corner to corner) in pixels.
                       [default: 1024]
  --write-master FILE  Optional path to write the assembled master PNG for
                       debugging.
  -v, --verbose        More logging.
  --help               Show this message and exit.
```

Example:
```
hex2tile --hexes hexes.json --out tiles --max-zoom 5 --min-zoom 2 --write-master master.png
```

Module form:

```
python -m foxhole_hexes.hex2tile --hexes hexes.json --out tiles --max-zoom 5 --min-zoom 2 --write-master master.png
```

**tga2png**

```
Usage: tga2png [OPTIONS]

  Convert TGA icons to PNG using Pillow.

Options:
  --from DIRECTORY              Source directory containing .tga files.
                                [required]
  --to DIRECTORY                Destination directory for .png files (created
                                if missing).  [required]
  --recursive / --no-recursive  Search for .tga files recursively under the
                                source directory.  [default: no-recursive]
  --overwrite / --no-overwrite  Overwrite existing .png files in the
                                destination directory.  [default: no-
                                overwrite]
  -h, --help                    Show this message and exit.
```

Example

```
tga2png --from ../warapi/Images/Maps --to png/
```

Module form:

```
python -m foxhole_hexes.tga2png --from ../warapi/Images/Maps --to png/
```

## Hexes

The map layout is configured in a json file.

```json
{
    "TempestIslandHex": { 
        "name": "Tempest Island", "file": "pngs/MapTempestIslandHex.png", "q": -2, "p": 4 
    },
    "GreatMarchHex": { 
        "name": "Great March", "file": "pngs/MapGreatMarchHex.png", "q": 2, "p": 0 
    },
    "DeadLandsHex": { 
        "name": "DeadLandsHex", "file": "pngs/MapDeadLandsHex.png", "q": 0, "p": 0 
    },
    ...
```

The position of each hex is defined by the q,p coordinates. This axial coordinate system is based on this diagram.

<img width="600" src="https://raw.githubusercontent.com/notbadjon/foxhole-hexes/refs/tags/v1.0.0/docs/hexagon-axial-coordinates.jpeg" />

Learn more about hexagon math here:
- https://math.stackexchange.com/questions/2254655/hexagon-grid-coordinate-system
- https://www.redblobgames.com/grids/hexagons/

I may have gotten some of the theory and conventions wrong in the code, but the results seem to work.
