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/icecrusher.hpp"
36 #include "badguy/iceflame.hpp"
37 #include "badguy/igel.hpp"
38 #include "badguy/jumpy.hpp"
39 #include "badguy/kamikazesnowball.hpp"
40 #include "badguy/kugelblitz.hpp"
41 #include "badguy/livefire.hpp"
42 #include "badguy/mole.hpp"
43 #include "badguy/mole_rock.hpp"
44 #include "badguy/mrbomb.hpp"
45 #include "badguy/mrtree.hpp"
46 #include "badguy/owl.hpp"
47 #include "badguy/plant.hpp"
48 #include "badguy/poisonivy.hpp"
49 #include "badguy/rcrystallo.hpp"
50 #include "badguy/short_fuse.hpp"
51 #include "badguy/skullyhop.hpp"
52 #include "badguy/skydive.hpp"
53 #include "badguy/smartball.hpp"
54 #include "badguy/smartblock.hpp"
55 #include "badguy/snail.hpp"
56 #include "badguy/snowball.hpp"
57 #include "badguy/snowman.hpp"
58 #include "badguy/spidermite.hpp"
59 #include "badguy/scrystallo.hpp"
60 #include "badguy/spiky.hpp"
61 #include "badguy/sspiky.hpp"
62 #include "badguy/stalactite.hpp"
63 #include "badguy/stumpy.hpp"
64 #include "badguy/toad.hpp"
65 #include "badguy/totem.hpp"
66 #include "badguy/walking_candle.hpp"
67 #include "badguy/walkingleaf.hpp"
68 #include "badguy/willowisp.hpp"
69 #include "badguy/yeti.hpp"
70 #include "badguy/yeti_stalactite.hpp"
71 #include "badguy/zeekling.hpp"
72 #include "editor/worldmap_objects.hpp"
73 #include "math/vector.hpp"
74 #include "object/ambient_light.hpp"
75 #include "object/ambient_sound.hpp"
76 #include "object/background.hpp"
77 #include "object/bicycle_platform.hpp"
78 #include "object/bonus_block.hpp"
79 #include "object/brick.hpp"
80 #include "object/bumper.hpp"
81 #include "object/camera.hpp"
82 #include "object/candle.hpp"
83 #include "object/circleplatform.hpp"
84 #include "object/cloud_particle_system.hpp"
85 #include "object/custom_particle_system.hpp"
86 #include "object/custom_particle_system_file.hpp"
87 #include "object/coin.hpp"
88 #include "object/decal.hpp"
89 #include "object/explosion.hpp"
90 #include "object/fallblock.hpp"
91 #include "object/firefly.hpp"
92 #include "object/ghost_particle_system.hpp"
93 #include "object/gradient.hpp"
94 #include "object/hurting_platform.hpp"
95 #include "object/infoblock.hpp"
96 #include "object/invisible_block.hpp"
97 #include "object/invisible_wall.hpp"
98 #include "object/ispy.hpp"
99 #include "object/lantern.hpp"
100 #include "object/level_time.hpp"
101 #include "object/magicblock.hpp"
102 #include "object/path_gameobject.hpp"
103 #include "object/particle_zone.hpp"
104 #include "object/platform.hpp"
105 #include "object/pneumatic_platform.hpp"
106 #include "object/powerup.hpp"
107 #include "object/pushbutton.hpp"
108 #include "object/rain_particle_system.hpp"
109 #include "object/rublight.hpp"
110 #include "object/rusty_trampoline.hpp"
111 #include "object/scripted_object.hpp"
112 #include "object/shard.hpp"
113 #include "object/skull_tile.hpp"
114 #include "object/snow_particle_system.hpp"
115 #include "object/spawnpoint.hpp"
116 #include "object/spotlight.hpp"
117 #include "object/text_array_object.hpp"
118 #include "object/textscroller.hpp"
119 #include "object/thunderstorm.hpp"
120 #include "object/tilemap.hpp"
121 #include "object/torch.hpp"
122 #include "object/trampoline.hpp"
123 #include "object/unstable_tile.hpp"
124 #include "object/weak_block.hpp"
125 #include "object/wind.hpp"
126 #include "supertux/level.hpp"
127 #include "supertux/tile_manager.hpp"
128 #include "trigger/climbable.hpp"
129 #include "trigger/door.hpp"
130 #include "trigger/scripttrigger.hpp"
131 #include "trigger/secretarea_trigger.hpp"
132 #include "trigger/sequence_trigger.hpp"
133 #include "trigger/switch.hpp"
134 #include "util/reader_document.hpp"
135 #include "util/reader_mapping.hpp"
136 
137 GameObjectFactory&
instance()138 GameObjectFactory::instance()
139 {
140   static GameObjectFactory instance_;
141   return instance_;
142 }
143 
GameObjectFactory()144 GameObjectFactory::GameObjectFactory()
145 {
146   init_factories();
147 }
148 
149 void
init_factories()150 GameObjectFactory::init_factories()
151 {
152   // badguys
153   add_factory<AngryStone>("angrystone");
154   add_factory<BouncingSnowball>("bouncingsnowball");
155   add_factory<CaptainSnowball>("captainsnowball");
156   add_factory<Crystallo>("crystallo");
157   add_factory<Dart>("dart");
158   add_factory<DartTrap>("darttrap");
159   add_factory<Dispenser>("dispenser");
160   add_factory<Fish>("fish");
161   add_factory<Flame>("flame");
162   add_factory<FlyingSnowBall>("flyingsnowball");
163   add_factory<Ghostflame>("ghostflame");
164   add_factory<GhostTree>("ghosttree");
165   add_factory<Ghoul>("ghoul");
166   add_factory<GoldBomb>("goldbomb");
167   add_factory<Haywire>("haywire");
168   add_factory<Iceflame>("iceflame");
169   add_factory<Igel>("igel");
170   add_factory<Jumpy>("jumpy");
171   add_factory<KamikazeSnowball>("kamikazesnowball");
172   add_factory<Kugelblitz>("kugelblitz");
173   add_factory<LeafShot>("leafshot");
174   add_factory<LiveFire>("livefire");
175   add_factory<LiveFireAsleep>("livefire_asleep");
176   add_factory<LiveFireDormant>("livefire_dormant");
177   add_factory<Mole>("mole");
178   add_factory<MoleRock>("mole_rock");
179   add_factory<MrBomb>("mrbomb");
180   add_factory<MrIceBlock>("mriceblock");
181   add_factory<MrTree>("mrtree");
182   add_factory<Owl>("owl");
183   add_factory<Plant>("plant");
184   add_factory<PoisonIvy>("poisonivy");
185   add_factory<RCrystallo>("rcrystallo");
186   add_factory<SCrystallo>("scrystallo");
187   add_factory<ShortFuse>("short_fuse");
188   add_factory<SSpiky>("sspiky");
189   add_factory<SkyDive>("skydive");
190   add_factory<SkullyHop>("skullyhop");
191   add_factory<SmartBall>("smartball");
192   add_factory<SmartBlock>("smartblock");
193   add_factory<Snail>("snail");
194   add_factory<SnowBall>("snowball");
195   add_factory<Snowman>("snowman");
196   add_factory<SpiderMite>("spidermite");
197   add_factory<Spiky>("spiky");
198   add_factory<Stalactite>("stalactite");
199   add_factory<Stumpy>("stumpy");
200   add_factory<Toad>("toad");
201   add_factory<Totem>("totem");
202   add_factory<WalkingCandle>("walking_candle");
203   add_factory<WalkingLeaf>("walkingleaf");
204   add_factory<WillOWisp>("willowisp");
205   add_factory<Yeti>("yeti");
206   add_factory<YetiStalactite>("yeti_stalactite");
207   add_factory<Zeekling>("zeekling");
208 
209   // other objects
210   add_factory<AmbientLight>("ambient-light");
211   add_factory<AmbientSound>("ambient_sound"); // backward compatibilty
212   add_factory<AmbientSound>("ambient-sound");
213   add_factory<Background>("background");
214   add_factory<PathGameObject>("path");
215   add_factory<BicyclePlatform>("bicycle-platform");
216   add_factory<BonusBlock>("bonusblock");
217   add_factory<Brick>("brick");
218   add_factory<Bumper>("bumper");
219   add_factory<Camera>("camera");
220   add_factory<Candle>("candle");
221   add_factory<CirclePlatform>("circleplatform");
222   add_factory<CloudParticleSystem>("particles-clouds");
223   add_factory<CustomParticleSystem>("particles-custom");
224   add_factory<CustomParticleSystemFile>("particles-custom-file");
225   add_factory<Coin>("coin");
226   add_factory<Decal>("decal");
227   add_factory<Explosion>("explosion");
228   add_factory<FallBlock>("fallblock");
229   add_factory<Firefly>("firefly");
230   add_factory<GhostParticleSystem>("particles-ghosts");
231   add_factory<Gradient>("gradient");
232   add_factory<HeavyCoin>("heavycoin");
233   add_factory<HurtingPlatform>("hurting_platform");
234   add_factory<IceCrusher>("icecrusher");
235   add_factory<InfoBlock>("infoblock");
236   add_factory<InvisibleBlock>("invisible_block");
237   add_factory<InvisibleWall>("invisible_wall");
238   add_factory<Ispy>("ispy");
239   add_factory<Lantern>("lantern");
240   add_factory<LevelTime>("leveltime");
241   add_factory<MagicBlock>("magicblock");
242   add_factory<ParticleZone>("particle-zone");
243   add_factory<Platform>("platform");
244   add_factory<PneumaticPlatform>("pneumatic-platform");
245   add_factory<PowerUp>("powerup");
246   add_factory<PushButton>("pushbutton");
247   add_factory<RainParticleSystem>("particles-rain");
248   add_factory<Rock>("rock");
249   add_factory<RubLight>("rublight");
250   add_factory<ScriptedObject>("scriptedobject");
251   add_factory<Shard>("shard");
252   add_factory<SkullTile>("skull_tile");
253   add_factory<SnowParticleSystem>("particles-snow");
254   add_factory<Spotlight>("spotlight");
255   add_factory<TextScroller>("textscroller");
256   add_factory<TextArrayObject>("text-array");
257   add_factory<Thunderstorm>("thunderstorm");
258   add_factory<Torch>("torch");
259   add_factory<Trampoline>("trampoline");
260   add_factory<RustyTrampoline>("rustytrampoline");
261   add_factory<UnstableTile>("unstable_tile");
262   add_factory<WeakBlock>("weak_block");
263   add_factory<Wind>("wind");
264 
265   // trigger
266   add_factory<Climbable>("climbable");
267   add_factory<Door>("door");
268   add_factory<ScriptTrigger>("scripttrigger");
269   add_factory<SecretAreaTrigger>("secretarea");
270   add_factory<SequenceTrigger>("sequencetrigger");
271   add_factory<Switch>("switch");
272 
273   // editor stuff
274   add_factory<SpawnPointMarker>("spawnpoint");
275 
276   // worldmap editor objects
277   add_factory<worldmap_editor::LevelDot>("level");
278   add_factory<worldmap_editor::SpecialTile>("special-tile");
279   add_factory<worldmap_editor::SpriteChange>("sprite-change");
280   add_factory<worldmap_editor::Teleporter>("teleporter");
281   add_factory<worldmap_editor::WorldmapSpawnPoint>("worldmap-spawnpoint");
282 
283   add_factory("tilemap", [](const ReaderMapping& reader) {
284       auto tileset = TileManager::current()->get_tileset(Level::current()->get_tileset());
285       return std::make_unique<TileMap>(tileset, reader);
286     });
287 }
288 
289 std::unique_ptr<GameObject>
create(const std::string & name,const Vector & pos,const Direction & dir,const std::string & data) const290 GameObjectFactory::create(const std::string& name, const Vector& pos, const Direction& dir, const std::string& data) const
291 {
292   std::stringstream lisptext;
293   lisptext << "(" << name << "\n"
294            << " (x " << pos.x << ")"
295            << " (y " << pos.y << ")" << data;
296   if (dir != Direction::AUTO) {
297     lisptext << " (direction \"" << dir << "\"))";
298   } else {
299     lisptext << ")";
300   }
301 
302   auto doc = ReaderDocument::from_stream(lisptext);
303   return create(name, doc.get_root().get_mapping());
304 }
305 
306 /* EOF */
307