Implemented serialization for text color and trajectory rendering #381

Merged
Xenosas1337 merged 10 commits from SP3-1-Rendering into main 2023-03-02 12:47:35 +08:00
4 changed files with 12 additions and 5 deletions
Showing only changes of commit 4b37be6075 - Show all commits

View File

@ -600,7 +600,7 @@ namespace SHADE
} }
); );
SHEditorWidgets::ColorPicker("Color", [&textComp = component]() {return textComp->GetColour(); }, [&textComp = component](SHVec4 const& newColor) {textComp->SetColour(newColor); }); SHEditorWidgets::ColorPicker("Color", [&textComp = component]() {return textComp->GetColor(); }, [&textComp = component](SHVec4 const& newColor) {textComp->SetColor(newColor); });
} }
else else
{ {

View File

@ -61,7 +61,7 @@ namespace SHADE
MakeDirty(); MakeDirty();
} }
void SHTextRenderableComponent::SetColour(SHColour const& newColor) noexcept void SHTextRenderableComponent::SetColor(SHColour const& newColor) noexcept
{ {
color = newColor; color = newColor;
} }
@ -87,7 +87,7 @@ namespace SHADE
return fontHandle; return fontHandle;
} }
SHADE::SHColour const& SHTextRenderableComponent::GetColour(void) const noexcept SHADE::SHColour const& SHTextRenderableComponent::GetColor(void) const noexcept
{ {
return color; return color;
} }

View File

@ -52,11 +52,11 @@ namespace SHADE
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
void SetText (std::string_view newText) noexcept; void SetText (std::string_view newText) noexcept;
void SetFont(Handle<SHFont> font) noexcept; void SetFont(Handle<SHFont> font) noexcept;
void SetColour(SHColour const& newColor) noexcept; void SetColor(SHColour const& newColor) noexcept;
std::string const& GetText (void) const noexcept; std::string const& GetText (void) const noexcept;
Handle<SHFont> GetFont (void) const noexcept; Handle<SHFont> GetFont (void) const noexcept;
SHColour const& GetColour (void) const noexcept; SHColour const& GetColor (void) const noexcept;
friend class SHTextRenderingSubSystem; friend class SHTextRenderingSubSystem;

View File

@ -353,12 +353,14 @@ namespace YAML
{ {
static constexpr std::string_view TEXT_YAML_TAG = "Text"; static constexpr std::string_view TEXT_YAML_TAG = "Text";
static constexpr std::string_view FONT_YAML_TAG = "Font"; static constexpr std::string_view FONT_YAML_TAG = "Font";
static constexpr std::string_view COLOR_YAML_TAG = "Color";
static YAML::Node encode(SHTextRenderableComponent const& rhs) static YAML::Node encode(SHTextRenderableComponent const& rhs)
{ {
YAML::Node node; YAML::Node node;
node[TEXT_YAML_TAG.data()] = rhs.GetText(); node[TEXT_YAML_TAG.data()] = rhs.GetText();
auto font = rhs.GetFont(); auto font = rhs.GetFont();
SHColour const& textColor = rhs.GetColor();
if (font) if (font)
{ {
node[FONT_YAML_TAG.data()] = SHResourceManager::GetAssetID<SHFont>(rhs.GetFont()).value_or(0); node[FONT_YAML_TAG.data()] = SHResourceManager::GetAssetID<SHFont>(rhs.GetFont()).value_or(0);
@ -367,6 +369,7 @@ namespace YAML
{ {
node[FONT_YAML_TAG.data()] = 0; node[FONT_YAML_TAG.data()] = 0;
} }
node[COLOR_YAML_TAG.data()] = SHVec4 (textColor);
return node; return node;
} }
static bool decode(YAML::Node const& node, SHTextRenderableComponent& rhs) static bool decode(YAML::Node const& node, SHTextRenderableComponent& rhs)
@ -385,6 +388,10 @@ namespace YAML
rhs.SetFont(SHResourceManager::LoadOrGet<SHFont>(node[FONT_YAML_TAG.data()].as<AssetID>())); rhs.SetFont(SHResourceManager::LoadOrGet<SHFont>(node[FONT_YAML_TAG.data()].as<AssetID>()));
} }
if (node[COLOR_YAML_TAG.data()].IsDefined())
{
rhs.SetColor(node[COLOR_YAML_TAG.data()].as<SHVec4>());
}
return true; return true;
} }
}; };