Skip to content

extract_game_data

Rebuild the bundled game-data YAML resources from a Terra Invicta templates directory.

tiargus.commands.extract_game_data

Maintenance tool: extract bundled game data from Terra Invicta templates.

Several report inputs are derived from Terra Invicta's static template JSON (shipped in …/TerraInvicta_Data/StreamingAssets/Templates/) and bundled as YAML package resources under tiargus/data/. This command parses a templates directory and (re)writes every bundled resource:

  • space_body_locations.yaml{templateName: locationLabel} from TISpaceBodyTemplate.json.
  • org_missions.yaml{orgTemplateName: [missions]} from TIOrgTemplate.json.
  • org_research_bonuses.yaml{orgTemplateName: {category: bonus}} from TIOrgTemplate.json.
  • councilor_missions.yaml — the per-source mission grants needed to derive a councilor's available missions (base/profession/trait_granted/ trait_restricted), from TIMissionTemplate.json, TICouncilorTypeTemplate.json, and TITraitTemplate.json.

Re-run this whenever the game is updated so new bodies, orgs, traits, or missions are reflected.

Example:

tiargus extract-game-data "/path/to/StreamingAssets/Templates"

add_parser(subparsers)

Register the extract-game-data subcommand on subparsers.

Source code in src/tiargus/commands/extract_game_data.py
190
191
192
193
194
195
196
197
198
199
@register
def add_parser(subparsers) -> None:
    """Register the ``extract-game-data`` subcommand on *subparsers*."""
    p = subparsers.add_parser(
        "extract-game-data",
        help="Rebuild bundled game-data YAML resources from a game templates directory.",
        description="Extract bundled game data from Terra Invicta template JSON files.",
    )
    _add_arguments(p)
    p.set_defaults(func=_run)

extract_councilor_missions(missions, professions, traits)

Build the per-source mission grants used to derive councilor missions.

Parameters:

Name Type Description Default
missions list[dict]

Parsed contents of TIMissionTemplate.json.

required
professions list[dict]

Parsed contents of TICouncilorTypeTemplate.json.

required
traits list[dict]

Parsed contents of TITraitTemplate.json.

required

Returns:

Type Description
dict[str, object]

A dict with keys base (missions every councilor can perform),

dict[str, object]

profession ({typeTemplateName: [missions]}), trait_granted

dict[str, object]

and trait_restricted ({traitName: [missions]}).

Source code in src/tiargus/commands/extract_game_data.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
def extract_councilor_missions(
    missions: list[dict],
    professions: list[dict],
    traits: list[dict],
) -> dict[str, object]:
    """Build the per-source mission grants used to derive councilor missions.

    Args:
        missions: Parsed contents of ``TIMissionTemplate.json``.
        professions: Parsed contents of ``TICouncilorTypeTemplate.json``.
        traits: Parsed contents of ``TITraitTemplate.json``.

    Returns:
        A dict with keys ``base`` (missions every councilor can perform),
        ``profession`` (``{typeTemplateName: [missions]}``), ``trait_granted``
        and ``trait_restricted`` (``{traitName: [missions]}``).
    """
    return {
        "base": sorted(m["dataName"] for m in missions if m.get("baseMission")),
        "profession": {
            p["dataName"]: list(p["missionNames"])
            for p in professions
            if p.get("missionNames")
        },
        "trait_granted": {
            t["dataName"]: list(t["missionsGrantedNames"])
            for t in traits
            if t.get("missionsGrantedNames")
        },
        "trait_restricted": {
            t["dataName"]: list(t["restrictedMissionNames"])
            for t in traits
            if t.get("restrictedMissionNames")
        },
    }

extract_locations(templates)

Map each space body's dataName to a human-readable region label.

Reads each entry's effectToExplore field (e.g. "Effect_ExploreAsteroids") and converts it to a region label (e.g. "Asteroids"). Entries without an effectToExplore field are skipped.

Parameters:

Name Type Description Default
templates list[dict]

Parsed contents of TISpaceBodyTemplate.json.

required

Returns:

Type Description
dict[str, str]

A dict mapping dataName to region label.

Source code in src/tiargus/commands/extract_game_data.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def extract_locations(templates: list[dict]) -> dict[str, str]:
    """Map each space body's ``dataName`` to a human-readable region label.

    Reads each entry's ``effectToExplore`` field (e.g.
    ``"Effect_ExploreAsteroids"``) and converts it to a region label (e.g.
    ``"Asteroids"``).  Entries without an ``effectToExplore`` field are skipped.

    Args:
        templates: Parsed contents of ``TISpaceBodyTemplate.json``.

    Returns:
        A dict mapping ``dataName`` to region label.
    """
    return {
        t["dataName"]: _effect_to_location(t["effectToExplore"])
        for t in templates
        if t.get("effectToExplore")
    }

extract_org_missions(templates)

Map each org template to the missions it grants.

Parameters:

Name Type Description Default
templates list[dict]

Parsed contents of TIOrgTemplate.json.

required

Returns:

Type Description
dict[str, list[str]]

A dict mapping dataName to its missionsGrantedNames list,

dict[str, list[str]]

omitting orgs that grant no missions.

Source code in src/tiargus/commands/extract_game_data.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def extract_org_missions(templates: list[dict]) -> dict[str, list[str]]:
    """Map each org template to the missions it grants.

    Args:
        templates: Parsed contents of ``TIOrgTemplate.json``.

    Returns:
        A dict mapping ``dataName`` to its ``missionsGrantedNames`` list,
        omitting orgs that grant no missions.
    """
    return {
        t["dataName"]: list(t["missionsGrantedNames"])
        for t in templates
        if t.get("missionsGrantedNames")
    }

extract_org_research_bonuses(templates)

Map each org template to its per-category research bonuses.

Parameters:

Name Type Description Default
templates list[dict]

Parsed contents of TIOrgTemplate.json.

required

Returns:

Type Description
dict[str, dict[str, float]]

A dict mapping dataName to {category: bonus} built from the

dict[str, dict[str, float]]

org's techBonuses list, omitting orgs whose techBonuses is

dict[str, dict[str, float]]

empty or absent.

Source code in src/tiargus/commands/extract_game_data.py
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
def extract_org_research_bonuses(
    templates: list[dict],
) -> dict[str, dict[str, float]]:
    """Map each org template to its per-category research bonuses.

    Args:
        templates: Parsed contents of ``TIOrgTemplate.json``.

    Returns:
        A dict mapping ``dataName`` to ``{category: bonus}`` built from the
        org's ``techBonuses`` list, omitting orgs whose ``techBonuses`` is
        empty or absent.
    """
    return {
        t["dataName"]: {b["category"]: float(b["bonus"]) for b in t["techBonuses"]}
        for t in templates
        if t.get("techBonuses")
    }