1 | // SuperTux |
2 | // Copyright (C) 2004 Ingo Ruhnke <grumbel@gmail.com> |
3 | // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de> |
4 | // |
5 | // This program is free software: you can redistribute it and/or modify |
6 | // it under the terms of the GNU General Public License as published by |
7 | // the Free Software Foundation, either version 3 of the License, or |
8 | // (at your option) any later version. |
9 | // |
10 | // This program is distributed in the hope that it will be useful, |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | // GNU General Public License for more details. |
14 | // |
15 | // You should have received a copy of the GNU General Public License |
16 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | |
18 | #include "worldmap/level_tile.hpp" |
19 | |
20 | #include <physfs.h> |
21 | |
22 | #include "sprite/sprite.hpp" |
23 | #include "sprite/sprite_manager.hpp" |
24 | #include "util/file_system.hpp" |
25 | #include "util/log.hpp" |
26 | #include "util/reader_mapping.hpp" |
27 | #include "worldmap/worldmap.hpp" |
28 | |
29 | namespace worldmap { |
30 | |
31 | LevelTile::LevelTile(const std::string& basedir, const ReaderMapping& mapping) : |
32 | GameObject(mapping), |
33 | m_pos(), |
34 | m_basedir(basedir), |
35 | m_level_filename(), |
36 | m_title(), |
37 | m_auto_play(false), |
38 | m_target_time(), |
39 | m_extro_script(), |
40 | m_solved(false), |
41 | m_perfect(false), |
42 | m_statistics(), |
43 | m_sprite(), |
44 | m_title_color(WorldMap::level_title_color) |
45 | { |
46 | if (!mapping.get("level" , m_level_filename)) { |
47 | // Hack for backward compatibility with 0.5.x level |
48 | m_level_filename = m_name; |
49 | } |
50 | |
51 | mapping.get("x" , m_pos.x); |
52 | mapping.get("y" , m_pos.y); |
53 | mapping.get("auto-play" , m_auto_play); |
54 | |
55 | std::string spritefile = "images/worldmap/common/leveldot.sprite" ; |
56 | mapping.get("sprite" , spritefile); |
57 | m_sprite = SpriteManager::current()->create(spritefile); |
58 | |
59 | mapping.get("extro-script" , m_extro_script); |
60 | |
61 | std::vector<float> vColor; |
62 | if (mapping.get("color" , vColor)) { |
63 | m_title_color = Color(vColor); |
64 | } |
65 | |
66 | if (m_basedir == "./" ) { |
67 | m_basedir = "" ; |
68 | } |
69 | |
70 | if (!PHYSFS_exists(FileSystem::join(m_basedir, m_level_filename).c_str())) |
71 | { |
72 | log_warning << "level file '" << m_level_filename |
73 | << "' does not exist and will not be added to the worldmap" << std::endl; |
74 | return; |
75 | } |
76 | } |
77 | |
78 | LevelTile::~LevelTile() |
79 | { |
80 | } |
81 | |
82 | void |
83 | LevelTile::draw(DrawingContext& context) |
84 | { |
85 | m_sprite->draw(context.color(), m_pos * 32 + Vector(16, 16), LAYER_OBJECTS - 1); |
86 | } |
87 | |
88 | void |
89 | LevelTile::update(float ) |
90 | { |
91 | } |
92 | |
93 | void |
94 | LevelTile::update_sprite_action() |
95 | { |
96 | if (!m_solved) { |
97 | m_sprite->set_action("default" ); |
98 | } else { |
99 | m_sprite->set_action((m_sprite->has_action("perfect" ) && m_perfect) ? "perfect" : "solved" ); |
100 | } |
101 | } |
102 | |
103 | void |
104 | LevelTile::set_solved(bool v) |
105 | { |
106 | m_solved = v; |
107 | update_sprite_action(); |
108 | } |
109 | |
110 | void |
111 | LevelTile::set_perfect(bool v) |
112 | { |
113 | m_perfect = v; |
114 | update_sprite_action(); |
115 | } |
116 | |
117 | } // namespace worldmap |
118 | |
119 | /* EOF */ |
120 | |