MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / TMXObject

Method TMXObject

source/game/StarDungeonTMXPart.cpp:285–347  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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";

Callers

nothing calls this directly

Calls 15

jsonFromRectIFunction · 0.85
toStringFunction · 0.85
getUIntMethod · 0.80
toArrayMethod · 0.80
getStringMethod · 0.80
toObjectMethod · 0.80
inheritMethod · 0.80
isValidMethod · 0.80
xMethod · 0.80
yMethod · 0.80
optFloatMethod · 0.80
optArrayMethod · 0.80

Tested by

no test coverage detected