Peoplemon  0.1.0
Peoplemon 3 game source documentation
LayerSet.cpp
Go to the documentation of this file.
1 #include <Core/Maps/LayerSet.hpp>
2 
3 #include <Core/Maps/Tileset.hpp>
4 #include <Core/Properties.hpp>
5 
6 namespace core
7 {
8 namespace map
9 {
10 void LayerSet::init(unsigned int width, unsigned int height, unsigned int bottomCount,
11  unsigned int ysortLayerCount, unsigned int topLayerCount) {
12  collisionLayer().create(width, height, Collision::Open);
13  catchLayer().create(width, height, 0);
14 
15  bottomLayers().resize(bottomCount);
16  for (TileLayer& layer : bottomLayers()) { layer.create(width, height, {Tile::Blank}); }
17 
18  ysortLayers().resize(ysortLayerCount);
19  for (TileLayer& layer : ysortLayers()) { layer.create(width, height, {Tile::Blank}); }
20 
21  topLayers().resize(topLayerCount);
22  for (TileLayer& layer : topLayers()) { layer.create(width, height, {Tile::Blank}); }
23 }
24 
25 CollisionLayer& LayerSet::collisionLayer() { return collisions; }
26 
27 const CollisionLayer& LayerSet::collisionLayer() const { return collisions; }
28 
29 CatchLayer& LayerSet::catchLayer() { return catches; }
30 
31 const CatchLayer& LayerSet::catchLayer() const { return catches; }
32 
33 std::vector<TileLayer>& LayerSet::bottomLayers() { return bottom; }
34 
35 std::vector<TileLayer>& LayerSet::ysortLayers() { return ysort; }
36 
37 std::vector<TileLayer>& LayerSet::topLayers() { return top; }
38 
39 unsigned int LayerSet::layerCount() const { return bottom.size() + ysort.size() + top.size(); }
40 
41 const std::vector<TileLayer>& LayerSet::bottomLayers() const { return bottom; }
42 
43 const std::vector<TileLayer>& LayerSet::ysortLayers() const { return ysort; }
44 
45 const std::vector<TileLayer>& LayerSet::topLayers() const { return top; }
46 
47 TileLayer& LayerSet::getLayer(unsigned int layer) {
48  if (layer >= layerCount()) {
49  BL_LOG_ERROR << "Accessing out of bounds layer: " << layer;
50  return bottom.front();
51  }
52 
53  if (layer < bottom.size()) { return bottom[layer]; }
54  layer -= bottom.size();
55  if (layer < ysort.size()) { return ysort[layer]; }
56  return top[layer - ysort.size()];
57 }
58 
59 } // namespace map
60 } // namespace core
Core classes and functionality for both the editor and game.
Generic map layer class. Can be used for any type of layer.
Definition: Layer.hpp:21
void create(unsigned int width, unsigned int height, const T &val=T())
Clears all stored data (if any) and creates the layer with the given size.
Definition: Layer.hpp:93
void init(unsigned int width, unsigned int height, unsigned int bottomLayerCount, unsigned int ysortLayerCount, unsigned int topLayercount)
Creates the given number of layers and sets the proper size for each layer, initializing each layer t...
Definition: LayerSet.cpp:10
CatchLayer & catchLayer()
Returns a reference to the catchable layer for this set.
Definition: LayerSet.cpp:29
std::vector< TileLayer > & bottomLayers()
Returns a reference to the bottom tiles in this set.
Definition: LayerSet.cpp:33
std::vector< TileLayer > & topLayers()
Returns a reference to the top tiles in this set.
Definition: LayerSet.cpp:37
CollisionLayer & collisionLayer()
Returns a reference to the collision layer for this set.
Definition: LayerSet.cpp:25
TileLayer & getLayer(unsigned int layer)
Returns a reference to the given tile layer. Helper to use absolute indices to access all layer zones...
Definition: LayerSet.cpp:47
std::vector< TileLayer > & ysortLayers()
Returns a reference to the sorted tiles in this set.
Definition: LayerSet.cpp:35
unsigned int layerCount() const
Returns the total number of layers contained.
Definition: LayerSet.cpp:39
static constexpr IdType Blank
Special id for blank tiles.
Definition: Tile.hpp:36