YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
TileLayerStack.cpp
Go to the documentation of this file.
1
#include "
YAPOG/Graphics/Game/World/Map/TileLayerStack.hpp
"
2
#include "
YAPOG/System/Error/Exception.hpp
"
3
#include "
YAPOG/System/StringHelper.hpp
"
4
#include "
YAPOG/Graphics/Game/World/Map/TileLayer.hpp
"
5
#include "
YAPOG/Graphics/Game/World/Map/TileLayoutHandler.hpp
"
6
7
namespace
yap
8
{
9
const
uint
TileLayerStack::DEFAULT_WIDTH
= 0;
10
const
uint
TileLayerStack::DEFAULT_HEIGHT
= 0;
11
const
uint
TileLayerStack::DEFAULT_MAX_HEIGHT
= 3;
12
13
TileLayerStack::TileLayerStack
()
14
: width_ (DEFAULT_WIDTH)
15
, height_ (DEFAULT_HEIGHT)
16
, tileLayers_ ()
17
{
18
}
19
20
TileLayerStack::~TileLayerStack
()
21
{
22
for
(
const
auto
& it :
tileLayers_
)
23
delete
it.second;
24
}
25
26
TileLayerStack::TileLayerStack
(
const
TileLayerStack
& copy)
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
35
TileLayerStack
*
TileLayerStack::Clone
()
const
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
51
void
TileLayerStack::AddTileLayer
(
52
uint
height,
53
TileLayoutHandler
* layoutHandler)
54
{
55
if
(height >
DEFAULT_MAX_HEIGHT
)
56
YAPOG_THROW
(
57
"TileLayer level `"
+
58
StringHelper::ToString
(height) +
59
"' is too high."
);
60
61
if
(
tileLayers_
.
Contains
(height))
62
YAPOG_THROW
(
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
71
const
TileLayer
&
TileLayerStack::GetTileLayer
(
uint
height)
const
72
{
73
return
*
tileLayers_
[height];
74
}
75
76
TileLayer
&
TileLayerStack::GetTileLayer
(
uint
height)
77
{
78
return
*
tileLayers_
[height];
79
}
80
81
void
TileLayerStack::Draw
(
IDrawingContext
& context)
82
{
83
for
(
auto
& it :
tileLayers_
)
84
it.second->Draw (context);
85
}
86
87
bool
TileLayerStack::IsVisible
()
const
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
YAPOG
src
YAPOG
Graphics
Game
World
Map
TileLayerStack.cpp
Generated on Mon Sep 17 2012 22:24:25 for YAPOG by
1.8.1.1