| 1073 | s32 flatten(UnitCompiler &c, CompileOptions &opts); |
| 1074 | |
| 1075 | s32 assign_unit_indices(UnitCompiler &c, Unit *unit, u32 parent_unit_index, CompileOptions &opts) |
| 1076 | { |
| 1077 | const u32 unit_index = c._num_units; |
| 1078 | const u32 root_unit_index = parent_unit_index == UINT32_MAX |
| 1079 | ? unit_index |
| 1080 | : c._unit_roots[parent_unit_index] |
| 1081 | ; |
| 1082 | unit->_index = unit_index; |
| 1083 | array::push_back(c._unit_parents, parent_unit_index); |
| 1084 | array::push_back(c._unit_roots, root_unit_index); |
| 1085 | array::push_back(c._unit_names, unit->_editor_name); |
| 1086 | ++c._num_units; |
| 1087 | |
| 1088 | for (u32 cc = 0; cc < array::size(unit->_merged_components); ++cc) { |
| 1089 | TempAllocator512 ta; |
| 1090 | JsonObject component(ta); |
| 1091 | RETURN_IF_ERROR(sjson::parse(component, unit->_merged_components[cc])); |
| 1092 | |
| 1093 | Guid component_id; |
| 1094 | if (json_object::has(component, "id")) { |
| 1095 | component_id = RETURN_IF_ERROR(sjson::parse_guid(component["id"])); |
| 1096 | } else { |
| 1097 | component_id = RETURN_IF_ERROR(sjson::parse_guid(component["_guid"])); |
| 1098 | } |
| 1099 | |
| 1100 | StringId32 comp_type; |
| 1101 | if (!json_object::has(component, "_type")) { |
| 1102 | comp_type = RETURN_IF_ERROR(sjson::parse_string_id(component["type"])); |
| 1103 | } else { |
| 1104 | comp_type = RETURN_IF_ERROR(sjson::parse_string_id(component["_type"])); |
| 1105 | } |
| 1106 | |
| 1107 | const ComponentKey key = { component_id, root_unit_index }; |
| 1108 | hash_map::set(c._component_unit_index, key, unit_index); |
| 1109 | hash_map::set(c._component_type, key, comp_type); |
| 1110 | } |
| 1111 | |
| 1112 | auto cur = hash_map::begin(unit->_children); |
| 1113 | auto end = hash_map::end(unit->_children); |
| 1114 | for (; cur != end; ++cur) { |
| 1115 | HASH_MAP_SKIP_HOLE(unit->_children, cur); |
| 1116 | |
| 1117 | s32 err = assign_unit_indices(c, cur->second, unit_index, opts); |
| 1118 | ENSURE_OR_RETURN(UNIT_COMPILER, err == 0, opts); |
| 1119 | } |
| 1120 | |
| 1121 | return 0; |
| 1122 | } |
| 1123 | |
| 1124 | s32 parse_unit_from_json(UnitCompiler &c, const char *unit_json, CompileOptions &opts) |
| 1125 | { |
no test coverage detected