Skip to content

3. GLD patching

jkdev edited this page Feb 2, 2025 · 1 revision

Making the mod

The first thing you probably immediately noticed is that we now start from a blank file instead of an existing GLD. PolyMod mods don't include the entire GLD file, but only the parts that are changed by the mod. This is to ensure multiple mods can be loaded at the same time - all of their files are added onto the base GLD when you launch the game. You'll probably still want to have the vanilla GLD open as a reference.

Every patch is merged into GLD using:

  • MergeArrayHandling.Replace this means that if an array exists in both gld (the target) and patch (the source), the array from patch will completely replace the array in gld, rather than merging or appending items

  • MergeNullValueHandling.Merge this means that if patch contains null values for any properties, those null values will be applied to gld, potentially overriding existing values with null

The basics

The patch.json file is essentially a mini GLD that includes only the values you want to change and nothing else. If you want to make a mod that just changes a warrior's attack, for example…

{
  "unitData": {
    "warrior": {
      "attack": 1000
    }
  }
}

As you can see, this uses the exact same keys as the GLD file, but excludes everything that's unnecessary for the mod.

Adding new content

Well, adding new content is as simple as editing existing content! You just have to pretend that something exists, and then it will exist: you need to set its idx to -1 for it to work. This will make PolyMod automatically assign an idx when the game starts (autoindex).

Warning

Manually setting idx to something other than -1 breaks mod compatibility!

Additionally, make sure that all the internal names you use are in lowercase. PolyMod will crash otherwise. Here's part of an example gld patch which adds new tribe:

{
  "tribeData": {
    "testingtribe": {
      "color":15713321,
      "language":"az,bar,bryn,dûm,girt,hall,kar,khâz,kol,kruk,lok,rûdh,ruf,und,vorn,zak",
      "startingTech":[
        "basic",
        "mining"
      ],
      "startingResource":[
        "metal"
      ],
      "skins":[
        "Testingskin"
      ],
      "priceTier":0,
      "category":2,
      "bonus":0,
      "startingUnit":"warrior",
      "idx":-1,
      "preview": [
        {
          "x": 0,
          "y": 0,
          "terrainType": "mountain",
          "unitType": "swordsman",
          "improvementType ": "mine"
        }
      ]
    }
  }
}

Custom Tribe Preview

As you could have noticed, our testingtribe has a field preview which does not exist in GLD. This field was added in order to modify tribe previews if needed.

"preview": [
  {
    "x": 0,
    "y": 0,
    "terrainType": "mountain",
    "unitType": "swordsman",
    "improvementType ": "mine"
  }
]

Each tile of preview consists of:

  • x X coordinate of the tile in the preview
  • y Y coordinate of the tile in the preview
  • terrainType terrain of the original tile will be replaced with the one you choose here
  • resourceType resource of the original tile will be replaced with the one you choose here
  • unitType unit of the original tile will be replaced with the one you choose here
  • improvementType improvement of the original tile will be replaced with the one you choose here

Based on that, our chosen preview tile will have mountain, swordsman and mine. You can see all tiles and their coordinates in Tribe Preview by enabling PolyMod debug mode in PolyMod.json

Custom Skins

Also, our tribe has a non-existing skin. By writing such, PolyMod will create a skin automatically:

"skins": [
  "Testingskin"
],

Prefabs

Let's look at this patch which adds new unit:

{
  "unitData": {
    "dashbender": {
      "health": 100,
      "defence": 10,
      "movement": 1,
      "range": 1,
      "attack": 0,
      "cost": 15,
      "unitAbilities": [
      "dash",
      "convert",
      "stiff",
      "land"
      ],
      "weapon": 4,
      "promotionLimit": 3,
      "idx": -1,
      "prefab": "mindbender"
    }
  }
}

By default, when creating a new unit, improvement or resource PolyMod will set basic sprites for them, such as:

  • New Unit have explorer's sprites by default
  • New Improvements have custom house's sprites by default
  • New Resources have animal's sprites by default

If you want to change it to another already existing type, you can do just what we did for dashbender:

"prefab": "mindbender"

That sets mindbender's sprites as our base sprites for dashbender.

Clone this wiki locally