Пример #1
0
 /**
  * Stringify the data.
  * @return the content of asset.
  */
 std::string toString() const override {
   return detail::PrettyStringBuilder()
       .init("Asset")
       .append("assetId", assetId())
       .append("domainId", domainId())
       .append("precision", std::to_string(precision()))
       .finalize();
 }
/**
 * @given fields for AccountAsset object
 * @when AccountAssetBuilder is invoked twice with the same configuration
 * @then Two constructed AccountAsset objects are identical
 */
TEST(ProtoAccountAssetBuilderTest, SeveralObjectsFromOneBuilder) {
  shared_model::proto::AccountAssetBuilder builder;

  auto expected_account_id = "account@name";
  auto expected_asset_id = "asset#coin";
  auto expected_balance =
      shared_model::proto::AmountBuilder().intValue(100).precision(2).build();

  auto state = builder.accountId(expected_account_id)
                   .assetId(expected_asset_id)
                   .balance(expected_balance);

  auto account_asset = state.build();
  auto account_asset2 = state.build();

  EXPECT_EQ(account_asset.accountId(), account_asset2.accountId());
  EXPECT_EQ(account_asset.assetId(), account_asset2.assetId());
  EXPECT_EQ(account_asset.balance(), account_asset2.balance());
}
/**
 * @given fields for AccountAsset object
 * @when AccountAssetBuilder is invoked
 * @then AccountAsset object is successfully constructed and has the same fields
 * as provided
 */
TEST(ProtoAccountAssetBuilder, AllFieldsBuild) {
  shared_model::proto::AccountAssetBuilder builder;

  auto expected_account_id = "account@name";
  auto expected_asset_id = "asset#coin";
  auto expected_balance =
      shared_model::proto::AmountBuilder().intValue(100).precision(2).build();

  auto account_asset = builder.accountId(expected_account_id)
                           .assetId(expected_asset_id)
                           .balance(expected_balance)
                           .build();

  EXPECT_EQ(account_asset.accountId(), expected_account_id);
  EXPECT_EQ(account_asset.assetId(), expected_asset_id);
  EXPECT_EQ(account_asset.balance(), expected_balance);
}
Пример #4
0
 bool GetAssetInfo::operator==(const ModelType &rhs) const {
   return assetId() == rhs.assetId();
 }
Пример #5
0
 std::string GetAssetInfo::toString() const {
   return detail::PrettyStringBuilder()
       .init("GetAssetInfo")
       .append("asset_id", assetId())
       .finalize();
 }
Пример #6
0
 /**
  * Checks equality of objects inside
  * @param rhs - other wrapped value
  * @return true, if wrapped objects are same
  */
 bool operator==(const ModelType &rhs) const override {
   return assetId() == rhs.assetId() and domainId() == rhs.domainId()
       and precision() == rhs.precision();
 }
Пример #7
0
void myLevelSystem::ProcessEntity(const tinyxml2::XMLNode* EntityNode) {
	const tinyxml2::XMLElement* entityElement = EntityNode->ToElement();
	std::string entityId;
	float posx;
	float posy;
	float rot;
	float scaleX;
	float scaleY;
	bool canAdd = true;

	do {
		if (entityElement->Attribute("id") == NULL) {
			break;
		}
		if (entityElement->Attribute("x") == NULL) {
			break;
		}
		if (entityElement->Attribute("y") == NULL) {
			break;
		}
		if (entityElement->Attribute("rot") == NULL) {
			break;
		}
		if (entityElement->Attribute("scalex") == NULL) {
			break;
		}
		if (entityElement->Attribute("scaley") == NULL) {
			break;
		}

		entityId = std::string((entityElement->Attribute("id")));
		posx = myMath::PixelsToMeters((float) atof(entityElement->Attribute("x")));
		posy = myMath::PixelsToMeters((float) atof(entityElement->Attribute("y")));
		rot = (float) atof(entityElement->Attribute("rot"));
		rot = myMath::DegreesToRadians(rot);
		scaleX = (float) atof(entityElement->Attribute("scalex"));
		scaleY = (float) atof(entityElement->Attribute("scaley"));

		std::shared_ptr<myEntity> entity(new myEntity(entityId, posx, posy, rot, scaleX, scaleY));

		// Process Components
		for (const tinyxml2::XMLNode* componentNode = EntityNode->FirstChild(); componentNode; componentNode = componentNode->NextSibling()) {
			const tinyxml2::XMLElement* componentElement = componentNode->ToElement();
			if (strcmp(componentElement->Name(), "Component") == 0) {
				std::string componentId;
				int type;
				bool enabled;

				do {
					if (componentElement->Attribute("id") == NULL) {
						break;
					}
					if (componentElement->Attribute("type") == NULL) {
						break;
					}
					if (componentElement->Attribute("enabled") == NULL) {
						break;
					}

					componentId = std::string(componentElement->Attribute("id"));
					type = atoi(componentElement->Attribute("type"));
					enabled = (atoi(componentElement->Attribute("enabled")) != 0);

					switch (type) {
						case myComponent::RENDER: {
							const tinyxml2::XMLElement* assetElement = componentNode->FirstChild()->ToElement();
							std::string assetId(assetElement->Attribute("asset"));
							std::shared_ptr<myAsset> asset = GetAsset(assetId);
							switch (asset->type) {
								case myAsset::SPRITE: {
									myDebug::Log(myDebug::LOG_INFO, "Loaded:\n%s", asset->ToString().c_str());
									std::shared_ptr<myRenderComponent> component(new myRenderComponent(componentId, std::static_pointer_cast < mySprite > (asset), enabled));
									entity->AddComponent(component);
								}
									break;
								case myAsset::SPRITE_SHEET: {
									myDebug::Log(myDebug::LOG_INFO, "Loaded:\n%s", asset->ToString().c_str());
									std::shared_ptr<myRenderComponent> component(new myRenderComponent(componentId, std::static_pointer_cast < mySpriteSheet > (asset), enabled));
									entity->AddComponent(component);
								}
									break;
							}

						}
							break;
						case myComponent::AUDIO:
							break;
						case myComponent::PHYSICS: {
							const tinyxml2::XMLElement* physicsElement = componentNode->FirstChild()->ToElement();
							unsigned int bodyType = atoi(physicsElement->Attribute("type"));
							float density = (float) atof(physicsElement->Attribute("density"));
							float friction = (float) atof(physicsElement->Attribute("friction"));
							float restitution = (float) atof(physicsElement->Attribute("restitution"));
							float gravityScale = (float) atof(physicsElement->Attribute("gravityScale"));
							bool allowSleep = (atoi(physicsElement->Attribute("allowSleep")) != 0);
							std::shared_ptr<myPhysicsComponent> component(new myPhysicsComponent(componentId, bodyType, enabled));
							component->density = density;
							component->friction = friction;
							component->restitution = restitution;
							component->gravityScale = gravityScale;
							component->allowSleep = allowSleep;
							entity->AddComponent(component);
						}
							break;
						case myComponent::INPUT: {
							const tinyxml2::XMLElement* inputElement = componentNode->FirstChild()->ToElement();
							std::shared_ptr<myInputComponent> component(new myInputComponent(componentId, enabled));
							entity->AddComponent(component);
						}
							break;
						case myComponent::SCRIPT: {
							const tinyxml2::XMLElement* scriptElement = componentNode->FirstChild()->ToElement();
							std::string filename(scriptElement->Attribute("filename"));
							std::shared_ptr<myScriptComponent> component(new myScriptComponent(componentId, filename, enabled));
							entity->AddComponent(component);
						}
					}
					/*if (component) {
					 entity->AddComponent(component);
					 Debug::Log(Debug::LOG_INFO, "Added Component To: %s\n%s", entity->GetId().c_str(), component->ToString().c_str());
					 }*/
				}
				while (0);
			}
		} // process components

		for (auto sharedEntity : _sharedEntities) {
			if (strcmp(entity->GetId().c_str(), sharedEntity->GetId().c_str()) == 0) {
				canAdd = false;
			}
		}

		if (canAdd) {
			myDebug::Log(myDebug::LOG_INFO, "Loaded:\n%s", entity->ToString().c_str());
			_sharedEntities.push_back(entity);
		}
		else {
			myDebug::Log(myDebug::LOG_INFO, "Could Not Load:\n%s", entity->ToString().c_str());
		}
	}
	while (0);
}