Skip to content

Commit

Permalink
Added Serialisation functions to Label.
Browse files Browse the repository at this point in the history
Renamed a member to snake_case.
  • Loading branch information
MStachowicz committed Sep 18, 2024
1 parent decbb40 commit 64e184d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ source/Component/Collider.hpp
source/Component/Input.cpp
source/Component/Input.hpp
source/Component/Label.hpp
source/Component/Label.cpp
source/Component/Mesh.cpp
source/Component/Mesh.hpp
source/Component/ParticleEmitter.hpp
Expand Down
18 changes: 18 additions & 0 deletions source/Component/Label.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "Label.hpp"

#include "Utility/Serialise.hpp"

namespace Component
{
void Label::serialise(std::ostream& p_out, uint16_t p_version, const Label& p_label)
{
Utility::write_binary(p_out, p_version, p_label.m_name);
}
Label Label::deserialise(std::istream& p_in, uint16_t p_version)
{
Label label("");
Utility::read_binary(p_in, p_version, label.m_name);
return label;
}
static_assert(Utility::Is_Serializable_v<Label>, "Label is not serializable, check that the required functions are implemented.");
}
11 changes: 8 additions & 3 deletions source/Component/Label.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <string>
#include <iostream>
#include <cstdint>

namespace Component
{
Expand All @@ -9,10 +11,13 @@ namespace Component
public:
constexpr static size_t Persistent_ID = 12;

Label(const std::string& pName)
: mName{pName}
Label(const std::string& p_name = "")
: m_name{p_name}
{}

std::string mName;
static void serialise(std::ostream& p_out, uint16_t p_version, const Label& p_label);
static Label deserialise(std::istream& p_in, uint16_t p_version);

std::string m_name;
};
}
4 changes: 2 additions & 2 deletions source/UI/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ namespace UI
if (scene.has_components<Component::Label>(p_entity))
{
auto label = scene.get_component<Component::Label&>(p_entity);
title = label.mName;
title = label.m_name;
}

if (ImGui::TreeNode(title.c_str()))
Expand Down Expand Up @@ -543,7 +543,7 @@ namespace UI
if (scene.has_components<Component::Label>(ent))
{
auto label = scene.get_component<Component::Label&>(ent);
title = label.mName;
title = label.m_name;
}
else
title = "Entity " + std::to_string(ent.ID);
Expand Down

0 comments on commit 64e184d

Please sign in to comment.