YAPOG  0.0.1
Yet Another Pokemon Online Game
TileLayerStack.cpp
Go to the documentation of this file.
6 
7 namespace yap
8 {
12 
14  : width_ (DEFAULT_WIDTH)
15  , height_ (DEFAULT_HEIGHT)
16  , tileLayers_ ()
17  {
18  }
19 
21  {
22  for (const auto& it : tileLayers_)
23  delete it.second;
24  }
25 
27  : width_ (copy.width_)
28  , height_ (copy.height_)
29  , tileLayers_ ()
30  {
31  for (const auto& it : copy.tileLayers_)
32  AddTileLayer (it.first, it.second->Clone ());
33  }
34 
36  {
37  return new TileLayerStack (*this);
38  }
39 
40  void TileLayerStack::SetSize (uint width, uint height)
41  {
42  width_ = width;
43  height_ = height;
44  }
45 
46  void TileLayerStack::AddTileLayer (uint height, TileLayer* tileLayer)
47  {
48  tileLayers_.Add (height, tileLayer);
49  }
50 
52  uint height,
53  TileLayoutHandler* layoutHandler)
54  {
55  if (height > DEFAULT_MAX_HEIGHT)
57  "TileLayer level `" +
58  StringHelper::ToString (height) +
59  "' is too high.");
60 
61  if (tileLayers_.Contains (height))
63  "TileLayer `" + StringHelper::ToString (height) + "' already exists.");
64 
65  TileLayer* tileLayer = new TileLayer (width_, height_);
66  layoutHandler->Execute (*tileLayer);
67 
68  AddTileLayer (height, tileLayer);
69  }
70 
72  {
73  return *tileLayers_[height];
74  }
75 
77  {
78  return *tileLayers_[height];
79  }
80 
82  {
83  for (auto& it : tileLayers_)
84  it.second->Draw (context);
85  }
86 
88  {
89  for (const auto& it : tileLayers_)
90  if (!it.second->IsVisible ())
91  return false;
92 
93  return true;
94  }
95 
96  void TileLayerStack::Show (bool isVisible)
97  {
98  for (auto& it : tileLayers_)
99  it.second->Show (isVisible);
100  }
101 
102  void TileLayerStack::ChangeColor (const sf::Color& color)
103  {
104  for (auto& it : tileLayers_)
105  it.second->ChangeColor (color);
106  }
107 
108  void TileLayerStack::Update (const Time& dt)
109  {
110  for (auto& it : tileLayers_)
111  it.second->Update (dt);
112  }
113 } // namespace yap