~ubuntu-branches/ubuntu/trusty/plee-the-bear/trusty-proposed

« back to all changes in this revision

Viewing changes to plee-the-bear/src/ptb/code/level_information.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Plee the Bear
 
3
 
 
4
  Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
 
5
 
 
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.
 
10
 
 
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
 
14
  more details.
 
15
 
 
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
 
19
 
 
20
  contact: plee-the-bear@gamned.org
 
21
 
 
22
  Please add the tag [PTB] in the subject of your mails.
 
23
*/
 
24
/**
 
25
 * \file level_information.cpp
 
26
 * \brief Implementation of the ptb::level_information class.
 
27
 * \author Sebastien Angibaud
 
28
 */
 
29
#include "ptb/level_information.hpp"
 
30
 
 
31
#include "ptb/game_variables.hpp"
 
32
#include "engine/game.hpp"
 
33
#include "engine/variable/variable.hpp"
 
34
 
 
35
#include <algorithm>
 
36
#include <claw/logger.hpp>
 
37
#include <claw/string_algorithm.hpp>
 
38
#include <libintl.h>
 
39
 
 
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";
 
50
 
 
51
/*----------------------------------------------------------------------------*/
 
52
/**
 
53
 * \brief Constructor.
 
54
 */
 
55
ptb::level_information::level_information()
 
56
{
 
57
 
 
58
} // level_information::level_information()
 
59
 
 
60
/*----------------------------------------------------------------------------*/
 
61
/**
 
62
 * \brief Constructor.
 
63
 */
 
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)")
 
67
{
 
68
  m_score_table.load
 
69
    ( bear::engine::game::get_instance().get_custom_game_file(m_id) );
 
70
 
 
71
  // get the thumbnail
 
72
  std::string thumb_name = m_id;
 
73
 
 
74
  claw::text::replace( thumb_name, std::string(" /"), std::string("_") );
 
75
  std::transform
 
76
    ( thumb_name.begin(), thumb_name.end(), thumb_name.begin(), tolower );
 
77
 
 
78
  m_thumb_filename = "gfx/thumb/" + thumb_name + ".png";
 
79
} // level_information::level_information()
 
80
 
 
81
/*----------------------------------------------------------------------------*/
 
82
/**
 
83
 * \brief Set a field of the level.
 
84
 * \param field The considered field.
 
85
 * \param The value of the field.
 
86
 */
 
87
void ptb::level_information::load
 
88
(const std::string& field, const std::string& value)
 
89
{
 
90
  if ( field == s_level_file_field )
 
91
    m_filename = value;
 
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") );
 
104
  else
 
105
    claw::logger << claw::log_error
 
106
                 << "The field '" << field << "' is unknown."  << std::endl;
 
107
} // level_information::load()
 
108
 
 
109
/*----------------------------------------------------------------------------*/
 
110
/**
 
111
 * \brief Tell if the item is correctly initialized.
 
112
 */
 
113
bool ptb::level_information::is_valid() const
 
114
{
 
115
  return (!m_id.empty()) && (!m_thumb_filename.empty());
 
116
} // level_information::is_valid()
 
117
 
 
118
/*----------------------------------------------------------------------------*/
 
119
/**
 
120
 * \brief Tell if the level is unlocked.
 
121
 */
 
122
bool ptb::level_information::is_unlocked() const
 
123
{
 
124
  return game_variables::get_all_mini_game_unlocked_status()
 
125
    || game_variables::get_mini_game_status( m_id );
 
126
} // level_information::is_unlocked()
 
127
 
 
128
/*----------------------------------------------------------------------------*/
 
129
/**
 
130
 * \brief Get the identifier of the level.
 
131
 */
 
132
const std::string& ptb::level_information::get_id() const
 
133
{
 
134
   return m_id;
 
135
} // level_information::get_id()
 
136
 
 
137
/*----------------------------------------------------------------------------*/
 
138
/**
 
139
 * \brief Get the filename of the level.
 
140
 */
 
141
const std::string& ptb::level_information::get_filename() const
 
142
{
 
143
   return m_filename;
 
144
} // level_information::get_filename()
 
145
 
 
146
/*----------------------------------------------------------------------------*/
 
147
/**
 
148
 * \brief Set the filename of thumb.
 
149
 * \param f The filename.
 
150
 */
 
151
void ptb::level_information::set_thumb_filename(const std::string& f)
 
152
{
 
153
  m_thumb_filename = f;
 
154
} // frame_play_level_information::set_thumb_filename()
 
155
 
 
156
/*----------------------------------------------------------------------------*/
 
157
/**
 
158
 * \brief Get the filename of thumb.
 
159
 */
 
160
const std::string& ptb::level_information::get_thumb_filename() const
 
161
{
 
162
  return m_thumb_filename;
 
163
} // frame_play_level_information::get_thumb_filename()
 
164
 
 
165
/*----------------------------------------------------------------------------*/
 
166
/**
 
167
 * \brief Set informations when the game is locked.
 
168
 * \param info Informations.
 
169
 */
 
170
void ptb::level_information::set_locked_informations(const std::string& info)
 
171
{
 
172
  m_locked_informations = info;
 
173
} // frame_play_level_information::set_locked informations()
 
174
 
 
175
/*----------------------------------------------------------------------------*/
 
176
/**
 
177
 * \brief Set informations when the game is unlocked.
 
178
 * \param info Informations.
 
179
 */
 
180
void ptb::level_information::set_unlocked_informations(const std::string& info)
 
181
{
 
182
  m_unlocked_informations = info;
 
183
} // frame_play_level_information::set_unlocked informations()
 
184
 
 
185
/*----------------------------------------------------------------------------*/
 
186
/**
 
187
 * \brief Get informations of the level.
 
188
 */
 
189
const std::string& ptb::level_information::get_informations() const
 
190
{
 
191
  if ( is_unlocked() )
 
192
    return m_unlocked_informations;
 
193
  else
 
194
    return m_locked_informations;
 
195
} // frame_play_level_information::get_informations()
 
196
 
 
197
/*----------------------------------------------------------------------------*/
 
198
/**
 
199
 * \brief Get records informations of the level.
 
200
 */
 
201
std::string ptb::level_information::get_record_informations() const
 
202
{
 
203
  std::string result;
 
204
 
 
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';
 
208
 
 
209
  return result;
 
210
} // frame_play_level_information::get_record_informations()
 
211
 
 
212
/*----------------------------------------------------------------------------*/
 
213
/**
 
214
 * \brief Tell if the level has already been finished.
 
215
 */
 
216
bool ptb::level_information::is_finished() const
 
217
{
 
218
  return !m_score_table.empty();
 
219
} // frame_play_level_information::is_finished()
 
220
 
 
221
/*----------------------------------------------------------------------------*/
 
222
/**
 
223
 * \brief Get the playability of the level : number of players.
 
224
 */
 
225
ptb::playability_type::value_type
 
226
ptb::level_information::get_playability() const
 
227
{
 
228
  return m_playability;
 
229
} // level_information::get_playability()