Skip to content

Commit

Permalink
Load TransformComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos2380 committed Mar 20, 2018
1 parent 2cf9a9d commit 0723a6b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
3 changes: 2 additions & 1 deletion LCSEngine/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ void Component::disable()

void Component::load(nlohmann::json& conf)
{

isEnable = conf.at("isEnable").get<bool>();
isUnique = conf.at("isUnique").get<bool>();
}

void Component::save(nlohmann::json& conf)
Expand Down
52 changes: 52 additions & 0 deletions LCSEngine/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,58 @@ void GameObject::load(nlohmann::json& conf) {
SaveLoadManager::convertMyJSONtoFloat4x4(conf["idBone"], idBone);
SaveLoadManager::convertMyJSONtoFloat3(conf["aabbMax"], aabb.maxPoint);
SaveLoadManager::convertMyJSONtoFloat3(conf["aabbMin"], aabb.minPoint);

list<nlohmann::json> componentsJson = conf["components"];
for (list<nlohmann::json>::iterator it = componentsJson.begin(); it != componentsJson.end(); ++it)
{
switch ((*it).at("typeComponent").get<int>())
{
//Se lo que piensas... mira al final del switch...
case TRANSFORM:
{
TransformComponent transformComp(this);
transformComp.typeComponent = TRANSFORM;
transformComp.load(*it);
}
break;
case MATERIAL:
{
MaterialComponent materialComp(this);
materialComp.typeComponent = MATERIAL;
materialComp.load(*it);
}
break;
case MESH:
{
MeshComponent meshComp(this);
meshComp.typeComponent = MESH;
meshComp.load(*it);
}
break;
case ANIMATION:
{
AnimationComponent animationComp(this);
animationComp.typeComponent = ANIMATION;
animationComp.load(*it);
}
break;
case AUDIOLISTENER:
{
AudioListenerComponent audioListenerComp(this);
audioListenerComp.typeComponent = AUDIOLISTENER;
audioListenerComp.load(*it);
}
break;
case AUDIOSOURCE:
{
AudioSourceComponent audioSourceComp(this);
audioSourceComp.typeComponent = AUDIOSOURCE;
audioSourceComp.load(*it);
}
break;
//Las llaves del case si tienes huevos las quitas ¬¬
}
}
}

void GameObject::drawComponentsElementsGui()
Expand Down
13 changes: 13 additions & 0 deletions LCSEngine/TransformComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,16 @@ void TransformComponent::save(nlohmann::json& conf)
SaveLoadManager::convertFloat4x4ToMyJSON(matrixRotate, customJsont);
conf["matrixRotate"] = customJsont;
}

void TransformComponent::load(nlohmann::json& conf)
{
Component::load(conf);
SaveLoadManager::convertMyJSONtoFloat3(conf["position"], position);
SaveLoadManager::convertMyJSONtoFloat3(conf["scale"], scale);
SaveLoadManager::convertMyJSONtoFloat3(conf["rotation"], position);
SaveLoadManager::convertMyJSONtoFloat4x4(conf["transform"], transform);
SaveLoadManager::convertMyJSONtoFloat4x4(conf["matrixTranslate"], matrixTranslate);
SaveLoadManager::convertMyJSONtoFloat4x4(conf["matrixScale"], matrixScale);
SaveLoadManager::convertMyJSONtoFloat4x4(conf["matrixRotate"], matrixRotate);
}

1 change: 1 addition & 0 deletions LCSEngine/TransformComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TransformComponent : public Component
float3 up();
float3 front();
virtual void save(nlohmann::json& conf);
virtual void load(nlohmann::json& conf);

public:
float3 position = { 0.0f, 0.0f, 0.0f };
Expand Down

0 comments on commit 0723a6b

Please sign in to comment.