Added class for parsing smlf (xml) files to game field structure and its description
This commit is contained in:
parent
65735c45a5
commit
cb147f7057
41
XmlLayout.cpp
Normal file
41
XmlLayout.cpp
Normal file
@ -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();
|
||||
}
|
||||
}
|
24
XmlLayout.h
Normal file
24
XmlLayout.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef XMLLAYOUT_H
|
||||
#define XMLLAYOUT_H
|
||||
|
||||
#include "wxw.h"
|
||||
|
||||
#include <wx/xml/xml.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
class XmlLayout {
|
||||
public:
|
||||
XmlLayout();
|
||||
|
||||
bool openFile(const wxString& path);
|
||||
wxSize getDimensions();
|
||||
void readLayout(TLVec& table);
|
||||
|
||||
private:
|
||||
wxString path;
|
||||
|
||||
wxXmlDocument layoutDoc;
|
||||
};
|
||||
|
||||
#endif
|
@ -10,4 +10,4 @@ int upDiv(int a, int b) {
|
||||
|
||||
wxString itowxS(int a) {
|
||||
return wxString::Format("%i", a);
|
||||
}
|
||||
}
|
||||
|
8
utils.h
8
utils.h
@ -7,4 +7,10 @@ wxString LTimeToStr(int time);
|
||||
int upDiv(int a, int b);
|
||||
wxString itowxS(int a);
|
||||
|
||||
#endif
|
||||
#define min(a, b) (a + b - abs(a - b)) / 2
|
||||
#define max(a, b) (a + b + abs(a - b)) / 2
|
||||
|
||||
using TLSquare = std::pair<uint8_t, uint8_t>;
|
||||
using TLVec = wxVector<wxVector<wxVector<TLSquare>>>;
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user