|
5 | 5 |
|
6 | 6 | using namespace ldtk; |
7 | 7 |
|
| 8 | +std::vector<EntityRef*> FieldsContainer::tmp_entity_refs_vector; |
| 9 | + |
8 | 10 | FieldsContainer::FieldsContainer(const nlohmann::json& j, const World* w) { |
9 | 11 | parseFields(j, w); |
10 | 12 | } |
@@ -100,16 +102,24 @@ void FieldsContainer::parseFields(const nlohmann::json& j, const World* w) { |
100 | 102 | } |
101 | 103 | else if (field_type == "Array<EntityRef>") { |
102 | 104 | std::vector<Field<EntityRef>> values; |
| 105 | + values.reserve(field_value.size()); |
103 | 106 | for (const auto& v : field_value) { |
104 | | - if (v.is_null()) |
| 107 | + if (v.is_null()) { |
105 | 108 | values.emplace_back(null); |
106 | | - else |
| 109 | + } |
| 110 | + else { |
107 | 111 | values.emplace_back(EntityRef{ |
108 | 112 | IID(v["entityIid"].get<std::string>()), IID(v["layerIid"].get<std::string>()), |
109 | 113 | IID(v["levelIid"].get<std::string>()), IID(v["worldIid"].get<std::string>()) |
110 | 114 | }); |
| 115 | + } |
111 | 116 | } |
112 | 117 | addArrayField(field_name, values); |
| 118 | + auto& this_field = *dynamic_cast<ArrayField<EntityRef>*>(m_array_fields.at(field_name)); |
| 119 | + for (auto& ent_ref : this_field) { |
| 120 | + tmp_entity_refs_vector.emplace_back(&ent_ref.value()); |
| 121 | + } |
| 122 | + |
113 | 123 | } |
114 | 124 | } |
115 | 125 | // simple fields |
@@ -163,13 +173,17 @@ void FieldsContainer::parseFields(const nlohmann::json& j, const World* w) { |
163 | 173 | addField<FilePath>(field_name, field_value.get<std::string>()); |
164 | 174 | } |
165 | 175 | else if (field_type == "EntityRef") { |
166 | | - if (field_value.is_null()) |
| 176 | + if (field_value.is_null()) { |
167 | 177 | addField<EntityRef>(field_name, null); |
168 | | - else |
| 178 | + } |
| 179 | + else { |
169 | 180 | addField<EntityRef>(field_name, {IID(field_value["entityIid"].get<std::string>()), |
170 | 181 | IID(field_value["layerIid"].get<std::string>()), |
171 | 182 | IID(field_value["levelIid"].get<std::string>()), |
172 | 183 | IID(field_value["worldIid"].get<std::string>())}); |
| 184 | + auto& this_field = *dynamic_cast<Field<EntityRef>*>(m_fields.at(field_name)); |
| 185 | + tmp_entity_refs_vector.emplace_back(&this_field.value()); |
| 186 | + } |
173 | 187 | } |
174 | 188 | } |
175 | 189 | } |
0 commit comments