YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
World.cpp
Go to the documentation of this file.
1
#include "
YAPOG/Game/Factory/ObjectFactory.hpp
"
2
3
#include "World/World.hpp"
4
#include "World/Map/Map.hpp"
5
6
namespace
ycl
7
{
8
const
bool
World::DEFAULT_VISIBLE_STATE
=
true
;
9
const
sf::Color
World::DEFAULT_COLOR
= sf::Color ();
10
11
World::World
()
12
: yap::
World
()
13
, OnMapChanged ()
14
, isVisible_ (DEFAULT_VISIBLE_STATE)
15
, color_ (DEFAULT_COLOR)
16
, drawingPolicy_ (nullptr)
17
, currentMapID_ ()
18
, currentMap_ (nullptr)
19
, maps_ ()
20
, packetHandler_ ()
21
{
22
}
23
24
World::~World
()
25
{
26
}
27
28
void
World::ChangeMap
(
const
yap::ID
& worldID)
29
{
30
if
(
currentMapID_
== worldID)
31
return
;
32
33
Map
* oldMap =
currentMap_
;
34
35
if
(oldMap !=
nullptr
)
36
{
37
RemoveRelay
(
currentMap_
);
38
currentMap_
->
SetParent
(
nullptr
);
39
}
40
41
currentMapID_
= worldID;
42
43
currentMap_
=
maps_
[
currentMapID_
];
44
45
AddRelay
(
currentMap_
);
46
currentMap_
->
SetParent
(
this
);
47
48
OnMapChanged
(*
this
,
yap::ChangeEventArgs<Map*>
(oldMap,
currentMap_
));
49
}
50
51
Map
&
World::GetCurrentMap
()
52
{
53
return
*
currentMap_
;
54
}
55
56
void
World::AddMap
(
const
yap::ID
& worldID,
const
yap::ID
&
id
)
57
{
58
if
(
maps_
.
Contains
(worldID))
59
return
;
60
61
Map
* map =
yap::ObjectFactory::Instance
().
Get
<
Map
> (
"Map"
, id);
62
map->
SetWorldID
(worldID);
63
64
AddMap
(map);
65
}
66
67
void
World::AddMap
(
Map
* map)
68
{
69
if
(
drawingPolicy_
!=
nullptr
)
70
map->
SetWorldDrawingPolicy
(*
drawingPolicy_
);
71
72
maps_
.
Add
(map->
GetWorldID
(), map);
73
}
74
75
void
World::RemoveMap
(
const
yap::ID
& worldID)
76
{
77
maps_
.
Remove
(worldID);
78
}
79
80
void
World::SetDrawingPolicy
(
const
yap::IWorldDrawingPolicy
& drawingPolicy)
81
{
82
drawingPolicy_
= &drawingPolicy;
83
84
for
(
auto
& idMapPair :
maps_
)
85
idMapPair.second->SetWorldDrawingPolicy (*
drawingPolicy_
);
86
}
87
88
void
World::Draw
(
yap::IDrawingContext
& context)
89
{
90
if
(!
IsVisible
())
91
return
;
92
93
HandleDraw
(context);
94
}
95
96
bool
World::IsVisible
()
const
97
{
98
return
isVisible_
;
99
}
100
101
void
World::Show
(
bool
isVisible)
102
{
103
isVisible_
= isVisible;
104
105
HandleShow
(isVisible);
106
}
107
108
void
World::ChangeColor
(
const
sf::Color& color)
109
{
110
color_
= color;
111
112
HandleChangeColor
(color);
113
}
114
115
bool
World::HandlePacket
(
yap::IPacket
& packet)
116
{
117
return
packetHandler_
.
HandlePacket
(packet);
118
}
119
120
bool
World::SendPacket
(
yap::IPacket
& packet)
121
{
122
return
packetHandler_
.
SendPacket
(packet);
123
}
124
125
void
World::AddRelay
(
yap::IPacketHandler
* relay)
126
{
127
packetHandler_
.
AddRelay
(relay);
128
}
129
130
void
World::RemoveRelay
(
yap::IPacketHandler
* relay)
131
{
132
packetHandler_
.
RemoveRelay
(relay);
133
}
134
135
void
World::SetParent
(
yap::IPacketHandler
* parent)
136
{
137
packetHandler_
.
SetParent
(parent);
138
}
139
140
void
World::HandleUpdate
(
const
yap::Time
& dt)
141
{
142
if
(
currentMap_
!=
nullptr
)
143
currentMap_
->
Update
(dt);
144
}
145
146
void
World::HandleDraw
(
yap::IDrawingContext
& context)
147
{
148
if
(
currentMap_
!=
nullptr
)
149
currentMap_
->
Draw
(context);
150
}
151
152
void
World::HandleShow
(
bool
isVisible)
153
{
154
}
155
156
void
World::HandleChangeColor
(
const
sf::Color& color)
157
{
158
for
(
auto
& it :
maps_
)
159
it.second->ChangeColor (color);
160
}
161
}
// namespace ycl
YAPOG.Client
src
World
World.cpp
Generated on Mon Sep 17 2012 22:24:25 for YAPOG by
1.8.1.1