| 944 | } |
| 945 | |
| 946 | s32 parse_unit_internal(UnitCompiler &c |
| 947 | , const char *unit_json |
| 948 | , Unit *instance_unit |
| 949 | , Unit *parent_unit |
| 950 | , CompileOptions &opts |
| 951 | ) |
| 952 | { |
| 953 | TempAllocator4096 ta; |
| 954 | JsonObject obj(ta); |
| 955 | RETURN_IF_ERROR(sjson::parse(obj, unit_json)); |
| 956 | |
| 957 | Guid id = RETURN_IF_ERROR(sjson::parse_guid(obj["_guid"])); |
| 958 | |
| 959 | Unit *unit = instance_unit; |
| 960 | if (unit == NULL) { |
| 961 | unit = CE_NEW(default_allocator(), Unit)(default_allocator()); |
| 962 | } |
| 963 | |
| 964 | if (instance_unit == NULL) { |
| 965 | if (parent_unit == NULL) { |
| 966 | hash_map::set(c._units, id, unit); |
| 967 | } else { |
| 968 | unit->_parent = parent_unit; |
| 969 | hash_map::set(parent_unit->_children, id, unit); |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | if (json_object::has(obj, "prefab") |
| 974 | && sjson::type(obj["prefab"]) == JsonValueType::STRING) { |
| 975 | TempAllocator512 ta; |
| 976 | DynamicString prefab(ta); |
| 977 | RETURN_IF_ERROR(sjson::parse_string(prefab, obj["prefab"])); |
| 978 | const char *prefab_json_data = prefab_json(c, prefab.c_str()); |
| 979 | RETURN_IF_FALSE(UNIT_COMPILER, prefab_json_data != NULL |
| 980 | , opts |
| 981 | , "Unknown prefab: '%s'" |
| 982 | , prefab.c_str() |
| 983 | ); |
| 984 | |
| 985 | s32 err = parse_unit_internal(c |
| 986 | , prefab_json_data |
| 987 | , unit |
| 988 | , NULL |
| 989 | , opts |
| 990 | ); |
| 991 | ENSURE_OR_RETURN(UNIT_COMPILER, err == 0, opts); |
| 992 | } |
| 993 | |
| 994 | s32 err = modify_unit_components(unit, unit_json, opts); |
| 995 | ENSURE_OR_RETURN(UNIT_COMPILER, err == 0, opts); |
| 996 | |
| 997 | if (json_object::has(obj, "children")) { |
| 998 | JsonArray children(ta); |
| 999 | RETURN_IF_ERROR(sjson::parse_array(children, obj["children"])); |
| 1000 | |
| 1001 | for (u32 cc = 0; cc < array::size(children); ++cc) { |
| 1002 | s32 err = parse_unit_internal(c |
| 1003 | , children[cc] |
no test coverage detected