diff --git a/XmlLayout.cpp b/XmlLayout.cpp new file mode 100644 index 0000000..6a44dcc --- /dev/null +++ b/XmlLayout.cpp @@ -0,0 +1,41 @@ +#include "XmlLayout.h" + +XmlLayout::XmlLayout() : path("") { } + +bool XmlLayout::openFile(const wxString& openPath) { + if (openPath.IsSameAs(path)) + return true; + + if (!layoutDoc.Load(openPath)) + return false; + + if (layoutDoc.GetRoot() == nullptr) + return false; + + return true; +} + +wxSize XmlLayout::getDimensions() { + return { wxAtoi(layoutDoc.GetRoot()->GetAttribute("ux")) + 2, + wxAtoi(layoutDoc.GetRoot()->GetAttribute("uy")) + 2 }; +} + +void XmlLayout::readLayout(TLVec& table) { + wxXmlNode* tilePtr = layoutDoc.GetRoot()->GetChildren(); + + int x = 0, y = 0, l = 1; + + while (tilePtr) { + if (tilePtr->GetName().IsSameAs("tile")) { + x = wxAtoi(tilePtr->GetAttribute("x")); + y = wxAtoi(tilePtr->GetAttribute("y")); + l = wxAtoi(tilePtr->GetAttribute("layer")); + + table[x][y].push_back(std::make_pair(l - 1, (uint8_t)-1)); + + table[x][y].at(table[x][y].size() -1).second = (random()) % 37; + } + + tilePtr = tilePtr->GetNext(); + } +} diff --git a/XmlLayout.h b/XmlLayout.h new file mode 100644 index 0000000..c5d98c8 --- /dev/null +++ b/XmlLayout.h @@ -0,0 +1,24 @@ +#ifndef XMLLAYOUT_H +#define XMLLAYOUT_H + +#include "wxw.h" + +#include + +#include "utils.h" + +class XmlLayout { +public: + XmlLayout(); + + bool openFile(const wxString& path); + wxSize getDimensions(); + void readLayout(TLVec& table); + +private: + wxString path; + + wxXmlDocument layoutDoc; +}; + +#endif diff --git a/utils.cpp b/utils.cpp index 6649a68..d950e43 100644 --- a/utils.cpp +++ b/utils.cpp @@ -10,4 +10,4 @@ int upDiv(int a, int b) { wxString itowxS(int a) { return wxString::Format("%i", a); -} \ No newline at end of file +} diff --git a/utils.h b/utils.h index dff6caa..9ba189d 100644 --- a/utils.h +++ b/utils.h @@ -7,4 +7,10 @@ wxString LTimeToStr(int time); int upDiv(int a, int b); wxString itowxS(int a); -#endif \ No newline at end of file +#define min(a, b) (a + b - abs(a - b)) / 2 +#define max(a, b) (a + b + abs(a - b)) / 2 + +using TLSquare = std::pair; +using TLVec = wxVector>>; + +#endif