当前位置: 首页>>代码示例>>C++>>正文


C++ Trigger::ImportFromJson方法代码示例

本文整理汇总了C++中Trigger::ImportFromJson方法的典型用法代码示例。如果您正苦于以下问题:C++ Trigger::ImportFromJson方法的具体用法?C++ Trigger::ImportFromJson怎么用?C++ Trigger::ImportFromJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Trigger的用法示例。


在下文中一共展示了Trigger::ImportFromJson方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

bool	EntityType::ImportFromJson(
		std::istream&	FileStream)
{
//	If it isn't a valid file stream, interrupt operation.
	rapidjson::Document	ConfigData;
	rapidjson::Value	WorkVal;
	std::string			StringStream, StringRead;
	while (getline(FileStream, StringRead))
		StringStream += StringRead;
	ConfigData.Parse(StringStream.c_str());
	if (!ConfigData.IsObject())
		return false;
//	Importing general properties
	ImportJsonData(Properties.Name, ConfigData["Properties"]["Name"]);
	ImportJsonData(Properties.Type, ConfigData["Properties"]["Type"]);
	Properties.Description = Properties.Name;
	ImportJsonData(Properties.Description, ConfigData["Properties"]["Description"]);
	ImportJsonData(Properties.ShowInCreative, ConfigData["Properties"]["ShowInCreative"]);
	ImportJsonData(Physics.PhysicsEnabled, ConfigData["Physics"]["PhysicsEnabled"]);
	ImportJsonData(Physics.CollisionEnabled, ConfigData["Physics"]["CollisionEnabled"]);
	ImportJsonData(Physics.LengthX, ConfigData["Physics"]["LengthX"]);
	ImportJsonData(Physics.LengthY, ConfigData["Physics"]["LengthY"]);
	ImportJsonData(Physics.Mass, ConfigData["Physics"]["Mass"]);
//	Friction factor, in all 4 faces
	ImportJsonData(Physics.FrictionFactor[2], ConfigData["Physics"]["FrictionFactorTop"]);
	Physics.FrictionFactor[3] = Physics.FrictionFactor[1] = Physics.FrictionFactor[0] = Physics.FrictionFactor[2];
	ImportJsonData(Physics.FrictionFactor[0], ConfigData["Physics"]["FrictionFactorLeft"]);
	ImportJsonData(Physics.FrictionFactor[1], ConfigData["Physics"]["FrictionFactorRight"]);
	ImportJsonData(Physics.FrictionFactor[3], ConfigData["Physics"]["FrictionFactorBottom"]);
//	Elasticity factor, in all 4 faces.
	ImportJsonData(Physics.ElasticFactor[2], ConfigData["Physics"]["ElasticFactorTop"]);
	Physics.ElasticFactor[3] = Physics.ElasticFactor[1] = Physics.ElasticFactor[0] = Physics.ElasticFactor[2];
	ImportJsonData(Physics.ElasticFactor[0], ConfigData["Physics"]["ElasticFactorLeft"]);
	ImportJsonData(Physics.ElasticFactor[1], ConfigData["Physics"]["ElasticFactorRight"]);
	ImportJsonData(Physics.ElasticFactor[3], ConfigData["Physics"]["ElasticFactorBottom"]);
//	Miscellaneous properties.
	ImportJsonData(Physics.BlastResistance, ConfigData["Physics"]["BlastResistance"]);
	ImportJsonData(Physics.CollisionIgnoreName, ConfigData["Physics"]["CollisionIgnore"]);
//	Importing general yet self-defined importing procedure properties
//	Entity class specific properties
	if (Properties.Type == "Player") {
		PlayerEntityType*	SubData = new PlayerEntityType;
		ImportJsonData(SubData->MoveSpeed, ConfigData["Properties"]["SpecificProperties"]["MoveSpeed"]);
		ImportJsonData(SubData->JumpSpeed, ConfigData["Properties"]["SpecificProperties"]["JumpSpeed"]);
		ImportJsonData(SubData->MaxLife, ConfigData["Properties"]["SpecificProperties"]["MaxLife"]);
		Properties.SpecificProperties = (void*)SubData;
	} else if (Properties.Type == "Projectile") {
		ProjectileEntityType*	SubData = new ProjectileEntityType;
		ImportJsonData(SubData->LaunchSpeed, ConfigData["Properties"]["SpecificProperties"]["LaunchSpeed"]);
		ImportJsonData(SubData->LaunchInterval, ConfigData["Properties"]["SpecificProperties"]["LaunchInterval"]);
		ImportJsonData(SubData->DeployDelay, ConfigData["Properties"]["SpecificProperties"]["DeployDelay"]);
		ImportJsonData(SubData->DeployRadius, ConfigData["Properties"]["SpecificProperties"]["DeployRadius"]);
		ImportJsonData(SubData->DeployPowerDamage, ConfigData["Properties"]["SpecificProperties"]["DeployPowerDamage"]);
		ImportJsonData(SubData->DeployPowerMotion, ConfigData["Properties"]["SpecificProperties"]["DeployPowerMotion"]);
		ImportJsonData(SubData->DeployPowerBlast, ConfigData["Properties"]["SpecificProperties"]["DeployPowerBlast"]);
		Properties.SpecificProperties = (void*)SubData;
	} else if (Properties.Type == "Particle") {
		ParticleEntityType*	SubData = new ParticleEntityType;
		ImportJsonData(SubData->LifeTime, ConfigData["Properties"]["SpecificProperties"]["LifeTime"]);
		Properties.SpecificProperties = (void*)SubData;
	}
//	Import textures list of PNGs and certain graphics properties.
	if (!ConfigData["Graphics"].IsArray())
		return false;
	for (int Indexer = 0; Indexer < (int)ConfigData["Graphics"].Size(); Indexer++) {
		typeGraphics	nGraphics;
		ImportJsonData(nGraphics.RenderEnabled, ConfigData["Graphics"][Indexer]["RenderEnabled"]);
		ImportJsonData(nGraphics.TexRotation, ConfigData["Graphics"][Indexer]["TexRotation"]);
		ImportJsonData(nGraphics.AnimationInterval, ConfigData["Graphics"][Indexer]["AnimationInterval"]);
		ImportJsonData(nGraphics.Luminosity, ConfigData["Graphics"][Indexer]["Luminosity"]);
		ImportJsonData(nGraphics.LengthX, ConfigData["Graphics"][Indexer]["LengthX"]);
		ImportJsonData(nGraphics.LengthY, ConfigData["Graphics"][Indexer]["LengthY"]);
		if (ConfigData["Graphics"][Indexer]["TextureList"].IsArray()) {
			std::vector<std::string> TexturePath;
			ImportJsonData(TexturePath, ConfigData["Graphics"][Indexer]["TextureList"]);
			for (auto i = TexturePath.begin(); i != TexturePath.end(); i++) {
				GLuint		Texture;
				std::string	Path = CurrentTextureDirectory + (*i);
				Texture = LoadPNGTexture(Path.c_str(), NULL, NULL);
				nGraphics.TextureList.push_back(Texture);
			}
		}
		if (ConfigData["Graphics"][Indexer]["TextureOnHand"].IsString()) {
			std::string	OnHandTex;
			std::string	Path;
			ImportJsonData(OnHandTex, ConfigData["Graphics"][Indexer]["TextureOnHand"]);
			Path = CurrentTextureDirectory + OnHandTex;
			nGraphics.TextureOnHand = LoadPNGTexture(Path.c_str(), NULL, NULL);
		} else if (nGraphics.TextureList.size() > 0){
			nGraphics.TextureOnHand = nGraphics.TextureList[0];
		}
		Graphics.push_back(nGraphics);
	}
//	Import trigger operators from JSON
	if (ConfigData["Physics"]["TriggerList"].IsArray()) {
		for (unsigned int i = 0; i < ConfigData["Physics"]["TriggerList"].Size(); i++) {
			Trigger*	Worker = new Trigger;
			if (!ConfigData["Physics"]["TriggerList"][i].IsObject())
				continue;
			if (!Worker->ImportFromJson(ConfigData["Physics"]["TriggerList"][i]))
//.........这里部分代码省略.........
开发者ID:ht35268,项目名称:exponential-chaos,代码行数:101,代码来源:entitytype.cpp


注:本文中的Trigger::ImportFromJson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。