| 27 | namespace level_resource_internal |
| 28 | { |
| 29 | s32 compile(CompileOptions &opts) |
| 30 | { |
| 31 | Buffer buf = opts.read(); |
| 32 | TempAllocator4096 ta; |
| 33 | JsonObject obj(ta); |
| 34 | RETURN_IF_ERROR(sjson::parse(obj, buf)); |
| 35 | |
| 36 | Array<LevelSound> sounds(default_allocator()); |
| 37 | if (json_object::has(obj, "sounds")) { |
| 38 | JsonArray sounds_json(ta); |
| 39 | RETURN_IF_ERROR(sjson::parse_array(sounds_json, obj["sounds"])); |
| 40 | |
| 41 | for (u32 i = 0; i < array::size(sounds_json); ++i) { |
| 42 | JsonObject sound(ta); |
| 43 | RETURN_IF_ERROR(sjson::parse_object(sound, sounds_json[i])); |
| 44 | |
| 45 | DynamicString sound_name(ta); |
| 46 | RETURN_IF_ERROR(sjson::parse_string(sound_name, sound["name"])); |
| 47 | WARN_IF_MISSING(LEVEL_RESOURCE, "sound" |
| 48 | , sound_name.c_str() |
| 49 | , opts |
| 50 | ); |
| 51 | opts.add_requirement("sound", sound_name.c_str()); |
| 52 | |
| 53 | LevelSound ls; |
| 54 | ls.name = RETURN_IF_ERROR(sjson::parse_resource_name(sound["name"])); |
| 55 | ls.position = RETURN_IF_ERROR(sjson::parse_vector3 (sound["position"])); |
| 56 | ls.volume = RETURN_IF_ERROR(sjson::parse_float (sound["volume"])); |
| 57 | ls.range = RETURN_IF_ERROR(sjson::parse_float (sound["range"])); |
| 58 | ls.loop = RETURN_IF_ERROR(sjson::parse_bool (sound["loop"])); |
| 59 | ls.group = StringId32(0u); |
| 60 | if (json_object::has(sound, "group")) { |
| 61 | ls.group = RETURN_IF_ERROR(sjson::parse_string_id(sound["group"])); |
| 62 | } |
| 63 | |
| 64 | array::push_back(sounds, ls); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | UnitCompiler uc(default_allocator()); |
| 69 | |
| 70 | if (json_object::has(obj, "units")) { |
| 71 | s32 err = unit_compiler::parse_unit_array_from_json(uc, obj["units"], opts); |
| 72 | ENSURE_OR_RETURN(LEVEL_RESOURCE, err == 0, opts); |
| 73 | } |
| 74 | |
| 75 | Buffer units_blob(default_allocator()); |
| 76 | s32 err = unit_compiler::blob(units_blob, uc); |
| 77 | ENSURE_OR_RETURN(LEVEL_RESOURCE, err == 0, opts); |
| 78 | |
| 79 | StringId64 skydome_unit; |
| 80 | if (json_object::has(obj, "skydome_unit")) { |
| 81 | TempAllocator256 ta; |
| 82 | DynamicString skydome_unit_name(ta); |
| 83 | |
| 84 | RETURN_IF_ERROR(sjson::parse_string(skydome_unit_name, obj["skydome_unit"])); |
| 85 | WARN_IF_MISSING(LEVEL_RESOURCE, "unit" |
| 86 | , skydome_unit_name.c_str() |
nothing calls this directly
no test coverage detected