summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/wwwroot/schemas/content-patcher.json
blob: 61a633cb9ae62cd8aaa034fe03ff01b939557e83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "https://smapi.io/schemas/content-patcher.json",
    "title": "Content Patcher content pack",
    "description": "Content Patcher content file for mods",
    "@documentationUrl": "https://github.com/Pathoschild/StardewMods/tree/develop/ContentPatcher#readme",
    "type": "object",

    "properties": {
        "Format": {
            "title": "Format version",
            "description": "The format version. You should always use the latest version to enable the latest features and avoid obsolete behavior.",
            "type": "string",
            "const": "1.9",
            "@errorMessages": {
                "const": "Incorrect value '@value'. This should be set to the latest format version, currently '1.9'."
            }
        },
        "ConfigSchema": {
            "title": "Config schema",
            "description": "Defines the config.json format, to support more complex mods.",
            "type": "object",
            "additionalProperties": {
                "type": "object",
                "properties": {
                    "AllowValues": {
                        "title": "Allowed values",
                        "description": "The values the player can provide, as a comma-delimited string. If omitted, any value is allowed.\nTip: for a boolean flag, use \"true, false\".",
                        "type": "string"
                    },
                    "AllowBlank": {
                        "title": "Allow blank",
                        "description": "Whether the field can be left blank. If false or omitted, blank fields will be replaced with the default value.",
                        "type": "boolean"
                    },
                    "AllowMultiple": {
                        "title": "Allow multiple values",
                        "description": "Whether the player can specify multiple comma-delimited values. Default false.",
                        "type": "boolean"
                    },
                    "Default": {
                        "title": "Default value",
                        "description": "The default values when the field is missing. Can contain multiple comma-delimited values if AllowMultiple is true. If omitted, blank fields are left blank.",
                        "type": "string"
                    },

                    "additionalProperties": false
                },
                "allOf": [
                    {
                        "if": {
                            "properties": {
                                "AllowBlank": { "const": false }
                            },
                            "required": [ "AllowBlank" ]
                        },
                        "then": {
                            "required": [ "Default" ]
                        }
                    }
                ],

                "@errorMessages": {
                    "allOf": "If 'AllowBlank' is false, the 'Default' field is required."
                }
            }
        },
        "DynamicTokens": {
            "title": "Dynamic tokens",
            "description": "Custom tokens that you can use.",
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "Name": {
                        "title": "Name",
                        "description": "The name of the token to use for tokens & conditions.",
                        "type": "string"
                    },
                    "Value": {
                        "title": "Token value",
                        "description": "The value(s) to set. This can be a comma-delimited value to give it multiple values. If any block for a token name has multiple values, it will only be usable in conditions. This field supports tokens, including dynamic tokens defined before this entry.",
                        "type": "string"
                    },
                    "When": {
                        "title": "When",
                        "description": "Only set the value if the given conditions match. If not specified, always matches.",
                        "$ref": "#/definitions/Condition"
                    }
                },

                "required": [ "Name", "Value" ],
                "additionalProperties": false
            }
        },
        "Changes": {
            "title": "Changes",
            "description": "The changes you want to make. Each entry is called a patch, and describes a specific action to perform: replace this file, copy this image into the file, etc. You can list any number of patches.",
            "type": "array",
            "items": {
                "properties": {
                    "Action": {
                        "title": "Action",
                        "description": "The kind of change to make.",
                        "type": "string",
                        "enum": [ "Load", "EditImage", "EditData", "EditMap" ]
                    },
                    "Target": {
                        "title": "Target asset",
                        "description": "The game asset you want to patch (or multiple comma-delimited assets). This is the file path inside your game's Content folder, without the file extension or language (like Animals/Dinosaur to edit Content/Animals/Dinosaur.xnb). This field supports tokens and capitalization doesn't matter. Your changes are applied in all languages unless you specify a language condition.",
                        "type": "string",
                        "not": {
                            "pattern": "^ *[cC][oO][nN][tT][eE][nN][tT]/|\\.[xX][nN][bB] *$|\\.[a-zA-Z][a-zA-Z]-[a-zA-Z][a-zA-Z](?:.xnb)? *$"
                        },
                        "@errorMessages": {
                            "not": "Invalid target; it shouldn't include the 'Content/' folder, '.xnb' extension, or locale code."
                        }
                    },
                    "LogName": {
                        "title": "Patch log name",
                        "description": "A name for this patch shown in log messages. This is very useful for understanding errors; if not specified, will default to a name like 'entry #14 (EditImage Animals/Dinosaurs)'.",
                        "type": "string"
                    },
                    "Enabled": {
                        "title": "Enabled",
                        "description": "Whether to apply this patch. Default true. This fields supports immutable tokens (e.g. config tokens) if they return true/false.",
                        "anyOf": [
                            {
                                "type": "string",
                                "enum": [ "true", "false" ]
                            },
                            {
                                "type": "string",
                                "pattern": "\\{\\{[^{}]+\\}\\}"
                            },
                            {
                                "type": "boolean"
                            }
                        ],
                        "@errorMessages": {
                            "anyOf": "Invalid value; must be true, false, or a single token which evaluates to true or false."
                        }
                    },
                    "FromFile": {
                        "title": "Source file",
                        "description": "The relative file path in your content pack folder to load instead (like 'assets/dinosaur.png'). This can be a .json (data), .png (image), .tbin (map), or .xnb file. This field supports tokens and capitalization doesn't matter.",
                        "type": "string",
                        "allOf": [
                            {
                                "not": {
                                    "pattern": "\b\\.\\.[/\\]"
                                }
                            },
                            {
                                "pattern": "\\.(json|png|tbin|xnb) *$"
                            }
                        ],
                        "@errorMessages": {
                            "allOf:indexes: 0": "Invalid value; must not contain directory climbing (like '../').",
                            "allOf:indexes: 1": "Invalid value; must be a file path ending with .json, .png, .tbin, or .xnb."
                        }
                    },
                    "FromArea": {
                        "title": "Source area",
                        "description": "The part of the source image to copy. Defaults to the whole source image.",
                        "$ref": "#/definitions/Rectangle"
                    },
                    "ToArea": {
                        "title": "Destination area",
                        "description": "The part of the target image to replace. Defaults to the FromArea size starting from the top-left corner.",
                        "$ref": "#/definitions/Rectangle"
                    },
                    "PatchMode": {
                        "title": "Patch mode",
                        "description": "How to apply FromArea to ToArea. Defaults to Replace.",
                        "type": "string",
                        "enum": [ "Replace", "Overlay" ],
                        "default": "Replace"
                    },
                    "Fields": {
                        "title": "Fields",
                        "description": "The individual fields you want to change for existing entries. This field supports tokens in field keys and values. The key for each field is the field index (starting at zero) for a slash-delimited string, or the field name for an object.",
                        "type": "object",
                        "additionalProperties": {
                            "type": "object"
                        }
                    },
                    "Entries": {
                        "title": "Entries",
                        "description": "The entries in the data file you want to add, replace, or delete. If you only want to change a few fields, use Fields instead for best compatibility with other mods. To add an entry, just specify a key that doesn't exist; to delete an entry, set the value to null (like \"some key\": null). This field supports tokens in entry keys and values.\nCaution: some XNB files have extra fields at the end for translations; when adding or replacing an entry for all locales, make sure you include the extra fields to avoid errors for non-English players.",
                        "type": "object",
                        "additionalProperties": {
                            "type": [ "object", "string" ]
                        }
                    },
                    "MoveEntries": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "ID": {
                                    "title": "ID",
                                    "description": "The ID of the entry to move",
                                    "type": "string"
                                },
                                "BeforeID": {
                                    "title": "Before ID",
                                    "description": "Move entry so it's right before this ID",
                                    "type": "string"
                                },
                                "AfterID": {
                                    "title": "After ID",
                                    "description": "Move entry so it's right after this ID",
                                    "type": "string"
                                },
                                "ToPosition": {
                                    "title": "To position",
                                    "description": "Move entry so it's right at this position",
                                    "enum": [ "Top", "Bottom" ]
                                }
                            },

                            "anyOf": [
                                {
                                    "required": [ "BeforeID" ]
                                },
                                {
                                    "required": [ "AfterID" ]
                                },
                                {
                                    "required": [ "ToPosition" ]
                                }
                            ],

                            "dependencies": {
                                "BeforeID": {
                                    "propertyNames": {
                                        "enum": [ "ID", "BeforeID" ]
                                    }
                                },
                                "AfterID": {
                                    "propertyNames": {
                                        "enum": [ "ID", "AfterID" ]
                                    }
                                },
                                "ToPosition": {
                                    "propertyNames": {
                                        "enum": [ "ID", "ToPosition" ]
                                    }
                                }
                            },

                            "required": [ "ID" ],
                            "@errorMessages": {
                                "anyOf": "You must specify one of 'AfterID', 'BeforeID', or 'ToPosition'.",
                                "dependencies:BeforeID": "If 'BeforeID' is specified, only 'ID' and 'BeforeID' fields are valid.",
                                "dependencies:AfterID": "If 'AfterID' is specified, only 'ID' and 'AfterID' fields are valid.",
                                "dependencies:ToPosition": "If 'ToPosition' is specified, only 'ID' and 'ToPosition' fields are valid."
                            }
                        }
                    },
                    "When": {
                        "title": "When",
                        "description": "Only apply the patch if the given conditions match.",
                        "$ref": "#/definitions/Condition"
                    }
                },
                "allOf": [
                    {
                        "if": {
                            "properties": {
                                "Action": { "const": "Load" }
                            }
                        },
                        "then": {
                            "required": [ "FromFile" ],
                            "propertyNames": {
                                "enum": [ "Action", "Target", "LogName", "Enabled", "When", "FromFile" ]
                            }
                        }
                    },
                    {
                        "if": {
                            "properties": {
                                "Action": { "const": "EditImage" }
                            }
                        },
                        "then": {
                            "required": [ "FromFile" ],
                            "propertyNames": {
                                "enum": [ "Action", "Target", "LogName", "Enabled", "When", "FromFile", "FromArea", "ToArea", "PatchMode" ]
                            }
                        }
                    },
                    {
                        "if": {
                            "properties": {
                                "Action": { "const": "EditData" }
                            }
                        },
                        "then": {
                            "propertyNames": {
                                "enum": [ "Action", "Target", "LogName", "Enabled", "When", "Fields", "Entries", "MoveEntries" ]
                            }
                        }
                    },
                    {
                        "if": {
                            "properties": {
                                "Action": { "const": "EditMap" }
                            }
                        },
                        "then": {
                            "properties": {
                                "FromFile": {
                                    "description": "The relative path to the map in your content pack folder from which to copy (like assets/town.tbin). This can be a .tbin or .xnb file. This field supports tokens and capitalization doesn't matter.\nContent Patcher will handle tilesheets referenced by the FromFile map for you if it's a .tbin file:\n - If a tilesheet isn't referenced by the target map, Content Patcher will add it for you (with a z_ ID prefix to avoid conflicts with hardcoded game logic). If the source map has a custom version of a tilesheet that's already referenced, it'll be added as a separate tilesheet only used by your tiles.\n - If you include the tilesheet file in your mod folder, Content Patcher will use that one automatically; otherwise it will be loaded from the game's Content/Maps folder."
                                },
                                "FromArea": {
                                    "description": "The part of the source map to copy. Defaults to the whole source map."
                                },
                                "ToArea": {
                                    "description": "The part of the target map to replace."
                                }
                            },
                            "propertyNames": {
                                "enum": [ "Action", "Target", "LogName", "Enabled", "When", "FromFile", "FromArea", "ToArea" ]
                            },
                            "required": [ "FromFile", "ToArea" ]
                        }
                    }
                ],

                "required": [ "Action", "Target" ],
                "@errorMessages": {
                    "allOf": "$transparent"
                }
            }
        },
        "$schema": {
            "title": "Schema",
            "description": "A reference to this JSON schema. Not part of the actual format, but useful for validation tools.",
            "type": "string",
            "const": "https://smapi.io/schemas/content-patcher.json"
        }
    },
    "definitions": {
        "Condition": {
            "type": "object",
            "additionalProperties": {
                "type": [ "boolean", "string" ]
            }
        },
        "Rectangle": {
            "type": "object",
            "properties": {
                "X": {
                    "title": "X-Coordinate",
                    "description": "Location in pixels of the top-left of the rectangle",
                    "type": "integer",
                    "minimum:": 0
                },
                "Y": {
                    "title": "Y-Coordinate",
                    "description": "Location in pixels of the top-left of the rectangle",
                    "type": "integer",
                    "minimum:": 0
                },
                "Width": {
                    "title": "Width",
                    "description": "The width of the rectangle",
                    "type": "integer",
                    "minimum:": 0
                },
                "Height": {
                    "title": "Height",
                    "description": "The height of the rectangle",
                    "type": "integer",
                    "minimum:": 0
                }
            },

            "required": [ "X", "Y", "Width", "Height" ],
            "additionalProperties": false
        }
    },

    "required": [ "Format", "Changes" ],
    "additionalProperties": false
}