Skip to content
Snippets Groups Projects
Commit fe650c77 authored by TheUltimateOptimist's avatar TheUltimateOptimist
Browse files

started implementing loadLevel

parent bb0f09e9
Branches
No related tags found
1 merge request!17Merge feature to load levels from file
......@@ -3,6 +3,9 @@
#include "building.hpp"
#include "effect.hpp"
#include "engine.hpp"
#include "highfive/H5File.hpp"
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include "spritesheet.hpp"
#include "unit.hpp"
#include <SDL.h>
......@@ -22,6 +25,36 @@ Level::Level(std::string name, int width, int height, std::vector<Tile> tiles,
}
};
Level Level::loadLevel(std::string path)
{
HighFive::File file(path, HighFive::File::ReadOnly);
// read level metadata
std::string level_metadata;
file.getDataSet("level/metadata").read(level_metadata);
// read tilesarray
std::vector<uint8_t> level_tilesarray;
file.getDataSet("level/tilesarray").read(level_tilesarray);
// extract metadata from xml
std::istringstream xmlStream(level_metadata);
boost::property_tree::ptree pt;
boost::property_tree::read_xml(xmlStream, pt);
int width = pt.get<int>("level.width");
int height = pt.get<int>("level.height");
std::string name = pt.get<std::string>("level.name");
std::vector<Tile> tiles;
tiles.reserve(width*height);
for (uint8_t value : level_tilesarray)
{
tiles.push_back(Tile())
}
throw std::runtime_error("some");
};
void Level::render(Engine &engine, std::vector<SDL_Event> &events) {
const int RENDERING_SCALE = 3;
......
......@@ -21,6 +21,8 @@ public:
std::vector<Building> buildings, std::vector<Unit> units,
std::vector<Effect>);
static Level loadLevel(std::string path);
void render(Engine &engine, std::vector<SDL_Event> &events);
private:
......
......@@ -30,6 +30,8 @@ int main() {
Window window("Advanced Wars", 960, 960);
Engine engine(window);
Level levell = Level::loadLevel("level.h5");
return 0;
// Construct a level
std::vector<Tile> tiles;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment