level.cpp 1.07 KB
Newer Older
Georg Schäfer's avatar
Georg Schäfer committed
1
2
3
4
5
#include "level.hpp"

#include <sstream>

namespace phase_shifter::level {
Georg Schäfer's avatar
Georg Schäfer committed
6
	Level::Level(Tileset_ptr tileset, vector_2d<char> tiles) : tileset(tileset), tiles(tiles) {}
Georg Schäfer's avatar
Georg Schäfer committed
7
8
9
10
11
12
13
14
} // namespace phase_shifter::level

namespace mirrage::asset {

	auto Loader<phase_shifter::level::Level>::load(istream in) -> async::task<phase_shifter::level::Level>
	{
		std::string tileset_name;
		in >> tileset_name;
15
		in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
Georg Schäfer's avatar
Georg Schäfer committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

		auto tileset = in.manager().load<phase_shifter::level::Tileset>(AID("tiles:" + tileset_name));

		auto all_loaded = async::when_all(tileset.internal_task());
		using Task_type = decltype(all_loaded)::result_type;

		auto                                         lines = in.lines();
		phase_shifter::level::Level::vector_2d<char> tiles;
		for(auto&& line : lines) {
			std::vector<char> row;
			for(auto&& key : line) {
				row.emplace_back(key);
			}
			tiles.emplace_back(row);
		}

		return all_loaded.then(
		        [=](const Task_type&) mutable { return phase_shifter::level::Level(tileset, tiles); });
	}
} // namespace mirrage::asset