(p: PrefabData)
| 70 | } |
| 71 | |
| 72 | export function validatePrefab(p: PrefabData): ValidationResult { |
| 73 | const errors: string[] = []; |
| 74 | |
| 75 | if (typeof p.schemaVersion !== 'number') { |
| 76 | errors.push('prefab.schemaVersion is missing or not a number'); |
| 77 | } else if (p.schemaVersion > WORLD_SCHEMA_VERSION) { |
| 78 | errors.push('prefab.schemaVersion ' + p.schemaVersion + ' is newer than engine'); |
| 79 | } |
| 80 | |
| 81 | if (typeof p.id !== 'string' || p.id.length === 0) { |
| 82 | errors.push('prefab.id must be a non-empty string'); |
| 83 | } |
| 84 | if (typeof p.name !== 'string') { |
| 85 | errors.push('prefab.name must be a string'); |
| 86 | } |
| 87 | |
| 88 | if (!Array.isArray(p.children)) { |
| 89 | errors.push('prefab.children must be an array'); |
| 90 | } else { |
| 91 | const seenIds = new Set<string>(); |
| 92 | for (let i = 0; i < p.children.length; i++) { |
| 93 | validatePrefabChild(errors, 'prefab.children[' + i + ']', p.children[i], seenIds); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return { ok: errors.length === 0, errors }; |
| 98 | } |
| 99 | |
| 100 | // ---- helpers --------------------------------------------------------------- |
| 101 |
no test coverage detected