MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / getLayerDict

Function getLayerDict

Source/Node/TileNode.cpp:577–727  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

575}
576
577static Dictionary* getLayerDict(tmx::Layer* target, const tmx::Map& map) {
578 Dictionary* data = Dictionary::create();
579 data->set("name"sv, Value::alloc(target->getName()));
580 data->set("class"sv, Value::alloc(target->getClass()));
581 data->set("opacity"sv, Value::alloc(target->getOpacity()));
582 data->set("visible"sv, Value::alloc(target->getVisible()));
583 {
584 auto tc = target->getTintColour();
585 data->set("tintColor"sv, Value::alloc(Color{tc.r, tc.g, tc.b, tc.a}.toARGB()));
586 }
587 data->set("size"sv, Value::alloc(Size{s_cast<float>(target->getSize().x), s_cast<float>(target->getSize().y)}));
588 data->set("offset"sv, Value::alloc(Vec2{s_cast<float>(target->getOffset().x), s_cast<float>(target->getOffset().y)}));
589 data->set("parallaxFactor"sv, Value::alloc(Vec2{s_cast<float>(target->getParallaxFactor().x), s_cast<float>(target->getParallaxFactor().y)}));
590 if (!target->getProperties().empty()) {
591 data->set("properties"sv, getProperties(target->getProperties(), map));
592 }
593 switch (target->getType()) {
594 case tmx::Layer::Type::Tile: {
595 data->set("type"sv, Value::alloc("Tile"sv));
596 const auto& layer = target->getLayerAs<tmx::TileLayer>();
597 if (map.isInfinite()) {
598 Array* chunks = Array::create();
599 for (const auto& c : layer.getChunks()) {
600 Dictionary* chunkData = Dictionary::create();
601 chunkData->set("size"sv, Value::alloc(Size{s_cast<float>(c.size.x), s_cast<float>(c.size.y)}));
602 chunkData->set("position"sv, Value::alloc(Size{s_cast<float>(c.position.x), s_cast<float>(c.position.y)}));
603 Array* tiles = Array::create(c.tiles.size());
604 for (const auto& t : c.tiles) {
605 tiles->add(Value::alloc(t.ID));
606 }
607 chunkData->set("tiles"sv, Value::alloc(tiles));
608 chunks->add(Value::alloc(chunkData));
609 }
610 data->set("chunks", Value::alloc(chunks));
611 } else {
612 Array* tiles = Array::create(layer.getTiles().size());
613 for (const auto& t : layer.getTiles()) {
614 tiles->add(Value::alloc(t.ID));
615 }
616 data->set("tiles", Value::alloc(tiles));
617 }
618 break;
619 }
620 case tmx::Layer::Type::Object: {
621 data->set("type"sv, Value::alloc("Object"sv));
622 const auto& layer = target->getLayerAs<tmx::ObjectGroup>();
623 switch (layer.getDrawOrder()) {
624 case tmx::ObjectGroup::DrawOrder::Index:
625 data->set("drawOrder", Value::alloc("Index"sv));
626 break;
627 case tmx::ObjectGroup::DrawOrder::TopDown:
628 data->set("drawOrder", Value::alloc("TopDown"sv));
629 break;
630 }
631 auto c = layer.getColour();
632 data->set("color"sv, Value::alloc(Color{c.r, c.g, c.b, c.a}.toARGB()));
633 Array* objects = Array::create(layer.getObjects().size());
634 for (const auto& object : layer.getObjects()) {

Callers 1

getLayerMethod · 0.85

Calls 15

getPropertiesFunction · 0.85
getClassMethod · 0.80
toARGBMethod · 0.80
setMethod · 0.65
getNameMethod · 0.65
addMethod · 0.65
getMethod · 0.65
createFunction · 0.50
allocFunction · 0.50
concatClass · 0.50
getOpacityMethod · 0.45
getVisibleMethod · 0.45

Tested by

no test coverage detected