4
Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
6
This program is free software; you can redistribute it and/or modify it
7
under the terms of the GNU General Public License as published by the
8
Free Software Foundation; either version 2 of the License, or (at your
9
option) any later version.
11
This program is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16
You should have received a copy of the GNU General Public License along
17
with this program; if not, write to the Free Software Foundation, Inc.,
18
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
contact: plee-the-bear@gamned.org
22
Please add the tag [PTB] in the subject of your mails.
25
* \file level_information.cpp
26
* \brief Implementation of the ptb::level_information class.
27
* \author Sebastien Angibaud
29
#include "ptb/level_information.hpp"
31
#include "ptb/game_variables.hpp"
32
#include "engine/game.hpp"
33
#include "engine/variable/variable.hpp"
36
#include <claw/logger.hpp>
37
#include <claw/string_algorithm.hpp>
40
/*----------------------------------------------------------------------------*/
41
const std::string ptb::level_information::s_level_file_field = "level_file";
42
const std::string ptb::level_information::s_locked_informations_field =
43
"locked_informations";
44
const std::string ptb::level_information::s_unlocked_informations_field =
45
"unlocked_informations";
46
const std::string ptb::level_information::s_playability_field = "playability";
47
const std::string ptb::level_information::s_score_format_field = "score_format";
48
const std::string ptb::level_information::s_score_ordering = "score_ordering";
49
const std::string ptb::level_information::s_unlocked = "unlocked";
51
/*----------------------------------------------------------------------------*/
55
ptb::level_information::level_information()
58
} // level_information::level_information()
60
/*----------------------------------------------------------------------------*/
64
ptb::level_information::level_information(const std::string& name)
65
: m_id(name), m_playability(playability_type::one_or_two_players),
66
m_score_format("%v (%p)")
69
( bear::engine::game::get_instance().get_custom_game_file(m_id) );
72
std::string thumb_name = m_id;
74
claw::text::replace( thumb_name, std::string(" /"), std::string("_") );
76
( thumb_name.begin(), thumb_name.end(), thumb_name.begin(), tolower );
78
m_thumb_filename = "gfx/thumb/" + thumb_name + ".png";
79
} // level_information::level_information()
81
/*----------------------------------------------------------------------------*/
83
* \brief Set a field of the level.
84
* \param field The considered field.
85
* \param The value of the field.
87
void ptb::level_information::load
88
(const std::string& field, const std::string& value)
90
if ( field == s_level_file_field )
92
else if ( field == s_locked_informations_field )
93
m_locked_informations = value;
94
else if ( field == s_unlocked_informations_field )
95
m_unlocked_informations = value;
96
else if ( field == s_playability_field )
97
m_playability = playability_type::from_string( value );
98
else if ( field == s_score_format_field )
99
m_score_format = gettext(value.c_str());
100
else if ( field == s_score_ordering )
101
m_score_table.set_score_ordering( value == "max" );
102
else if ( field == s_unlocked )
103
game_variables::set_mini_game_status( m_id, (value == "true") );
105
claw::logger << claw::log_error
106
<< "The field '" << field << "' is unknown." << std::endl;
107
} // level_information::load()
109
/*----------------------------------------------------------------------------*/
111
* \brief Tell if the item is correctly initialized.
113
bool ptb::level_information::is_valid() const
115
return (!m_id.empty()) && (!m_thumb_filename.empty());
116
} // level_information::is_valid()
118
/*----------------------------------------------------------------------------*/
120
* \brief Tell if the level is unlocked.
122
bool ptb::level_information::is_unlocked() const
124
return game_variables::get_all_mini_game_unlocked_status()
125
|| game_variables::get_mini_game_status( m_id );
126
} // level_information::is_unlocked()
128
/*----------------------------------------------------------------------------*/
130
* \brief Get the identifier of the level.
132
const std::string& ptb::level_information::get_id() const
135
} // level_information::get_id()
137
/*----------------------------------------------------------------------------*/
139
* \brief Get the filename of the level.
141
const std::string& ptb::level_information::get_filename() const
144
} // level_information::get_filename()
146
/*----------------------------------------------------------------------------*/
148
* \brief Set the filename of thumb.
149
* \param f The filename.
151
void ptb::level_information::set_thumb_filename(const std::string& f)
153
m_thumb_filename = f;
154
} // frame_play_level_information::set_thumb_filename()
156
/*----------------------------------------------------------------------------*/
158
* \brief Get the filename of thumb.
160
const std::string& ptb::level_information::get_thumb_filename() const
162
return m_thumb_filename;
163
} // frame_play_level_information::get_thumb_filename()
165
/*----------------------------------------------------------------------------*/
167
* \brief Set informations when the game is locked.
168
* \param info Informations.
170
void ptb::level_information::set_locked_informations(const std::string& info)
172
m_locked_informations = info;
173
} // frame_play_level_information::set_locked informations()
175
/*----------------------------------------------------------------------------*/
177
* \brief Set informations when the game is unlocked.
178
* \param info Informations.
180
void ptb::level_information::set_unlocked_informations(const std::string& info)
182
m_unlocked_informations = info;
183
} // frame_play_level_information::set_unlocked informations()
185
/*----------------------------------------------------------------------------*/
187
* \brief Get informations of the level.
189
const std::string& ptb::level_information::get_informations() const
192
return m_unlocked_informations;
194
return m_locked_informations;
195
} // frame_play_level_information::get_informations()
197
/*----------------------------------------------------------------------------*/
199
* \brief Get records informations of the level.
201
std::string ptb::level_information::get_record_informations() const
205
for (score_table::const_iterator it=m_score_table.begin();
206
it!=m_score_table.end(); ++it)
207
result += it->format(m_score_format) + '\n';
210
} // frame_play_level_information::get_record_informations()
212
/*----------------------------------------------------------------------------*/
214
* \brief Tell if the level has already been finished.
216
bool ptb::level_information::is_finished() const
218
return !m_score_table.empty();
219
} // frame_play_level_information::is_finished()
221
/*----------------------------------------------------------------------------*/
223
* \brief Get the playability of the level : number of players.
225
ptb::playability_type::value_type
226
ptb::level_information::get_playability() const
228
return m_playability;
229
} // level_information::get_playability()