| 283 | } |
| 284 | |
| 285 | TMXObject::TMXObject(Maybe<Json> const& groupProperties, Json const& tmx, TMXTilesetsPtr tilesets) { |
| 286 | m_objectId = tmx.getUInt("id"); |
| 287 | |
| 288 | // convert object properties in array format to object format |
| 289 | Maybe<Json> objectProperties = tmx.opt("properties").apply([](Json const& properties) -> Json { |
| 290 | if (properties.type() == Json::Type::Array) { |
| 291 | JsonObject objectProperties; |
| 292 | for (auto& p : properties.toArray()) |
| 293 | objectProperties.set(p.getString("name"), p.get("value")); |
| 294 | return objectProperties; |
| 295 | } else { |
| 296 | return properties.toObject(); |
| 297 | } |
| 298 | }); |
| 299 | |
| 300 | m_layer = getLayer(groupProperties, objectProperties); |
| 301 | |
| 302 | Maybe<TileObjectInfo> tileObjectInfo = getTileObjectInfo(tmx, tilesets, m_layer); |
| 303 | |
| 304 | // Merge properties in this order: |
| 305 | // Object |
| 306 | // Tile (and tileset by proxy) |
| 307 | // ObjectGroup |
| 308 | Tiled::Properties properties; |
| 309 | if (objectProperties) |
| 310 | properties = properties.inherit(*objectProperties); |
| 311 | if (tileObjectInfo.isValid()) |
| 312 | properties = properties.inherit(tileObjectInfo->tileProperties); |
| 313 | if (groupProperties.isValid()) |
| 314 | properties = properties.inherit(*groupProperties); |
| 315 | |
| 316 | // Check whether the object was flipped horizontally before creating this |
| 317 | // object's Tile |
| 318 | bool flipX = tileObjectInfo.isValid() && (tileObjectInfo->flipBits & TileFlip::Horizontal) != 0; |
| 319 | |
| 320 | m_kind = getObjectKind(tmx, objectProperties); |
| 321 | |
| 322 | Vec2I pos = getPos(tmx) - getImagePosition(properties); |
| 323 | Vec2I size = getSize(tmx); |
| 324 | m_rect = RectI(pos, Vec2I(pos.x() + size.x(), pos.y() + size.y())); |
| 325 | |
| 326 | JsonObject computedProperties; |
| 327 | if (m_kind == ObjectKind::Stagehand) { |
| 328 | Vec2I cPos = rect().center(); |
| 329 | RectI broadcastArea(rect().min() - cPos, rect().max() - cPos); |
| 330 | computedProperties["broadcastArea"] = jsonFromRectI(broadcastArea).repr(); |
| 331 | } |
| 332 | |
| 333 | Maybe<float> rotation = tmx.optFloat("rotation"); |
| 334 | if (rotation.isValid() && *rotation != 0.0f) |
| 335 | throw tmxObjectError(tmx, "object is rotated, which is not supported"); |
| 336 | |
| 337 | Maybe<JsonArray> polyline = tmx.optArray("polyline"); |
| 338 | if (polyline.isValid()) { |
| 339 | for (Json const& point : *polyline) |
| 340 | m_polyline.append(getPos(point)); |
| 341 | computedProperties["wire"] = "_polylineWire" + toString(m_objectId); |
| 342 | computedProperties["local"] = "true"; |
nothing calls this directly
no test coverage detected