This commit is contained in:
aozhiwei 2023-02-06 19:27:15 +08:00
parent 365008150d
commit 9b7b8df895
4 changed files with 46 additions and 1 deletions

View File

@ -0,0 +1,13 @@
#include "precompile.h"
#include "mapcollider.h"
namespace mc
{
void ColliderNode::Read(std::shared_ptr<a8::XObject> xobj)
{
name = xobj->At("name")->AsXValue().GetString();
}
}

View File

@ -49,6 +49,8 @@ namespace mc
std::string name;
std::vector<Collider*> colliders;
std::map<std::string, ColliderNode*> childs;
void Read(std::shared_ptr<a8::XObject> xobj);
};
};

View File

@ -0,0 +1,26 @@
#include "precompile.h"
#include <a8/xobject.h>
#include "mt/MapCollider.h"
namespace mt
{
void MapCollider::Load(const std::string& filename)
{
a8::XObject xobj_root;
xobj_root.ReadFromFile(filename);
auto xobj_nodes = xobj_root.At("nodes");
for (int i = 0; i < xobj_nodes->Size(); ++i) {
auto xobj_node = xobj_nodes->At(i);
mc::ColliderNode* node = new mc::ColliderNode();
node->Read(xobj_node);
if (nodes_.find(node->name) != nodes_.end()) {
abort();
}
nodes_[node->name] = node;
}
}
}

View File

@ -7,8 +7,12 @@ namespace mt
class MapCollider
{
public:
void Load(const std::string& filename);
private:
std::map<std::string, mc::ColliderNode*> nodes;
std::map<std::string, mc::ColliderNode*> nodes_;
};
}