Skip to content

Use this script to extract building sizes #1

Description

@gynt

Use this script to extra building sizes: https://github.com/kolunmi/gtk-crusader-village

import json5
import json
import pathlib



def get_variant_file_data():
    itemsdir = pathlib.Path("src/items")
    
    variantfiles = itemsdir.glob("*.variant")
    
    for f in variantfiles:
        try:
            d = json5.loads(f.read_text().replace("<", "").replace(">", ""))
        except Exception as e:
            print(f.read_text())
            raise e
        yield d


def export_simplified(datas, path = "metadata.json"):
    buildings = []
    units = []
    for d in datas:
        if d['kind'] == 'building':
            buildings.append({
                "id": d['id'],
                "name": d['name'],
                "kind": d['kind'],
                "size": d["tile-width"] if "tile-width" in d else 0
            })
        if d['kind'] == 'unit':
            units.append({
                "id": d['id'],
                "name": d['name'],
                "kind": d['kind']
            })
    buildings = sorted(buildings, key=lambda x: x['id'])
    units = sorted(units, key=lambda x: x['id'])
    pathlib.Path(path).write_text(json.dumps({"buildings": buildings, "units": units}, indent=2))

export_simplified(get_variant_file_data())

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions