diff --git a/LCSEngine/Component.cpp b/LCSEngine/Component.cpp index 591b66b..1de5b71 100644 --- a/LCSEngine/Component.cpp +++ b/LCSEngine/Component.cpp @@ -34,7 +34,8 @@ void Component::disable() void Component::load(nlohmann::json& conf) { - + isEnable = conf.at("isEnable").get(); + isUnique = conf.at("isUnique").get(); } void Component::save(nlohmann::json& conf) diff --git a/LCSEngine/GameObject.cpp b/LCSEngine/GameObject.cpp index abe8c91..1f9f9b4 100644 --- a/LCSEngine/GameObject.cpp +++ b/LCSEngine/GameObject.cpp @@ -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 componentsJson = conf["components"]; + for (list::iterator it = componentsJson.begin(); it != componentsJson.end(); ++it) + { + switch ((*it).at("typeComponent").get()) + { + //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() diff --git a/LCSEngine/TransformComponent.cpp b/LCSEngine/TransformComponent.cpp index fef78a3..722391e 100644 --- a/LCSEngine/TransformComponent.cpp +++ b/LCSEngine/TransformComponent.cpp @@ -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); +} + diff --git a/LCSEngine/TransformComponent.h b/LCSEngine/TransformComponent.h index b854d95..e863d47 100644 --- a/LCSEngine/TransformComponent.h +++ b/LCSEngine/TransformComponent.h @@ -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 };