|
| 1 | +# Gld Patching |
| 2 | + |
| 3 | +## Rules |
| 4 | +The rules that PolyMod uses to merge patches into the gld are: |
| 5 | +- If an array exists in both the patch and the gld, the array will be **completely replaced**, it will not be merged. This can be useful to remove items from an array. |
| 6 | +- If a value is `null` in the patch, it will be removed from the gld. |
| 7 | + |
| 8 | +## The basics |
| 9 | +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… |
| 10 | +```json |
| 11 | +{ |
| 12 | + "unitData": { |
| 13 | + "warrior": { |
| 14 | + "attack": 1000 |
| 15 | + } |
| 16 | + } |
| 17 | +} |
| 18 | +``` |
| 19 | + |
| 20 | +As you can see, this uses the exact same keys as the GLD file, but excludes everything that's unnecessary for the mod. |
| 21 | + |
| 22 | +## Adding new content |
| 23 | +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). |
| 24 | +> [!WARNING] |
| 25 | +> Manually setting `idx` to something other than `-1` breaks mod compatibility! |
| 26 | +
|
| 27 | +Additionally, make sure that all the internal names you use are in lowercase. PolyMod will crash otherwise. |
| 28 | +Here's part of an example gld patch which adds new tribe: |
| 29 | +```json |
| 30 | +{ |
| 31 | + "tribeData": { |
| 32 | + "testingtribe": { |
| 33 | + "color":15713321, |
| 34 | + "language":"az,bar,bryn,dûm,girt,hall,kar,khâz,kol,kruk,lok,rûdh,ruf,und,vorn,zak", |
| 35 | + "startingTech":[ |
| 36 | + "basic", |
| 37 | + "mining" |
| 38 | + ], |
| 39 | + "startingResource":[ |
| 40 | + "metal" |
| 41 | + ], |
| 42 | + "skins":[ |
| 43 | + "Testingskin" |
| 44 | + ], |
| 45 | + "priceTier":0, |
| 46 | + "category":2, |
| 47 | + "bonus":0, |
| 48 | + "startingUnit":"warrior", |
| 49 | + "idx":-1, |
| 50 | + "preview": [ |
| 51 | + { |
| 52 | + "x": 0, |
| 53 | + "y": 0, |
| 54 | + "terrainType": "mountain", |
| 55 | + "unitType": "swordsman", |
| 56 | + "improvementType ": "mine" |
| 57 | + } |
| 58 | + ] |
| 59 | + } |
| 60 | + } |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +## Custom Tribe Preview |
| 65 | +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. |
| 66 | +```json |
| 67 | +{ |
| 68 | + "preview": [ |
| 69 | + { |
| 70 | + "x": 0, |
| 71 | + "y": 0, |
| 72 | + "terrainType": "mountain", |
| 73 | + "unitType": "swordsman", |
| 74 | + "improvementType ": "mine" |
| 75 | + } |
| 76 | + ] |
| 77 | +} |
| 78 | +``` |
| 79 | +Each tile of preview consists of: |
| 80 | +* `x` X coordinate of the tile in the preview |
| 81 | +* `y` Y coordinate of the tile in the preview |
| 82 | +* `terrainType` terrain of the original tile will be replaced with the one you choose here |
| 83 | +* `resourceType` resource of the original tile will be replaced with the one you choose here |
| 84 | +* `unitType` unit of the original tile will be replaced with the one you choose here |
| 85 | +* `improvementType` improvement of the original tile will be replaced with the one you choose here |
| 86 | + |
| 87 | +Based on that, our chosen preview tile will have `mountain`, `swordsman` and `mine`. |
| 88 | +You can see all tiles and their coordinates in Tribe Preview by enabling PolyMod debug mode in `PolyMod.json` |
| 89 | + |
| 90 | +## Custom Skins |
| 91 | +Also, our tribe has a non-existing skin. By writing such, PolyMod will create a skin automatically: |
| 92 | +```json |
| 93 | +{ |
| 94 | + "skins": [ |
| 95 | + "Testingskin" |
| 96 | + ] |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +## Prefabs |
| 101 | +Let's look at this patch which adds new unit: |
| 102 | +```json |
| 103 | +{ |
| 104 | + "unitData": { |
| 105 | + "dashbender": { |
| 106 | + "health": 100, |
| 107 | + "defence": 10, |
| 108 | + "movement": 1, |
| 109 | + "range": 1, |
| 110 | + "attack": 0, |
| 111 | + "cost": 15, |
| 112 | + "unitAbilities": [ |
| 113 | + "dash", |
| 114 | + "convert", |
| 115 | + "stiff", |
| 116 | + "land" |
| 117 | + ], |
| 118 | + "weapon": 4, |
| 119 | + "promotionLimit": 3, |
| 120 | + "idx": -1, |
| 121 | + "prefab": "mindbender" |
| 122 | + } |
| 123 | + } |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +By default, when creating a new unit, improvement or resource PolyMod will set basic sprites for them, such as: |
| 128 | + |
| 129 | +* New **Unit** have explorer's sprites by default |
| 130 | +* New **Improvement**s have custom house's sprites by default |
| 131 | +* New **Resource**s have animal's sprites by default |
| 132 | + |
| 133 | +If you want to change it to another already existing type, you can do just what we did for `dashbender`: |
| 134 | +```json |
| 135 | +{ |
| 136 | + "prefab": "mindbender" |
| 137 | +} |
| 138 | +``` |
| 139 | +That sets `mindbender`'s sprites as our base sprites for `dashbender`. |
| 140 | + |
| 141 | +## Config |
| 142 | +Say that, in your mod, you created a new unit, but you aren't a balancing expert and thus you want the user to be able to configure how expensive it is. Before, you would need polyscript to do this. However, in polymod 1.2 there is a new feature that allows you to have configurable options in gld patches! |
| 143 | +Say that, for example, you wanted to change the warrior's cost to whatever the user wants. |
| 144 | +you can use `{{ config key defaultValue}}`. |
| 145 | +``` |
| 146 | +{ |
| 147 | + "unitData" : { |
| 148 | + "warrior" : { |
| 149 | + "cost" : {{ config "warriorCost" 5 }} |
| 150 | + } |
| 151 | + } |
| 152 | +} |
| 153 | +``` |
| 154 | +but what if you want to disable or enable a unit based on config? For that, you need to do more advanced templating. Here is an example that gives ai-mo a dashbender if dashbenders are enabled, otherwise a mindbender. In reality you will also need to modify tech etc. |
| 155 | +``` |
| 156 | +{ |
| 157 | + "unitData": { |
| 158 | + {% if config "dashbenders" true %} |
| 159 | + "dashbender": { |
| 160 | + "health": 100, |
| 161 | + "defence": 10, |
| 162 | + "movement": 1, |
| 163 | + "range": 1, |
| 164 | + "attack": 0, |
| 165 | + "cost": 15, |
| 166 | + "unitAbilities": [ |
| 167 | + "dash", |
| 168 | + "convert", |
| 169 | + "stiff", |
| 170 | + "land" |
| 171 | + ], |
| 172 | + "weapon": 4, |
| 173 | + "promotionLimit": 3, |
| 174 | + "idx": -1, |
| 175 | + "prefab": "mindbender" |
| 176 | + } |
| 177 | + } |
| 178 | + {% aimo-starting = "dashbender" %} |
| 179 | + {% else %} |
| 180 | + {% aimo-starting = "mindbender" %} |
| 181 | + {% end %} |
| 182 | + "tribeData":{ |
| 183 | + "ai-mo":{ |
| 184 | + "startingUnit": "{{ aimo-starting }}" |
| 185 | + } |
| 186 | + } |
| 187 | +} |
| 188 | +``` |
| 189 | +For a full list of templates, see [Scriban docs](https://github.com/scriban/scriban/blob/master/doc/language.md). |
0 commit comments