(w: WorldData)
| 22 | } |
| 23 | |
| 24 | export function validateWorld(w: WorldData): ValidationResult { |
| 25 | const errors: string[] = []; |
| 26 | |
| 27 | if (typeof w.schemaVersion !== 'number') { |
| 28 | errors.push('world.schemaVersion is missing or not a number'); |
| 29 | } else if (w.schemaVersion > WORLD_SCHEMA_VERSION) { |
| 30 | errors.push( |
| 31 | 'world.schemaVersion ' + w.schemaVersion + ' is newer than engine version ' + WORLD_SCHEMA_VERSION, |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | if (typeof w.name !== 'string' || w.name.length === 0) { |
| 36 | errors.push('world.name must be a non-empty string'); |
| 37 | } |
| 38 | if (typeof w.id !== 'string' || w.id.length === 0) { |
| 39 | errors.push('world.id must be a non-empty string'); |
| 40 | } |
| 41 | |
| 42 | checkVec3(errors, 'world.bounds.min', w.bounds ? w.bounds.min : null); |
| 43 | checkVec3(errors, 'world.bounds.max', w.bounds ? w.bounds.max : null); |
| 44 | |
| 45 | if (!w.environment) { |
| 46 | errors.push('world.environment is missing'); |
| 47 | } |
| 48 | |
| 49 | if (w.terrain !== null && w.terrain !== undefined) { |
| 50 | validateTerrain(errors, w.terrain); |
| 51 | } |
| 52 | |
| 53 | if (!Array.isArray(w.entities)) { |
| 54 | errors.push('world.entities must be an array'); |
| 55 | } else { |
| 56 | const seenIds = new Set<string>(); |
| 57 | for (let i = 0; i < w.entities.length; i++) { |
| 58 | validateEntity(errors, 'world.entities[' + i + ']', w.entities[i], seenIds); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | if (!Array.isArray(w.water)) { |
| 63 | errors.push('world.water must be an array'); |
| 64 | } |
| 65 | if (!Array.isArray(w.rivers)) { |
| 66 | errors.push('world.rivers must be an array'); |
| 67 | } |
| 68 | |
| 69 | return { ok: errors.length === 0, errors }; |
| 70 | } |
| 71 | |
| 72 | export function validatePrefab(p: PrefabData): ValidationResult { |
| 73 | const errors: string[] = []; |
no test coverage detected