2020-02-19 12:50:09 -05:00
|
|
|
#ifndef LEVEL_H
|
|
|
|
#define LEVEL_H
|
|
|
|
|
2020-03-19 17:59:21 -04:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2020-02-19 12:50:09 -05:00
|
|
|
#include <array>
|
2020-03-19 10:24:18 -04:00
|
|
|
#include <map>
|
2020-03-20 18:40:54 -04:00
|
|
|
#include <sstream>
|
2020-02-19 12:50:09 -05:00
|
|
|
|
2020-03-19 10:24:18 -04:00
|
|
|
#include "cell.h"
|
2020-02-19 12:50:09 -05:00
|
|
|
|
2020-03-19 10:24:18 -04:00
|
|
|
// Very desirable to create module for default values
|
2020-03-19 17:59:21 -04:00
|
|
|
const std::string default_file_path = "test_map";
|
2020-02-19 12:50:09 -05:00
|
|
|
|
2020-02-21 09:20:40 -05:00
|
|
|
/// Abstraction over 2D array to quickly get access to level cells
|
2020-02-19 12:50:09 -05:00
|
|
|
class Level
|
|
|
|
{
|
|
|
|
private:
|
2020-03-19 10:24:18 -04:00
|
|
|
struct Map
|
|
|
|
{
|
|
|
|
using Row = std::vector<CellPtr>;
|
|
|
|
using Matrix = std::vector<Row>;
|
|
|
|
|
|
|
|
enum class SECTION
|
|
|
|
{
|
|
|
|
SIZE,
|
|
|
|
MAP,
|
|
|
|
TELEPORT,
|
2020-03-20 18:40:54 -04:00
|
|
|
CHARGE,
|
2020-03-19 10:24:18 -04:00
|
|
|
TRIGGER,
|
|
|
|
NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
std::map<std::string, SECTION> map_section =
|
|
|
|
{
|
|
|
|
{ "size", SECTION::SIZE },
|
|
|
|
{ "map", SECTION::MAP },
|
|
|
|
{ "teleport", SECTION::TELEPORT },
|
2020-03-20 18:40:54 -04:00
|
|
|
{ "charge", SECTION::CHARGE },
|
2020-03-19 10:24:18 -04:00
|
|
|
{ "trigger", SECTION::TRIGGER },
|
|
|
|
{ "", SECTION::NONE }
|
|
|
|
};
|
|
|
|
|
|
|
|
Matrix data;
|
|
|
|
size_t rows, cols;
|
|
|
|
std::array<CellPtr, N_CELLS> default_cells;
|
|
|
|
|
2020-03-19 17:59:21 -04:00
|
|
|
void init(const std::string &path = default_file_path);
|
2020-03-19 10:24:18 -04:00
|
|
|
|
|
|
|
/// Prepare prototypes of default cells
|
|
|
|
void prepareDefaultCells();
|
|
|
|
|
2020-03-19 11:42:45 -04:00
|
|
|
// Map file section readers
|
2020-03-19 10:24:18 -04:00
|
|
|
void readMapSize(std::istringstream &sstr);
|
|
|
|
void readMapRow(std::istringstream &sstr);
|
2020-03-20 18:40:54 -04:00
|
|
|
void readCellSection(std::istringstream &sstr, const SECTION §ion);
|
|
|
|
std::unique_ptr<TeleportCell> &&readTeleport(std::istringstream &sstr, std::unique_ptr<TeleportCell> &&cell);
|
|
|
|
std::unique_ptr<ChargeCell> &&readCharge(std::istringstream &sstr, std::unique_ptr<ChargeCell> &&cell);
|
|
|
|
std::unique_ptr<TriggerCell> &&readTrigger(std::istringstream &sstr, std::unique_ptr<TriggerCell> &&cell);
|
2020-03-19 10:24:18 -04:00
|
|
|
};
|
|
|
|
|
2020-02-19 12:50:09 -05:00
|
|
|
Map map;
|
2020-03-15 11:02:37 -04:00
|
|
|
sf::Color color_ground;
|
2020-02-19 12:50:09 -05:00
|
|
|
|
|
|
|
public:
|
2020-03-19 17:59:21 -04:00
|
|
|
Level(const std::string &path = default_file_path);
|
2020-03-15 17:57:39 -04:00
|
|
|
|
2020-03-19 10:24:18 -04:00
|
|
|
/// Number of map rows
|
2020-03-17 00:27:30 -04:00
|
|
|
size_t rows() const;
|
2020-03-19 10:24:18 -04:00
|
|
|
|
|
|
|
/// Number of map columns
|
2020-03-17 00:27:30 -04:00
|
|
|
size_t cols() const;
|
2020-02-20 13:34:41 -05:00
|
|
|
|
2020-03-19 10:24:18 -04:00
|
|
|
/// Get cell at position row, col
|
|
|
|
CellPtr &getCellAt(coordinate row, coordinate col);
|
|
|
|
|
2020-02-20 13:34:41 -05:00
|
|
|
/// Place a bridge cell
|
2020-02-21 09:13:12 -05:00
|
|
|
void placeBridge(coordinate x, coordinate y);
|
2020-02-20 13:34:41 -05:00
|
|
|
|
|
|
|
/// Replace a charge cell with a ground cell
|
2020-02-21 09:13:12 -05:00
|
|
|
void removeCharge(coordinate x, coordinate y);
|
2020-03-15 11:02:37 -04:00
|
|
|
|
|
|
|
/// Get default color for passable cells
|
|
|
|
sf::Color defaultGroundColor();
|
|
|
|
|
|
|
|
/// Set default color for passable cells
|
|
|
|
void setDefaultGroundColor(const sf::Color &color);
|
2020-02-19 12:50:09 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LEVEL_H
|