HDSDK/SDK/Data/HProgramInfo.cpp
2024-12-09 14:32:58 +08:00

244 lines
6.4 KiB
C++

#include "HXml.h"
#include <Data/HProgramInfo.h>
void to_xml(HXml &xml, const EffectInfo &node)
{
xml["effect"] = {
{"inSpeed", node.inSpeed},
{"outSpeed", node.outSpeed},
{"in", node.in},
{"out", node.out},
{"duration", node.duration},
};
}
void from_xml(const HXml &xml, EffectInfo &node)
{
node.inSpeed = xml.at("effect").GetAttribute("inSpeed").ToInt();
node.outSpeed = xml.at("effect").GetAttribute("outSpeed").ToInt();
node.in = xml.at("effect").GetAttribute("in").ToInt();
node.out = xml.at("effect").GetAttribute("out").ToInt();
node.duration = xml.at("effect").GetAttribute("duration").ToInt();
}
void to_xml(HXml &xml, const FileInfo &node)
{
xml["file"] = {
{"name", node.name},
{"md5", node.md5},
{"size", node.size},
};
}
void from_xml(const HXml &xml, FileInfo &node)
{
node.name = xml.at("file").GetAttribute("name");
node.md5 = xml.at("file").GetAttribute("md5");
node.size = xml.at("file").GetAttribute("size").ToInt();
}
void to_xml(HXml &xml, const TextInfo &node)
{
xml = {
{"guid", node.guid},
{"background", node.background},
};
xml["string"].SetText(node.text);
xml["style"] = {
{"valign", node.style.valign},
{"align", node.style.align},
};
xml["font"] = {
{"name", node.font.name},
{"color", node.font.color},
{"italic", node.font.italic},
{"bold", node.font.bold},
{"underline", node.font.underline},
{"size", node.font.size},
};
xml.ToXml(node.effect);
}
void from_xml(const HXml &xml, TextInfo &node)
{
node.guid = xml.GetAttribute("guid");
node.background = xml.GetAttribute("background");
node.text.Clear();
if (xml.ContainsNodes("string")) {
node.text = xml.at("string").GetText();
}
node.style.valign = xml.at("style").GetAttribute("valign");
node.style.align = xml.at("style").GetAttribute("align");
node.font.name = xml.at("font").GetAttribute("name");
node.font.color = xml.at("font").GetAttribute("color");
if (xml.at("font").ContainsAttribute("italic")) {
node.font.italic = xml.at("font").GetAttribute("italic") == "true";
}
if (xml.at("font").ContainsAttribute("bold")) {
node.font.bold = xml.at("font").GetAttribute("bold") == "true";
}
if (xml.at("font").ContainsAttribute("underline")) {
node.font.underline = xml.at("font").GetAttribute("underline") == "true";
}
node.font.size = xml.at("font").GetAttribute("size").ToInt();
xml.get_to(node.effect);
}
void to_xml(HXml &xml, const PhotoInfo &node)
{
xml = {
{"guid",node.guid},
{"fit", node.fit},
};
xml.ToXml(node.file);
xml.ToXml(node.effect);
}
void from_xml(const HXml &xml, PhotoInfo &node)
{
node.guid = xml.GetAttribute("guid");
if (xml.ContainsAttribute("fit")) {
node.fit = xml.GetAttribute("fit");
}
xml.get_to(node.file);
xml.get_to(node.effect);
}
void to_xml(HXml &xml, const VideoInfo &node)
{
xml = {
{"guid", node.guid},
{"aspectRatio", node.aspectRatio ? "true" : "false"},
};
xml["playParams"] = {
{"duration", node.playParams.duration},
};
xml.ToXml(node.file);
}
void from_xml(const HXml &xml, VideoInfo &node)
{
node.guid = xml.GetAttribute("guid");
if (xml.ContainsAttribute("aspectRatio")) {
node.aspectRatio = xml.GetAttribute("aspectRatio") == "true";
}
xml.get_to(node.file);
if (xml.ContainsNodes("playParams")) {
node.playParams.duration = xml.at("playParams").GetAttribute("duration").ToInt();
}
}
void to_xml(HXml &xml, const ResourcesInfo &node)
{
for (const auto &i : node.nodeList) {
i->ToXml(xml);
}
}
void from_xml(const HXml &xml, ResourcesInfo &node)
{
node.nodeList.clear();
auto *xmlNode = xml.GetNode()->FirstChildElement();
while (xmlNode != nullptr) {
std::shared_ptr<IProgramNode> item;
const cat::HCatBuffer name(xmlNode->Name());
if (name == "text") {
item.reset(new TextInfo());
} else if (name == "image") {
item.reset(new PhotoInfo());
} else if (name == "video") {
item.reset(new VideoInfo());
} else {
printf("Not suuport node[%s]\n", name.ConstData());
continue;
}
if (item->FromXml(HXml(xmlNode)) == false) {
xmlNode = xmlNode->NextSiblingElement();
continue;
}
node.nodeList.emplace_back(item);
xmlNode = xmlNode->NextSiblingElement();
}
}
void to_xml(HXml &xml, const AreaNodeInfo &node)
{
xml = {
{"guid", node.guid},
{"alpha", node.alpha},
};
xml["rectangle"] = {
{"x", node.rect.x},
{"y", node.rect.y},
{"width", node.rect.width},
{"height", node.rect.height},
};
xml["resources"].ToXml(node.resource);
}
void from_xml(const HXml &xml, AreaNodeInfo &node)
{
node.guid = xml.GetAttribute("guid");
node.alpha = xml.GetAttribute("alpha").ToInt();
node.rect.x = xml.at("rectangle").GetAttribute("x").ToInt();
node.rect.y = xml.at("rectangle").GetAttribute("y").ToInt();
node.rect.width = xml.at("rectangle").GetAttribute("width").ToInt();
node.rect.height = xml.at("rectangle").GetAttribute("height").ToInt();
xml.at("resource").get_to(node.resource);
}
void to_xml(HXml &xml, const ProgramNodeInfo &node)
{
xml = {
{"guid", node.guid},
};
for (const auto &i : node.areaList) {
xml.NewChild("area").ToXml(i);
}
}
void from_xml(const HXml &xml, ProgramNodeInfo &node) {
node.guid = xml.GetAttribute("guid");
for (const auto &i : xml.at("area")) {
AreaNodeInfo item;
if (i.get_to(item) == false) {
continue;
}
node.areaList.emplace_back(std::move(item));
}
}
void to_xml(HXml &xml, const ScreenNodeInfo &node) {
xml["screen"] = {
{"timeStamps", node.timeStamps},
};
for (const auto &i : node.programList) {
xml["screen"].NewChild("program").ToXml(i);
}
}
void from_xml(const HXml &xml, ScreenNodeInfo &node) {
node.timeStamps = xml.at("screen").GetAttribute("timeStamps").ToInt();
for (const auto &i : xml.at("screen").at("program")) {
ProgramNodeInfo item;
if (i.get_to(item) == false) {
continue;
}
node.programList.emplace_back(std::move(item));
}
}