1// SuperTux
2// Copyright (C) 2018 Ingo Ruhnke <grumbel@gmail.com>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17#include "supertux/game_object_factory.hpp"
18
19#include "audio/sound_source.hpp"
20#include "badguy/angrystone.hpp"
21#include "badguy/bouncing_snowball.hpp"
22#include "badguy/captainsnowball.hpp"
23#include "badguy/crystallo.hpp"
24#include "badguy/dart.hpp"
25#include "badguy/darttrap.hpp"
26#include "badguy/dispenser.hpp"
27#include "badguy/fish.hpp"
28#include "badguy/flame.hpp"
29#include "badguy/flyingsnowball.hpp"
30#include "badguy/ghostflame.hpp"
31#include "badguy/ghosttree.hpp"
32#include "badguy/ghoul.hpp"
33#include "badguy/goldbomb.hpp"
34#include "badguy/haywire.hpp"
35#include "badguy/iceflame.hpp"
36#include "badguy/igel.hpp"
37#include "badguy/jumpy.hpp"
38#include "badguy/kamikazesnowball.hpp"
39#include "badguy/kugelblitz.hpp"
40#include "badguy/livefire.hpp"
41#include "badguy/mole.hpp"
42#include "badguy/mole_rock.hpp"
43#include "badguy/mrbomb.hpp"
44#include "badguy/mrtree.hpp"
45#include "badguy/owl.hpp"
46#include "badguy/plant.hpp"
47#include "badguy/poisonivy.hpp"
48#include "badguy/short_fuse.hpp"
49#include "badguy/skullyhop.hpp"
50#include "badguy/skydive.hpp"
51#include "badguy/smartball.hpp"
52#include "badguy/smartblock.hpp"
53#include "badguy/snail.hpp"
54#include "badguy/snowball.hpp"
55#include "badguy/snowman.hpp"
56#include "badguy/spidermite.hpp"
57#include "badguy/spiky.hpp"
58#include "badguy/sspiky.hpp"
59#include "badguy/stalactite.hpp"
60#include "badguy/stumpy.hpp"
61#include "badguy/toad.hpp"
62#include "badguy/totem.hpp"
63#include "badguy/walking_candle.hpp"
64#include "badguy/walkingleaf.hpp"
65#include "badguy/willowisp.hpp"
66#include "badguy/yeti.hpp"
67#include "badguy/yeti_stalactite.hpp"
68#include "badguy/zeekling.hpp"
69#include "editor/worldmap_objects.hpp"
70#include "math/vector.hpp"
71#include "object/ambient_light.hpp"
72#include "object/ambient_sound.hpp"
73#include "object/background.hpp"
74#include "object/bicycle_platform.hpp"
75#include "object/bonus_block.hpp"
76#include "object/brick.hpp"
77#include "object/camera.hpp"
78#include "object/candle.hpp"
79#include "object/cloud_particle_system.hpp"
80#include "object/coin.hpp"
81#include "object/decal.hpp"
82#include "object/explosion.hpp"
83#include "object/firefly.hpp"
84#include "object/ghost_particle_system.hpp"
85#include "object/gradient.hpp"
86#include "object/hurting_platform.hpp"
87#include "object/icecrusher.hpp"
88#include "object/infoblock.hpp"
89#include "object/invisible_block.hpp"
90#include "object/invisible_wall.hpp"
91#include "object/ispy.hpp"
92#include "object/lantern.hpp"
93#include "object/level_time.hpp"
94#include "object/magicblock.hpp"
95#include "object/path_gameobject.hpp"
96#include "object/platform.hpp"
97#include "object/pneumatic_platform.hpp"
98#include "object/powerup.hpp"
99#include "object/pushbutton.hpp"
100#include "object/rain_particle_system.hpp"
101#include "object/rusty_trampoline.hpp"
102#include "object/scripted_object.hpp"
103#include "object/skull_tile.hpp"
104#include "object/snow_particle_system.hpp"
105#include "object/spawnpoint.hpp"
106#include "object/spotlight.hpp"
107#include "object/text_array_object.hpp"
108#include "object/textscroller.hpp"
109#include "object/thunderstorm.hpp"
110#include "object/tilemap.hpp"
111#include "object/torch.hpp"
112#include "object/trampoline.hpp"
113#include "object/unstable_tile.hpp"
114#include "object/weak_block.hpp"
115#include "object/wind.hpp"
116#include "supertux/level.hpp"
117#include "supertux/tile_manager.hpp"
118#include "trigger/climbable.hpp"
119#include "trigger/door.hpp"
120#include "trigger/scripttrigger.hpp"
121#include "trigger/secretarea_trigger.hpp"
122#include "trigger/sequence_trigger.hpp"
123#include "trigger/switch.hpp"
124#include "util/reader_document.hpp"
125#include "util/reader_mapping.hpp"
126
127GameObjectFactory&
128GameObjectFactory::instance()
129{
130 static GameObjectFactory instance_;
131 return instance_;
132}
133
134GameObjectFactory::GameObjectFactory()
135{
136 init_factories();
137}
138
139void
140GameObjectFactory::init_factories()
141{
142 // badguys
143 add_factory<AngryStone>("angrystone");
144 add_factory<BouncingSnowball>("bouncingsnowball");
145 add_factory<CaptainSnowball>("captainsnowball");
146 add_factory<Crystallo>("crystallo");
147 add_factory<Dart>("dart");
148 add_factory<DartTrap>("darttrap");
149 add_factory<Dispenser>("dispenser");
150 add_factory<Fish>("fish");
151 add_factory<Flame>("flame");
152 add_factory<FlyingSnowBall>("flyingsnowball");
153 add_factory<Ghostflame>("ghostflame");
154 add_factory<GhostTree>("ghosttree");
155 add_factory<Ghoul>("ghoul");
156 add_factory<GoldBomb>("goldbomb");
157 add_factory<Haywire>("haywire");
158 add_factory<Iceflame>("iceflame");
159 add_factory<Igel>("igel");
160 add_factory<Jumpy>("jumpy");
161 add_factory<KamikazeSnowball>("kamikazesnowball");
162 add_factory<Kugelblitz>("kugelblitz");
163 add_factory<LeafShot>("leafshot");
164 add_factory<LiveFire>("livefire");
165 add_factory<LiveFireAsleep>("livefire_asleep");
166 add_factory<LiveFireDormant>("livefire_dormant");
167 add_factory<Mole>("mole");
168 add_factory<MoleRock>("mole_rock");
169 add_factory<MrBomb>("mrbomb");
170 add_factory<MrIceBlock>("mriceblock");
171 add_factory<MrTree>("mrtree");
172 add_factory<Owl>("owl");
173 add_factory<Plant>("plant");
174 add_factory<PoisonIvy>("poisonivy");
175 add_factory<ShortFuse>("short_fuse");
176 add_factory<SSpiky>("sspiky");
177 add_factory<SkyDive>("skydive");
178 add_factory<SkullyHop>("skullyhop");
179 add_factory<SmartBall>("smartball");
180 add_factory<SmartBlock>("smartblock");
181 add_factory<Snail>("snail");
182 add_factory<SnowBall>("snowball");
183 add_factory<Snowman>("snowman");
184 add_factory<SpiderMite>("spidermite");
185 add_factory<Spiky>("spiky");
186 add_factory<Stalactite>("stalactite");
187 add_factory<Stumpy>("stumpy");
188 add_factory<Toad>("toad");
189 add_factory<Totem>("totem");
190 add_factory<WalkingCandle>("walking_candle");
191 add_factory<WalkingLeaf>("walkingleaf");
192 add_factory<WillOWisp>("willowisp");
193 add_factory<Yeti>("yeti");
194 add_factory<YetiStalactite>("yeti_stalactite");
195 add_factory<Zeekling>("zeekling");
196
197 // other objects
198 add_factory<AmbientLight>("ambient-light");
199 add_factory<AmbientSound>("ambient_sound"); // backward compatibilty
200 add_factory<AmbientSound>("ambient-sound");
201 add_factory<Background>("background");
202 add_factory<PathGameObject>("path");
203 add_factory<BicyclePlatform>("bicycle-platform");
204 add_factory<BonusBlock>("bonusblock");
205 add_factory<Brick>("brick");
206 add_factory<Camera>("camera");
207 add_factory<Candle>("candle");
208 add_factory<CloudParticleSystem>("particles-clouds");
209 add_factory<Coin>("coin");
210 add_factory<Decal>("decal");
211 add_factory<Explosion>("explosion");
212 add_factory<Firefly>("firefly");
213 add_factory<GhostParticleSystem>("particles-ghosts");
214 add_factory<Gradient>("gradient");
215 add_factory<HeavyCoin>("heavycoin");
216 add_factory<HurtingPlatform>("hurting_platform");
217 add_factory<IceCrusher>("icecrusher");
218 add_factory<InfoBlock>("infoblock");
219 add_factory<InvisibleBlock>("invisible_block");
220 add_factory<InvisibleWall>("invisible_wall");
221 add_factory<Ispy>("ispy");
222 add_factory<Lantern>("lantern");
223 add_factory<LevelTime>("leveltime");
224 add_factory<MagicBlock>("magicblock");
225 add_factory<Platform>("platform");
226 add_factory<PneumaticPlatform>("pneumatic-platform");
227 add_factory<PowerUp>("powerup");
228 add_factory<PushButton>("pushbutton");
229 add_factory<RainParticleSystem>("particles-rain");
230 add_factory<Rock>("rock");
231 add_factory<ScriptedObject>("scriptedobject");
232 add_factory<SkullTile>("skull_tile");
233 add_factory<SnowParticleSystem>("particles-snow");
234 add_factory<Spotlight>("spotlight");
235 add_factory<TextScroller>("textscroller");
236 add_factory<TextArrayObject>("text-array");
237 add_factory<Thunderstorm>("thunderstorm");
238 add_factory<Torch>("torch");
239 add_factory<Trampoline>("trampoline");
240 add_factory<RustyTrampoline>("rustytrampoline");
241 add_factory<UnstableTile>("unstable_tile");
242 add_factory<WeakBlock>("weak_block");
243 add_factory<Wind>("wind");
244
245 // trigger
246 add_factory<Climbable>("climbable");
247 add_factory<Door>("door");
248 add_factory<ScriptTrigger>("scripttrigger");
249 add_factory<SecretAreaTrigger>("secretarea");
250 add_factory<SequenceTrigger>("sequencetrigger");
251 add_factory<Switch>("switch");
252
253 // editor stuff
254 add_factory<SpawnPointMarker>("spawnpoint");
255
256 // worldmap editor objects
257 add_factory<worldmap_editor::LevelDot>("level");
258 add_factory<worldmap_editor::SpecialTile>("special-tile");
259 add_factory<worldmap_editor::SpriteChange>("sprite-change");
260 add_factory<worldmap_editor::Teleporter>("teleporter");
261 add_factory<worldmap_editor::WorldmapSpawnPoint>("worldmap-spawnpoint");
262
263 add_factory("tilemap", [](const ReaderMapping& reader) {
264 auto tileset = TileManager::current()->get_tileset(Level::current()->get_tileset());
265 return std::make_unique<TileMap>(tileset, reader);
266 });
267}
268
269std::unique_ptr<GameObject>
270GameObjectFactory::create(const std::string& name, const Vector& pos, const Direction& dir, const std::string& data) const
271{
272 std::stringstream lisptext;
273 lisptext << "(" << name << "\n"
274 << " (x " << pos.x << ")"
275 << " (y " << pos.y << ")" << data;
276 if (dir != Direction::AUTO) {
277 lisptext << " (direction \"" << dir << "\"))";
278 } else {
279 lisptext << ")";
280 }
281
282 auto doc = ReaderDocument::from_stream(lisptext);
283 return create(name, doc.get_root().get_mapping());
284}
285
286/* EOF */
287