@@ -151,22 +151,6 @@ namespace Hazel {
151151 // Serialize components (except IDComponent)
152152 SerializeAllEntityComponents (out,entity);
153153
154- if (entity.HasComponent <CircleCollider2DComponent>())
155- {
156- out << YAML ::Key << " CircleCollider2DComponent" ;
157- out << YAML ::BeginMap; // CircleCollider2DComponent
158-
159- auto & cc2dComponent = entity.GetComponent <CircleCollider2DComponent>();
160- out << YAML ::Key << " Offset" << YAML ::Value << cc2dComponent.Offset ;
161- out << YAML ::Key << " Radius" << YAML ::Value << cc2dComponent.Radius ;
162- out << YAML ::Key << " Density" << YAML ::Value << cc2dComponent.Density ;
163- out << YAML ::Key << " Friction" << YAML ::Value << cc2dComponent.Friction ;
164- out << YAML ::Key << " Restitution" << YAML ::Value << cc2dComponent.Restitution ;
165- out << YAML ::Key << " RestitutionThreshold" << YAML ::Value << cc2dComponent.RestitutionThreshold ;
166-
167- out << YAML ::EndMap; // CircleCollider2DComponent
168- }
169-
170154 out << YAML ::EndMap; // Entity
171155 }
172156
@@ -362,6 +346,10 @@ namespace Hazel {
362346 out << YAML ::BeginMap; // SpriteRendererComponent
363347
364348 auto & spriteRendererComponent = entity.GetComponent <SpriteRendererComponent>();
349+ if (spriteRendererComponent.Texture && std::filesystem::exists (spriteRendererComponent.Texture ->GetPath ()))
350+ {
351+ out << YAML ::Key << " TexturePath" << YAML ::Value << spriteRendererComponent.Texture ->GetPath ();
352+ }
365353 out << YAML ::Key << " Color" << YAML ::Value << spriteRendererComponent.Color ;
366354 out << YAML ::Key << " TilingFactor" << YAML ::Value << spriteRendererComponent.TilingFactor ;
367355
@@ -376,6 +364,8 @@ namespace Hazel {
376364 if (spriteRendererComponent)
377365 {
378366 auto & src = deserializedEntity.AddComponent <SpriteRendererComponent>();
367+ if (spriteRendererComponent[" TexturePath" ])
368+ src.Texture = Texture2D::Create (spriteRendererComponent[" TexturePath" ].as <std::string>());
379369 src.Color = spriteRendererComponent[" Color" ].as <glm::vec4>();
380370 if (spriteRendererComponent[" TilingFactor" ])
381371 src.TilingFactor = spriteRendererComponent[" TilingFactor" ].as <float >();
@@ -473,6 +463,42 @@ namespace Hazel {
473463 bc2d.RestitutionThreshold = boxCollider2DComponent[" RestitutionThreshold" ].as <float >();
474464 }
475465 }
466+ template <>
467+ static void SerializeEntityComponent<CircleCollider2DComponent>(YAML ::Emitter& out, Entity entity)
468+ {
469+
470+ if (entity.HasComponent <CircleCollider2DComponent>())
471+ {
472+ out << YAML ::Key << " CircleCollider2DComponent" ;
473+ out << YAML ::BeginMap; // CircleCollider2DComponent
474+
475+ auto & cc2dComponent = entity.GetComponent <CircleCollider2DComponent>();
476+ out << YAML ::Key << " Offset" << YAML ::Value << cc2dComponent.Offset ;
477+ out << YAML ::Key << " Radius" << YAML ::Value << cc2dComponent.Radius ;
478+ out << YAML ::Key << " Density" << YAML ::Value << cc2dComponent.Density ;
479+ out << YAML ::Key << " Friction" << YAML ::Value << cc2dComponent.Friction ;
480+ out << YAML ::Key << " Restitution" << YAML ::Value << cc2dComponent.Restitution ;
481+ out << YAML ::Key << " RestitutionThreshold" << YAML ::Value << cc2dComponent.RestitutionThreshold ;
482+
483+ out << YAML ::EndMap; // CircleCollider2DComponent
484+ }
485+ }
486+
487+ template <>
488+ static void DeserializeEntryComponent<CircleCollider2DComponent>(YAML ::detail::iterator_value& entity, Entity& deserializedEntity)
489+ {
490+ auto circleCollider2DComponent = entity[" CircleCollider2DComponent" ];
491+ if (circleCollider2DComponent)
492+ {
493+ auto & bc2d = deserializedEntity.AddComponent <CircleCollider2DComponent>();
494+ bc2d.Offset = circleCollider2DComponent[" Offset" ].as <glm::vec2>();
495+ bc2d.Radius = circleCollider2DComponent[" Radius" ].as <float >();
496+ bc2d.Density = circleCollider2DComponent[" Density" ].as <float >();
497+ bc2d.Friction = circleCollider2DComponent[" Friction" ].as <float >();
498+ bc2d.Restitution = circleCollider2DComponent[" Restitution" ].as <float >();
499+ bc2d.RestitutionThreshold = circleCollider2DComponent[" RestitutionThreshold" ].as <float >();
500+ }
501+ }
476502
477503 template <>
478504 static void SerializeEntityComponent<NativeScriptComponent>(YAML ::Emitter& out, Entity entity)
0 commit comments