@codexo/exojs-tiled 0.15.3 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -66
- package/dist/esm/TiledLayer.d.ts +2 -1
- package/dist/esm/TiledLayer.d.ts.map +1 -0
- package/dist/esm/TiledLayer.js +106 -108
- package/dist/esm/TiledLayer.js.map +1 -1
- package/dist/esm/TiledMap.d.ts +35 -7
- package/dist/esm/TiledMap.d.ts.map +1 -0
- package/dist/esm/TiledMap.js +714 -589
- package/dist/esm/TiledMap.js.map +1 -1
- package/dist/esm/TiledObject.d.ts +7 -0
- package/dist/esm/TiledObject.d.ts.map +1 -0
- package/dist/esm/TiledObject.js +59 -51
- package/dist/esm/TiledObject.js.map +1 -1
- package/dist/esm/TiledTileset.d.ts +11 -4
- package/dist/esm/TiledTileset.d.ts.map +1 -0
- package/dist/esm/TiledTileset.js +81 -70
- package/dist/esm/TiledTileset.js.map +1 -1
- package/dist/esm/data.d.ts +25 -7
- package/dist/esm/data.d.ts.map +1 -0
- package/dist/esm/decodeLayerData.d.ts +2 -1
- package/dist/esm/decodeLayerData.d.ts.map +1 -0
- package/dist/esm/decodeLayerData.js +53 -92
- package/dist/esm/decodeLayerData.js.map +1 -1
- package/dist/esm/gid.d.ts +2 -1
- package/dist/esm/gid.d.ts.map +1 -0
- package/dist/esm/gid.js +15 -24
- package/dist/esm/gid.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +14 -12
- package/dist/esm/loadTiledMap.d.ts +11 -5
- package/dist/esm/loadTiledMap.d.ts.map +1 -0
- package/dist/esm/loadTiledMap.js +82 -91
- package/dist/esm/loadTiledMap.js.map +1 -1
- package/dist/esm/objectAlignment.d.ts +28 -0
- package/dist/esm/objectAlignment.d.ts.map +1 -0
- package/dist/esm/objectAlignment.js +79 -0
- package/dist/esm/objectAlignment.js.map +1 -0
- package/dist/esm/public.d.ts +17 -15
- package/dist/esm/public.d.ts.map +1 -0
- package/dist/esm/public.js +14 -0
- package/dist/esm/tileMapType.d.ts +31 -0
- package/dist/esm/tileMapType.d.ts.map +1 -0
- package/dist/esm/tileMapType.js +42 -0
- package/dist/esm/tileMapType.js.map +1 -0
- package/dist/esm/tiledBuildInfo.d.ts +1 -0
- package/dist/esm/tiledBuildInfo.d.ts.map +1 -0
- package/dist/esm/tiledBuildInfo.js +6 -4
- package/dist/esm/tiledBuildInfo.js.map +1 -1
- package/dist/esm/tiledExtension.d.ts +7 -6
- package/dist/esm/tiledExtension.d.ts.map +1 -0
- package/dist/esm/tiledExtension.js +23 -25
- package/dist/esm/tiledExtension.js.map +1 -1
- package/dist/esm/tiledOptions.d.ts +5 -4
- package/dist/esm/tiledOptions.d.ts.map +1 -0
- package/dist/esm/tiledOptions.js +11 -13
- package/dist/esm/tiledOptions.js.map +1 -1
- package/dist/esm/tiledSourceType.d.ts +24 -0
- package/dist/esm/tiledSourceType.d.ts.map +1 -0
- package/dist/esm/tiledSourceType.js +44 -0
- package/dist/esm/tiledSourceType.js.map +1 -0
- package/dist/esm/url.d.ts +2 -1
- package/dist/esm/url.d.ts.map +1 -0
- package/dist/esm/url.js +26 -37
- package/dist/esm/url.js.map +1 -1
- package/dist/esm/validate.d.ts +11 -10
- package/dist/esm/validate.d.ts.map +1 -0
- package/dist/esm/validate.js +485 -534
- package/dist/esm/validate.js.map +1 -1
- package/dist/esm/wangSets.d.ts +5 -4
- package/dist/esm/wangSets.d.ts.map +1 -0
- package/dist/esm/wangSets.js +90 -115
- package/dist/esm/wangSets.js.map +1 -1
- package/package.json +10 -18
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/register.d.ts +0 -1
- package/dist/esm/register.js +0 -22
- package/dist/esm/register.js.map +0 -1
- package/dist/esm/tiledMapBinding.d.ts +0 -19
- package/dist/esm/tiledMapBinding.js +0 -31
- package/dist/esm/tiledMapBinding.js.map +0 -1
- package/dist/esm/tiledRuntimeMapBinding.d.ts +0 -29
- package/dist/esm/tiledRuntimeMapBinding.js +0 -42
- package/dist/esm/tiledRuntimeMapBinding.js.map +0 -1
package/dist/esm/validate.js
CHANGED
|
@@ -1,547 +1,498 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//
|
|
5
|
-
// There is no fall-through: an unrecognised shape, an unsupported encoding,
|
|
6
|
-
// or an out-of-range value is always a thrown error carrying the source URL
|
|
7
|
-
// and a JSON-path-like field path, never a silently-substituted default.
|
|
1
|
+
import { TILED_OBJECT_ALIGNMENTS } from "./objectAlignment.js";
|
|
2
|
+
|
|
3
|
+
//#region src/validate.ts
|
|
8
4
|
/**
|
|
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
|
-
return value === undefined ? undefined : mapArray(value, source, path, fn);
|
|
114
|
-
}
|
|
115
|
-
// ── Custom properties ───────────────────────────────────────────────────────
|
|
116
|
-
const PROPERTY_TYPES = ['string', 'int', 'float', 'bool', 'color', 'file', 'object', 'class'];
|
|
117
|
-
function validateTiledClassPropertyValue(raw, source, path) {
|
|
118
|
-
const obj = expectObject(raw, source, path);
|
|
119
|
-
const result = {};
|
|
120
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
121
|
-
const memberPath = joinPath(path, key);
|
|
122
|
-
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
123
|
-
result[key] = value;
|
|
124
|
-
}
|
|
125
|
-
else if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
126
|
-
result[key] = validateTiledClassPropertyValue(value, source, memberPath);
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
throw new TiledFormatError(source, memberPath, `expected a string, number, boolean, or nested object, got ${describeValue(value)}`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return result;
|
|
133
|
-
}
|
|
5
|
+
* Thrown when a Tiled JSON document does not match the expected shape.
|
|
6
|
+
* `source` is the URL of the file being parsed; `path` is a JSON-path-like
|
|
7
|
+
* pointer (e.g. `layers[2].objects[0].properties[1].value`) to the offending
|
|
8
|
+
* value, or `''` for the document root.
|
|
9
|
+
*/
|
|
10
|
+
var TiledFormatError = class extends Error {
|
|
11
|
+
source;
|
|
12
|
+
path;
|
|
13
|
+
constructor(source, path, message) {
|
|
14
|
+
super(`Invalid Tiled data in "${source}" at ${path === "" ? "<root>" : path}: ${message}`);
|
|
15
|
+
this.name = "TiledFormatError";
|
|
16
|
+
this.source = source;
|
|
17
|
+
this.path = path;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const describeValue = (value) => {
|
|
21
|
+
if (value === null) return "null";
|
|
22
|
+
if (Array.isArray(value)) return "an array";
|
|
23
|
+
return typeof value;
|
|
24
|
+
};
|
|
25
|
+
const joinPath = (path, key) => {
|
|
26
|
+
if (typeof key === "number") return `${path}[${key}]`;
|
|
27
|
+
return path === "" ? key : `${path}.${key}`;
|
|
28
|
+
};
|
|
29
|
+
const expectObject = (value, source, path) => {
|
|
30
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TiledFormatError(source, path, `expected an object, got ${describeValue(value)}`);
|
|
31
|
+
return value;
|
|
32
|
+
};
|
|
33
|
+
const expectArray = (value, source, path) => {
|
|
34
|
+
if (!Array.isArray(value)) throw new TiledFormatError(source, path, `expected an array, got ${describeValue(value)}`);
|
|
35
|
+
return value;
|
|
36
|
+
};
|
|
37
|
+
const expectString = (value, source, path) => {
|
|
38
|
+
if (typeof value !== "string") throw new TiledFormatError(source, path, `expected a string, got ${describeValue(value)}`);
|
|
39
|
+
return value;
|
|
40
|
+
};
|
|
41
|
+
const expectNumber = (value, source, path) => {
|
|
42
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new TiledFormatError(source, path, `expected a finite number, got ${describeValue(value)}`);
|
|
43
|
+
return value;
|
|
44
|
+
};
|
|
45
|
+
const expectInteger = (value, source, path) => {
|
|
46
|
+
const n = expectNumber(value, source, path);
|
|
47
|
+
if (!Number.isInteger(n)) throw new TiledFormatError(source, path, `expected an integer, got ${n}`);
|
|
48
|
+
return n;
|
|
49
|
+
};
|
|
50
|
+
const expectNonNegativeInteger = (value, source, path) => {
|
|
51
|
+
const n = expectInteger(value, source, path);
|
|
52
|
+
if (n < 0) throw new TiledFormatError(source, path, `expected a non-negative integer, got ${n}`);
|
|
53
|
+
return n;
|
|
54
|
+
};
|
|
55
|
+
const expectPositiveInteger = (value, source, path) => {
|
|
56
|
+
const n = expectInteger(value, source, path);
|
|
57
|
+
if (n <= 0) throw new TiledFormatError(source, path, `expected a positive integer, got ${n}`);
|
|
58
|
+
return n;
|
|
59
|
+
};
|
|
60
|
+
const expectBoolean = (value, source, path) => {
|
|
61
|
+
if (typeof value !== "boolean") throw new TiledFormatError(source, path, `expected a boolean, got ${describeValue(value)}`);
|
|
62
|
+
return value;
|
|
63
|
+
};
|
|
64
|
+
const optionalString = (obj, key, source, path) => {
|
|
65
|
+
const value = obj[key];
|
|
66
|
+
return value === void 0 ? void 0 : expectString(value, source, joinPath(path, key));
|
|
67
|
+
};
|
|
68
|
+
const optionalNumber = (obj, key, source, path) => {
|
|
69
|
+
const value = obj[key];
|
|
70
|
+
return value === void 0 ? void 0 : expectNumber(value, source, joinPath(path, key));
|
|
71
|
+
};
|
|
72
|
+
const optionalInteger = (obj, key, source, path) => {
|
|
73
|
+
const value = obj[key];
|
|
74
|
+
return value === void 0 ? void 0 : expectInteger(value, source, joinPath(path, key));
|
|
75
|
+
};
|
|
76
|
+
const optionalNonNegativeInteger = (obj, key, source, path) => {
|
|
77
|
+
const value = obj[key];
|
|
78
|
+
return value === void 0 ? void 0 : expectNonNegativeInteger(value, source, joinPath(path, key));
|
|
79
|
+
};
|
|
80
|
+
const optionalBoolean = (obj, key, source, path) => {
|
|
81
|
+
const value = obj[key];
|
|
82
|
+
return value === void 0 ? void 0 : expectBoolean(value, source, joinPath(path, key));
|
|
83
|
+
};
|
|
84
|
+
const mapArray = (value, source, path, fn) => {
|
|
85
|
+
return expectArray(value, source, path).map((item, i) => fn(item, joinPath(path, i)));
|
|
86
|
+
};
|
|
87
|
+
const optionalMapArray = (value, source, path, fn) => value === void 0 ? void 0 : mapArray(value, source, path, fn);
|
|
88
|
+
const PROPERTY_TYPES = [
|
|
89
|
+
"string",
|
|
90
|
+
"int",
|
|
91
|
+
"float",
|
|
92
|
+
"bool",
|
|
93
|
+
"color",
|
|
94
|
+
"file",
|
|
95
|
+
"object",
|
|
96
|
+
"class"
|
|
97
|
+
];
|
|
98
|
+
const validateTiledClassPropertyValue = (raw, source, path) => {
|
|
99
|
+
const obj = expectObject(raw, source, path);
|
|
100
|
+
const result = {};
|
|
101
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
102
|
+
const memberPath = joinPath(path, key);
|
|
103
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") result[key] = value;
|
|
104
|
+
else if (typeof value === "object" && value !== null && !Array.isArray(value)) result[key] = validateTiledClassPropertyValue(value, source, memberPath);
|
|
105
|
+
else throw new TiledFormatError(source, memberPath, `expected a string, number, boolean, or nested object, got ${describeValue(value)}`);
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
};
|
|
134
109
|
/** @internal */
|
|
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
|
-
function validateTiledPointArray(value, source, path) {
|
|
179
|
-
return mapArray(value, source, path, (item, itemPath) => validateTiledPointData(item, source, itemPath));
|
|
180
|
-
}
|
|
110
|
+
const validateTiledPropertyData = (raw, source, path) => {
|
|
111
|
+
const obj = expectObject(raw, source, path);
|
|
112
|
+
const name = expectString(obj.name, source, joinPath(path, "name"));
|
|
113
|
+
const typePath = joinPath(path, "type");
|
|
114
|
+
const typeName = obj.type === void 0 ? "string" : expectString(obj.type, source, typePath);
|
|
115
|
+
if (!PROPERTY_TYPES.includes(typeName)) throw new TiledFormatError(source, typePath, `unknown property type "${typeName}"`);
|
|
116
|
+
const type = typeName;
|
|
117
|
+
const propertytype = optionalString(obj, "propertytype", source, path);
|
|
118
|
+
const valuePath = joinPath(path, "value");
|
|
119
|
+
let value;
|
|
120
|
+
switch (type) {
|
|
121
|
+
case "string":
|
|
122
|
+
case "color":
|
|
123
|
+
case "file":
|
|
124
|
+
value = expectString(obj.value, source, valuePath);
|
|
125
|
+
break;
|
|
126
|
+
case "int":
|
|
127
|
+
case "float":
|
|
128
|
+
case "object":
|
|
129
|
+
value = expectNumber(obj.value, source, valuePath);
|
|
130
|
+
break;
|
|
131
|
+
case "bool":
|
|
132
|
+
value = expectBoolean(obj.value, source, valuePath);
|
|
133
|
+
break;
|
|
134
|
+
case "class": value = validateTiledClassPropertyValue(obj.value, source, valuePath);
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
name,
|
|
138
|
+
type,
|
|
139
|
+
propertytype,
|
|
140
|
+
value
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
const validateTiledPropertiesArray = (value, source, path) => optionalMapArray(value, source, path, (item, itemPath) => validateTiledPropertyData(item, source, itemPath));
|
|
144
|
+
const validateTiledPointData = (raw, source, path) => {
|
|
145
|
+
const obj = expectObject(raw, source, path);
|
|
146
|
+
return {
|
|
147
|
+
x: expectNumber(obj.x, source, joinPath(path, "x")),
|
|
148
|
+
y: expectNumber(obj.y, source, joinPath(path, "y"))
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
const validateTiledPointArray = (value, source, path) => mapArray(value, source, path, (item, itemPath) => validateTiledPointData(item, source, itemPath));
|
|
181
152
|
/** @internal */
|
|
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
|
-
|
|
153
|
+
const validateTiledAnimationFrameData = (raw, source, path) => {
|
|
154
|
+
const obj = expectObject(raw, source, path);
|
|
155
|
+
return {
|
|
156
|
+
tileid: expectNonNegativeInteger(obj.tileid, source, joinPath(path, "tileid")),
|
|
157
|
+
duration: expectNonNegativeInteger(obj.duration, source, joinPath(path, "duration"))
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
const HALIGN_VALUES = [
|
|
161
|
+
"center",
|
|
162
|
+
"right",
|
|
163
|
+
"justify",
|
|
164
|
+
"left"
|
|
165
|
+
];
|
|
166
|
+
const VALIGN_VALUES = [
|
|
167
|
+
"center",
|
|
168
|
+
"bottom",
|
|
169
|
+
"top"
|
|
170
|
+
];
|
|
171
|
+
const validateTiledTextData = (raw, source, path) => {
|
|
172
|
+
const obj = expectObject(raw, source, path);
|
|
173
|
+
const text = expectString(obj.text, source, joinPath(path, "text"));
|
|
174
|
+
let halign;
|
|
175
|
+
if (obj.halign !== void 0) {
|
|
176
|
+
const value = expectString(obj.halign, source, joinPath(path, "halign"));
|
|
177
|
+
if (!HALIGN_VALUES.includes(value)) throw new TiledFormatError(source, joinPath(path, "halign"), `unknown horizontal alignment "${value}"`);
|
|
178
|
+
halign = value;
|
|
179
|
+
}
|
|
180
|
+
let valign;
|
|
181
|
+
if (obj.valign !== void 0) {
|
|
182
|
+
const value = expectString(obj.valign, source, joinPath(path, "valign"));
|
|
183
|
+
if (!VALIGN_VALUES.includes(value)) throw new TiledFormatError(source, joinPath(path, "valign"), `unknown vertical alignment "${value}"`);
|
|
184
|
+
valign = value;
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
text,
|
|
188
|
+
bold: optionalBoolean(obj, "bold", source, path),
|
|
189
|
+
color: optionalString(obj, "color", source, path),
|
|
190
|
+
fontfamily: optionalString(obj, "fontfamily", source, path),
|
|
191
|
+
halign,
|
|
192
|
+
italic: optionalBoolean(obj, "italic", source, path),
|
|
193
|
+
kerning: optionalBoolean(obj, "kerning", source, path),
|
|
194
|
+
pixelsize: optionalNonNegativeInteger(obj, "pixelsize", source, path),
|
|
195
|
+
strikeout: optionalBoolean(obj, "strikeout", source, path),
|
|
196
|
+
underline: optionalBoolean(obj, "underline", source, path),
|
|
197
|
+
valign,
|
|
198
|
+
wrap: optionalBoolean(obj, "wrap", source, path)
|
|
199
|
+
};
|
|
200
|
+
};
|
|
227
201
|
/** @internal */
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const LAYER_TYPES = [
|
|
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
|
-
return {
|
|
330
|
-
...base,
|
|
331
|
-
type: 'imagelayer',
|
|
332
|
-
image: obj.image === undefined ? '' : expectString(obj.image, source, joinPath(path, 'image')),
|
|
333
|
-
repeatx: optionalBoolean(obj, 'repeatx', source, path),
|
|
334
|
-
repeaty: optionalBoolean(obj, 'repeaty', source, path),
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
function validateTiledGroupLayerData(obj, base, source, path) {
|
|
338
|
-
return {
|
|
339
|
-
...base,
|
|
340
|
-
type: 'group',
|
|
341
|
-
layers: mapArray(obj.layers, source, joinPath(path, 'layers'), (item, itemPath) => validateTiledLayerData(item, source, itemPath)),
|
|
342
|
-
};
|
|
343
|
-
}
|
|
202
|
+
const validateTiledObjectData = (raw, source, path) => {
|
|
203
|
+
const obj = expectObject(raw, source, path);
|
|
204
|
+
return {
|
|
205
|
+
id: expectNonNegativeInteger(obj.id, source, joinPath(path, "id")),
|
|
206
|
+
name: expectString(obj.name, source, joinPath(path, "name")),
|
|
207
|
+
type: optionalString(obj, "type", source, path) ?? "",
|
|
208
|
+
class: optionalString(obj, "class", source, path),
|
|
209
|
+
x: expectNumber(obj.x, source, joinPath(path, "x")),
|
|
210
|
+
y: expectNumber(obj.y, source, joinPath(path, "y")),
|
|
211
|
+
width: expectNumber(obj.width, source, joinPath(path, "width")),
|
|
212
|
+
height: expectNumber(obj.height, source, joinPath(path, "height")),
|
|
213
|
+
rotation: expectNumber(obj.rotation, source, joinPath(path, "rotation")),
|
|
214
|
+
visible: expectBoolean(obj.visible, source, joinPath(path, "visible")),
|
|
215
|
+
gid: optionalNonNegativeInteger(obj, "gid", source, path),
|
|
216
|
+
point: optionalBoolean(obj, "point", source, path),
|
|
217
|
+
ellipse: optionalBoolean(obj, "ellipse", source, path),
|
|
218
|
+
polygon: obj.polygon === void 0 ? void 0 : validateTiledPointArray(obj.polygon, source, joinPath(path, "polygon")),
|
|
219
|
+
polyline: obj.polyline === void 0 ? void 0 : validateTiledPointArray(obj.polyline, source, joinPath(path, "polyline")),
|
|
220
|
+
text: obj.text === void 0 ? void 0 : validateTiledTextData(obj.text, source, joinPath(path, "text")),
|
|
221
|
+
template: optionalString(obj, "template", source, path),
|
|
222
|
+
properties: validateTiledPropertiesArray(obj.properties, source, joinPath(path, "properties"))
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
const LAYER_TYPES = [
|
|
226
|
+
"tilelayer",
|
|
227
|
+
"objectgroup",
|
|
228
|
+
"imagelayer",
|
|
229
|
+
"group"
|
|
230
|
+
];
|
|
231
|
+
const SUPPORTED_TILE_LAYER_ENCODINGS = /* @__PURE__ */ new Set(["csv"]);
|
|
232
|
+
const DRAW_ORDERS = ["topdown", "index"];
|
|
233
|
+
const validateTiledLayerBase = (obj, source, path) => ({
|
|
234
|
+
id: expectNonNegativeInteger(obj.id, source, joinPath(path, "id")),
|
|
235
|
+
name: expectString(obj.name, source, joinPath(path, "name")),
|
|
236
|
+
class: optionalString(obj, "class", source, path),
|
|
237
|
+
visible: expectBoolean(obj.visible, source, joinPath(path, "visible")),
|
|
238
|
+
opacity: expectNumber(obj.opacity, source, joinPath(path, "opacity")),
|
|
239
|
+
x: expectNumber(obj.x, source, joinPath(path, "x")),
|
|
240
|
+
y: expectNumber(obj.y, source, joinPath(path, "y")),
|
|
241
|
+
offsetx: optionalNumber(obj, "offsetx", source, path),
|
|
242
|
+
offsety: optionalNumber(obj, "offsety", source, path),
|
|
243
|
+
parallaxx: optionalNumber(obj, "parallaxx", source, path),
|
|
244
|
+
parallaxy: optionalNumber(obj, "parallaxy", source, path),
|
|
245
|
+
tintcolor: optionalString(obj, "tintcolor", source, path),
|
|
246
|
+
properties: validateTiledPropertiesArray(obj.properties, source, joinPath(path, "properties"))
|
|
247
|
+
});
|
|
248
|
+
const validateTiledGidArray = (value, source, path) => mapArray(value, source, path, (item, itemPath) => expectNonNegativeInteger(item, source, itemPath));
|
|
249
|
+
const validateTiledChunkData = (raw, source, path) => {
|
|
250
|
+
const obj = expectObject(raw, source, path);
|
|
251
|
+
return {
|
|
252
|
+
x: expectInteger(obj.x, source, joinPath(path, "x")),
|
|
253
|
+
y: expectInteger(obj.y, source, joinPath(path, "y")),
|
|
254
|
+
width: expectPositiveInteger(obj.width, source, joinPath(path, "width")),
|
|
255
|
+
height: expectPositiveInteger(obj.height, source, joinPath(path, "height")),
|
|
256
|
+
data: validateTiledGidArray(obj.data, source, joinPath(path, "data"))
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
const validateTiledTileLayerData = (obj, base, source, path) => {
|
|
260
|
+
if (obj.compression !== void 0) throw new TiledFormatError(source, joinPath(path, "compression"), `compressed tile layer data is not supported (compression: ${JSON.stringify(obj.compression)})`);
|
|
261
|
+
const encoding = obj.encoding;
|
|
262
|
+
if (encoding !== void 0 && !(typeof encoding === "string" && SUPPORTED_TILE_LAYER_ENCODINGS.has(encoding))) throw new TiledFormatError(source, joinPath(path, "encoding"), `unsupported tile layer encoding ${JSON.stringify(encoding)} (only plain CSV/array data is supported)`);
|
|
263
|
+
const width = expectNonNegativeInteger(obj.width, source, joinPath(path, "width"));
|
|
264
|
+
const height = expectNonNegativeInteger(obj.height, source, joinPath(path, "height"));
|
|
265
|
+
const hasData = obj.data !== void 0;
|
|
266
|
+
const hasChunks = obj.chunks !== void 0;
|
|
267
|
+
if (hasData === hasChunks) throw new TiledFormatError(source, path, hasData ? "tile layer has both \"data\" and \"chunks\"" : "tile layer has neither \"data\" nor \"chunks\"");
|
|
268
|
+
return {
|
|
269
|
+
...base,
|
|
270
|
+
type: "tilelayer",
|
|
271
|
+
width,
|
|
272
|
+
height,
|
|
273
|
+
data: hasData ? validateTiledGidArray(obj.data, source, joinPath(path, "data")) : void 0,
|
|
274
|
+
chunks: hasChunks ? mapArray(obj.chunks, source, joinPath(path, "chunks"), (item, itemPath) => validateTiledChunkData(item, source, itemPath)) : void 0
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
const validateTiledObjectLayerData = (obj, base, source, path) => {
|
|
278
|
+
let draworder;
|
|
279
|
+
if (obj.draworder !== void 0) {
|
|
280
|
+
const value = expectString(obj.draworder, source, joinPath(path, "draworder"));
|
|
281
|
+
if (!DRAW_ORDERS.includes(value)) throw new TiledFormatError(source, joinPath(path, "draworder"), `unknown draw order "${value}"`);
|
|
282
|
+
draworder = value;
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
...base,
|
|
286
|
+
type: "objectgroup",
|
|
287
|
+
draworder,
|
|
288
|
+
objects: mapArray(obj.objects, source, joinPath(path, "objects"), (item, itemPath) => validateTiledObjectData(item, source, itemPath))
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
const validateTiledImageLayerData = (obj, base, source, path) => ({
|
|
292
|
+
...base,
|
|
293
|
+
type: "imagelayer",
|
|
294
|
+
image: obj.image === void 0 ? "" : expectString(obj.image, source, joinPath(path, "image")),
|
|
295
|
+
repeatx: optionalBoolean(obj, "repeatx", source, path),
|
|
296
|
+
repeaty: optionalBoolean(obj, "repeaty", source, path)
|
|
297
|
+
});
|
|
298
|
+
const validateTiledGroupLayerData = (obj, base, source, path) => ({
|
|
299
|
+
...base,
|
|
300
|
+
type: "group",
|
|
301
|
+
layers: mapArray(obj.layers, source, joinPath(path, "layers"), (item, itemPath) => validateTiledLayerData(item, source, itemPath))
|
|
302
|
+
});
|
|
344
303
|
/** @internal */
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
throw new TiledFormatError(source, joinPath(path, 'type'), `unknown layer type "${type}" (expected one of ${known.join(', ')})`);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
304
|
+
const validateTiledLayerData = (raw, source, path) => {
|
|
305
|
+
const obj = expectObject(raw, source, path);
|
|
306
|
+
const type = expectString(obj.type, source, joinPath(path, "type"));
|
|
307
|
+
const base = validateTiledLayerBase(obj, source, path);
|
|
308
|
+
switch (type) {
|
|
309
|
+
case "tilelayer": return validateTiledTileLayerData(obj, base, source, path);
|
|
310
|
+
case "objectgroup": return validateTiledObjectLayerData(obj, base, source, path);
|
|
311
|
+
case "imagelayer": return validateTiledImageLayerData(obj, base, source, path);
|
|
312
|
+
case "group": return validateTiledGroupLayerData(obj, base, source, path);
|
|
313
|
+
default: {
|
|
314
|
+
const known = LAYER_TYPES;
|
|
315
|
+
throw new TiledFormatError(source, joinPath(path, "type"), `unknown layer type "${type}" (expected one of ${known.join(", ")})`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
};
|
|
364
319
|
/**
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
else if (layer.type === 'group') {
|
|
383
|
-
checkTiledLayerInfiniteConsistency(layer.layers, infinite, source, joinPath(layerPath, 'layers'));
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
// ── Tile definitions ─────────────────────────────────────────────────────────
|
|
320
|
+
* Walks a layer tree and ensures every tile layer's `data`/`chunks` choice
|
|
321
|
+
* matches the map's `infinite` flag. Tiled itself is consistent across an
|
|
322
|
+
* entire map; a mismatch indicates a hand-edited or corrupt file.
|
|
323
|
+
* @internal
|
|
324
|
+
*/
|
|
325
|
+
const checkTiledLayerInfiniteConsistency = (layers, infinite, source, path) => {
|
|
326
|
+
for (let i = 0; i < layers.length; i++) {
|
|
327
|
+
const layer = layers[i];
|
|
328
|
+
if (layer === void 0) continue;
|
|
329
|
+
const layerPath = joinPath(path, i);
|
|
330
|
+
if (layer.type === "tilelayer") {
|
|
331
|
+
if (layer.chunks !== void 0 !== infinite) throw new TiledFormatError(source, layerPath, infinite ? "tile layer is missing \"chunks\" on an infinite map" : "tile layer has \"chunks\" on a finite map (expected \"data\")");
|
|
332
|
+
} else if (layer.type === "group") checkTiledLayerInfiniteConsistency(layer.layers, infinite, source, joinPath(layerPath, "layers"));
|
|
333
|
+
}
|
|
334
|
+
};
|
|
388
335
|
/** @internal */
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
}
|
|
336
|
+
const validateTiledTileData = (raw, source, path) => {
|
|
337
|
+
const obj = expectObject(raw, source, path);
|
|
338
|
+
let objectgroup;
|
|
339
|
+
if (obj.objectgroup !== void 0) {
|
|
340
|
+
const objectgroupPath = joinPath(path, "objectgroup");
|
|
341
|
+
const layer = validateTiledLayerData(obj.objectgroup, source, objectgroupPath);
|
|
342
|
+
if (layer.type !== "objectgroup") throw new TiledFormatError(source, objectgroupPath, `expected an "objectgroup" layer, got "${layer.type}"`);
|
|
343
|
+
objectgroup = layer;
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
id: expectNonNegativeInteger(obj.id, source, joinPath(path, "id")),
|
|
347
|
+
type: optionalString(obj, "type", source, path),
|
|
348
|
+
properties: validateTiledPropertiesArray(obj.properties, source, joinPath(path, "properties")),
|
|
349
|
+
animation: optionalMapArray(obj.animation, source, joinPath(path, "animation"), (item, itemPath) => validateTiledAnimationFrameData(item, source, itemPath)),
|
|
350
|
+
objectgroup,
|
|
351
|
+
image: optionalString(obj, "image", source, path),
|
|
352
|
+
imagewidth: optionalNonNegativeInteger(obj, "imagewidth", source, path),
|
|
353
|
+
imageheight: optionalNonNegativeInteger(obj, "imageheight", source, path)
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
const validateTiledWangColorData = (raw, source, path) => {
|
|
357
|
+
const obj = expectObject(raw, source, path);
|
|
358
|
+
return {
|
|
359
|
+
name: expectString(obj.name, source, joinPath(path, "name")),
|
|
360
|
+
color: expectString(obj.color, source, joinPath(path, "color")),
|
|
361
|
+
tile: expectInteger(obj.tile, source, joinPath(path, "tile")),
|
|
362
|
+
probability: expectNumber(obj.probability, source, joinPath(path, "probability"))
|
|
363
|
+
};
|
|
364
|
+
};
|
|
365
|
+
const validateTiledWangTileData = (raw, source, path) => {
|
|
366
|
+
const obj = expectObject(raw, source, path);
|
|
367
|
+
return {
|
|
368
|
+
tileid: expectNonNegativeInteger(obj.tileid, source, joinPath(path, "tileid")),
|
|
369
|
+
wangid: mapArray(obj.wangid, source, joinPath(path, "wangid"), (item, itemPath) => expectNonNegativeInteger(item, source, itemPath))
|
|
370
|
+
};
|
|
371
|
+
};
|
|
372
|
+
const validateTiledWangSetData = (raw, source, path) => {
|
|
373
|
+
const obj = expectObject(raw, source, path);
|
|
374
|
+
return {
|
|
375
|
+
name: expectString(obj.name, source, joinPath(path, "name")),
|
|
376
|
+
type: expectString(obj.type, source, joinPath(path, "type")),
|
|
377
|
+
tile: expectInteger(obj.tile, source, joinPath(path, "tile")),
|
|
378
|
+
colors: mapArray(obj.colors, source, joinPath(path, "colors"), (item, itemPath) => validateTiledWangColorData(item, source, itemPath)),
|
|
379
|
+
wangtiles: mapArray(obj.wangtiles, source, joinPath(path, "wangtiles"), (item, itemPath) => validateTiledWangTileData(item, source, itemPath)),
|
|
380
|
+
properties: validateTiledPropertiesArray(obj.properties, source, joinPath(path, "properties"))
|
|
381
|
+
};
|
|
382
|
+
};
|
|
383
|
+
const validateTiledWangSets = (value, source, path) => optionalMapArray(value, source, path, (item, itemPath) => validateTiledWangSetData(item, source, itemPath));
|
|
384
|
+
const validateTiledVersion = (value, source, path) => {
|
|
385
|
+
if (typeof value !== "string" && typeof value !== "number") throw new TiledFormatError(source, path, `expected a string or number, got ${describeValue(value)}`);
|
|
386
|
+
return value;
|
|
387
|
+
};
|
|
388
|
+
const validateTiledObjectAlignment = (obj, source, path) => {
|
|
389
|
+
const value = obj.objectalignment;
|
|
390
|
+
if (value === void 0) return void 0;
|
|
391
|
+
const alignmentPath = joinPath(path, "objectalignment");
|
|
392
|
+
const name = expectString(value, source, alignmentPath);
|
|
393
|
+
if (!TILED_OBJECT_ALIGNMENTS.includes(name)) throw new TiledFormatError(source, alignmentPath, `unknown object alignment "${name}" (expected one of ${TILED_OBJECT_ALIGNMENTS.join(", ")})`);
|
|
394
|
+
return name;
|
|
395
|
+
};
|
|
449
396
|
/** @internal */
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
};
|
|
471
|
-
}
|
|
397
|
+
const validateTiledTilesetData = (obj, source, path) => ({
|
|
398
|
+
name: expectString(obj.name, source, joinPath(path, "name")),
|
|
399
|
+
class: optionalString(obj, "class", source, path),
|
|
400
|
+
tilewidth: expectPositiveInteger(obj.tilewidth, source, joinPath(path, "tilewidth")),
|
|
401
|
+
tileheight: expectPositiveInteger(obj.tileheight, source, joinPath(path, "tileheight")),
|
|
402
|
+
tilecount: expectNonNegativeInteger(obj.tilecount, source, joinPath(path, "tilecount")),
|
|
403
|
+
columns: expectNonNegativeInteger(obj.columns, source, joinPath(path, "columns")),
|
|
404
|
+
spacing: optionalNonNegativeInteger(obj, "spacing", source, path),
|
|
405
|
+
margin: optionalNonNegativeInteger(obj, "margin", source, path),
|
|
406
|
+
image: optionalString(obj, "image", source, path),
|
|
407
|
+
imagewidth: optionalNonNegativeInteger(obj, "imagewidth", source, path),
|
|
408
|
+
imageheight: optionalNonNegativeInteger(obj, "imageheight", source, path),
|
|
409
|
+
tileoffset: obj.tileoffset === void 0 ? void 0 : validateTiledPointData(obj.tileoffset, source, joinPath(path, "tileoffset")),
|
|
410
|
+
objectalignment: validateTiledObjectAlignment(obj, source, path),
|
|
411
|
+
tiles: optionalMapArray(obj.tiles, source, joinPath(path, "tiles"), (item, itemPath) => validateTiledTileData(item, source, itemPath)),
|
|
412
|
+
wangsets: validateTiledWangSets(obj.wangsets, source, joinPath(path, "wangsets")),
|
|
413
|
+
properties: validateTiledPropertiesArray(obj.properties, source, joinPath(path, "properties")),
|
|
414
|
+
tiledversion: optionalString(obj, "tiledversion", source, path),
|
|
415
|
+
version: obj.version === void 0 ? void 0 : validateTiledVersion(obj.version, source, joinPath(path, "version"))
|
|
416
|
+
});
|
|
472
417
|
/**
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
418
|
+
* Validates one entry of a map's `tilesets` array: either `{ firstgid,
|
|
419
|
+
* source }` (external `.tsj`) or `{ firstgid, ...embedded tileset fields }`.
|
|
420
|
+
* @internal
|
|
421
|
+
*/
|
|
422
|
+
const validateTiledTilesetRefData = (raw, source, path) => {
|
|
423
|
+
const obj = expectObject(raw, source, path);
|
|
424
|
+
const firstgid = expectPositiveInteger(obj.firstgid, source, joinPath(path, "firstgid"));
|
|
425
|
+
if ("source" in obj) return {
|
|
426
|
+
firstgid,
|
|
427
|
+
source: expectString(obj.source, source, joinPath(path, "source"))
|
|
428
|
+
};
|
|
429
|
+
return {
|
|
430
|
+
...validateTiledTilesetData(obj, source, path),
|
|
431
|
+
firstgid
|
|
432
|
+
};
|
|
433
|
+
};
|
|
434
|
+
const ORIENTATIONS = [
|
|
435
|
+
"orthogonal",
|
|
436
|
+
"isometric",
|
|
437
|
+
"staggered",
|
|
438
|
+
"hexagonal"
|
|
439
|
+
];
|
|
440
|
+
const RENDER_ORDERS = [
|
|
441
|
+
"right-down",
|
|
442
|
+
"right-up",
|
|
443
|
+
"left-down",
|
|
444
|
+
"left-up"
|
|
445
|
+
];
|
|
488
446
|
/**
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
backgroundcolor: optionalString(obj, 'backgroundcolor', source, ''),
|
|
533
|
-
layers,
|
|
534
|
-
tilesets: mapArray(obj.tilesets, source, 'tilesets', (item, itemPath) => validateTiledTilesetRefData(item, source, itemPath)),
|
|
535
|
-
properties: validateTiledPropertiesArray(obj.properties, source, 'properties'),
|
|
536
|
-
};
|
|
537
|
-
}
|
|
447
|
+
* Validates the root of a `.tmj` file. Throws {@link TiledFormatError} on
|
|
448
|
+
* any structural problem, including unsupported tile-layer encodings and
|
|
449
|
+
* `infinite`/`data`/`chunks` inconsistencies.
|
|
450
|
+
* @internal
|
|
451
|
+
*/
|
|
452
|
+
const validateTiledMapData = (raw, source) => {
|
|
453
|
+
const obj = expectObject(raw, source, "");
|
|
454
|
+
const type = expectString(obj.type, source, "type");
|
|
455
|
+
if (type !== "map") throw new TiledFormatError(source, "type", `expected "map", got "${type}"`);
|
|
456
|
+
const version = validateTiledVersion(obj.version, source, "version");
|
|
457
|
+
const orientationValue = expectString(obj.orientation, source, "orientation");
|
|
458
|
+
if (!ORIENTATIONS.includes(orientationValue)) throw new TiledFormatError(source, "orientation", `unknown orientation "${orientationValue}" (expected one of ${ORIENTATIONS.join(", ")})`);
|
|
459
|
+
const orientation = orientationValue;
|
|
460
|
+
let renderorder;
|
|
461
|
+
if (obj.renderorder !== void 0) {
|
|
462
|
+
const value = expectString(obj.renderorder, source, "renderorder");
|
|
463
|
+
if (!RENDER_ORDERS.includes(value)) throw new TiledFormatError(source, "renderorder", `unknown render order "${value}" (expected one of ${RENDER_ORDERS.join(", ")})`);
|
|
464
|
+
renderorder = value;
|
|
465
|
+
}
|
|
466
|
+
const infinite = expectBoolean(obj.infinite, source, "infinite");
|
|
467
|
+
const layers = mapArray(obj.layers, source, "layers", (item, itemPath) => validateTiledLayerData(item, source, itemPath));
|
|
468
|
+
checkTiledLayerInfiniteConsistency(layers, infinite, source, "layers");
|
|
469
|
+
return {
|
|
470
|
+
type: "map",
|
|
471
|
+
version,
|
|
472
|
+
tiledversion: optionalString(obj, "tiledversion", source, ""),
|
|
473
|
+
class: optionalString(obj, "class", source, ""),
|
|
474
|
+
orientation,
|
|
475
|
+
renderorder,
|
|
476
|
+
width: expectNonNegativeInteger(obj.width, source, "width"),
|
|
477
|
+
height: expectNonNegativeInteger(obj.height, source, "height"),
|
|
478
|
+
tilewidth: expectPositiveInteger(obj.tilewidth, source, "tilewidth"),
|
|
479
|
+
tileheight: expectPositiveInteger(obj.tileheight, source, "tileheight"),
|
|
480
|
+
infinite,
|
|
481
|
+
compressionlevel: optionalInteger(obj, "compressionlevel", source, ""),
|
|
482
|
+
nextlayerid: optionalNonNegativeInteger(obj, "nextlayerid", source, ""),
|
|
483
|
+
nextobjectid: optionalNonNegativeInteger(obj, "nextobjectid", source, ""),
|
|
484
|
+
backgroundcolor: optionalString(obj, "backgroundcolor", source, ""),
|
|
485
|
+
layers,
|
|
486
|
+
tilesets: mapArray(obj.tilesets, source, "tilesets", (item, itemPath) => validateTiledTilesetRefData(item, source, itemPath)),
|
|
487
|
+
properties: validateTiledPropertiesArray(obj.properties, source, "properties")
|
|
488
|
+
};
|
|
489
|
+
};
|
|
538
490
|
/**
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
return validateTiledTilesetData(expectObject(raw, source, ''), source, '');
|
|
544
|
-
}
|
|
491
|
+
* Validates a standalone `.tsj` tileset file's root object.
|
|
492
|
+
* @internal
|
|
493
|
+
*/
|
|
494
|
+
const validateTiledTilesetFileData = (raw, source) => validateTiledTilesetData(expectObject(raw, source, ""), source, "");
|
|
545
495
|
|
|
496
|
+
//#endregion
|
|
546
497
|
export { TiledFormatError, checkTiledLayerInfiniteConsistency, validateTiledAnimationFrameData, validateTiledLayerData, validateTiledMapData, validateTiledObjectData, validateTiledPropertyData, validateTiledTileData, validateTiledTilesetData, validateTiledTilesetFileData, validateTiledTilesetRefData };
|
|
547
|
-
//# sourceMappingURL=validate.js.map
|
|
498
|
+
//# sourceMappingURL=validate.js.map
|