X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsupertux%2Fobject_factory.cpp;h=fe6cb0872e97185e06e9f5913977af9f55e9411a;hb=729bc6717bf68314dc9fad25db3a9f728062263e;hp=ea2b35d3a3ec868893475d02eb0e615d9452c289;hpb=2b318b2284a78ae34a6752a807c4eb7b5632299c;p=supertux.git diff --git a/src/supertux/object_factory.cpp b/src/supertux/object_factory.cpp index ea2b35d3a..fe6cb0872 100644 --- a/src/supertux/object_factory.cpp +++ b/src/supertux/object_factory.cpp @@ -23,19 +23,256 @@ #include "util/reader.hpp" #include "supertux/object_factory.hpp" -GameObject* create_object(const std::string& name, const Reader& reader) +#include "badguy/angrystone.hpp" +#include "badguy/badguy.hpp" +#include "badguy/bomb.hpp" +#include "badguy/bouncing_snowball.hpp" +#include "badguy/captainsnowball.hpp" +#include "badguy/crystallo.hpp" +#include "badguy/dart.hpp" +#include "badguy/darttrap.hpp" +#include "badguy/dispenser.hpp" +#include "badguy/fish.hpp" +#include "badguy/flame.hpp" +#include "badguy/flyingsnowball.hpp" +#include "badguy/ghosttree.hpp" +#include "badguy/igel.hpp" +#include "badguy/jumpy.hpp" +#include "badguy/kamikazesnowball.hpp" +#include "badguy/kugelblitz.hpp" +#include "badguy/mole.hpp" +#include "badguy/mole_rock.hpp" +#include "badguy/mrbomb.hpp" +#include "badguy/mriceblock.hpp" +#include "badguy/mrrocket.hpp" +#include "badguy/mrtree.hpp" +#include "badguy/plant.hpp" +#include "badguy/poisonivy.hpp" +#include "badguy/root.hpp" +#include "badguy/skullyhop.hpp" +#include "badguy/smartball.hpp" +#include "badguy/snail.hpp" +#include "badguy/snowball.hpp" +#include "badguy/spidermite.hpp" +#include "badguy/spiky.hpp" +#include "badguy/sspiky.hpp" +#include "badguy/stalactite.hpp" +#include "badguy/stumpy.hpp" +#include "badguy/toad.hpp" +#include "badguy/totem.hpp" +#include "badguy/treewillowisp.hpp" +#include "badguy/walking_badguy.hpp" +#include "badguy/walkingleaf.hpp" +#include "badguy/willowisp.hpp" +#include "badguy/yeti.hpp" +#include "badguy/yeti_stalactite.hpp" +#include "badguy/zeekling.hpp" + +#include "object/ambient_sound.hpp" +#include "object/anchor_point.hpp" +#include "object/background.hpp" +#include "object/bicycle_platform.hpp" +#include "object/block.hpp" +#include "object/bonus_block.hpp" +#include "object/bouncy_coin.hpp" +#include "object/brick.hpp" +#include "object/broken_brick.hpp" +#include "object/bullet.hpp" +#include "object/camera.hpp" +#include "object/candle.hpp" +#include "object/cloud_particle_system.hpp" +#include "object/coin.hpp" +#include "object/comet_particle_system.hpp" +#include "object/decal.hpp" +#include "object/display_effect.hpp" +#include "object/electrifier.hpp" +#include "object/endsequence_fireworks.hpp" +#include "object/endsequence.hpp" +#include "object/endsequence_walkleft.hpp" +#include "object/endsequence_walkright.hpp" +#include "object/explosion.hpp" +#include "object/falling_coin.hpp" +#include "object/firefly.hpp" +#include "object/fireworks.hpp" +#include "object/floating_image.hpp" +#include "object/floating_text.hpp" +#include "object/flower.hpp" +#include "object/ghost_particle_system.hpp" +#include "object/gradient.hpp" +#include "object/growup.hpp" +#include "object/hurting_platform.hpp" +#include "object/icecrusher.hpp" +#include "object/infoblock.hpp" +#include "object/invisible_block.hpp" +#include "object/invisible_wall.hpp" +#include "object/ispy.hpp" +#include "object/lantern.hpp" +#include "object/level_time.hpp" +#include "object/light.hpp" +#include "object/magicblock.hpp" +#include "object/moving_sprite.hpp" +#include "object/oneup.hpp" +#include "object/particles.hpp" +#include "object/particlesystem.hpp" +#include "object/particlesystem_interactive.hpp" +#include "object/path.hpp" +#include "object/path_walker.hpp" +#include "object/platform.hpp" +#include "object/player.hpp" +#include "object/pneumatic_platform.hpp" +#include "object/portable.hpp" +#include "object/powerup.hpp" +#include "object/pulsing_light.hpp" +#include "object/pushbutton.hpp" +#include "object/rain_particle_system.hpp" +#include "object/rainsplash.hpp" +#include "object/rock.hpp" +#include "object/scripted_object.hpp" +#include "object/skull_tile.hpp" +#include "object/smoke_cloud.hpp" +#include "object/snow_particle_system.hpp" +#include "object/specialriser.hpp" +#include "object/spotlight.hpp" +#include "object/sprite_particle.hpp" +#include "object/star.hpp" +#include "object/text_object.hpp" +#include "object/thunderstorm.hpp" +#include "object/tilemap.hpp" +#include "object/trampoline.hpp" +#include "object/unstable_tile.hpp" +#include "object/weak_block.hpp" +#include "object/wind.hpp" + +#include "trigger/climbable.hpp" +#include "trigger/door.hpp" +#include "trigger/scripttrigger.hpp" +#include "trigger/secretarea_trigger.hpp" +#include "trigger/sequence_trigger.hpp" +#include "trigger/switch.hpp" + +ObjectFactory& +ObjectFactory::instance() +{ + static ObjectFactory instance_; + return instance_; +} + +ObjectFactory::ObjectFactory() : + factories() { - Factory::Factories::iterator i = Factory::get_factories().find(name); - if(i == Factory::get_factories().end()) { + init_factories(); +} + +ObjectFactory::~ObjectFactory() +{ +} + +void +ObjectFactory::init_factories() +{ + // badguys + add_factory("angrystone"); + add_factory("bouncingsnowball"); + add_factory("captainsnowball"); + add_factory("crystallo"); + add_factory("dart"); + add_factory("darttrap"); + add_factory("dispenser"); + add_factory("fish"); + add_factory("flame"); + add_factory("flyingsnowball"); + add_factory("ghosttree"); + add_factory("igel"); + add_factory("jumpy"); + add_factory("kamikazesnowball"); + add_factory("kugelblitz"); + add_factory("mole"); + add_factory("mole_rock"); + add_factory("mrbomb"); + add_factory("mriceblock"); + add_factory("mrrocket"); + add_factory("mrtree"); + add_factory("plant"); + add_factory("poisonivy"); + add_factory("sspiky"); + add_factory("skullyhop"); + add_factory("smartball"); + add_factory("snail"); + add_factory("snowball"); + add_factory("spidermite"); + add_factory("spiky"); + add_factory("stalactite"); + add_factory("stumpy"); + add_factory("toad"); + add_factory("totem"); + add_factory("walkingleaf"); + add_factory("willowisp"); + add_factory("yeti"); + add_factory("yeti_stalactite"); + add_factory("zeekling"); + + // other objects + add_factory("ambient_sound"); + add_factory("background"); + add_factory("bicycle-platform"); + add_factory("bonusblock"); + add_factory("candle"); + add_factory("coin"); + add_factory("decal"); + add_factory("explosion"); + add_factory("firefly"); + add_factory("gradient"); + add_factory("hurting_platform"); + add_factory("icecrusher"); + add_factory("infoblock"); + add_factory("invisible_wall"); + add_factory("ispy"); + add_factory("lantern"); + add_factory("leveltime"); + add_factory("magicblock"); + add_factory("platform"); + add_factory("pneumatic-platform"); + add_factory("powerup"); + add_factory("pushbutton"); + add_factory("rock"); + add_factory("scriptedobject"); + add_factory("skull_tile"); + add_factory("spotlight"); + add_factory("thunderstorm"); + add_factory("tilemap"); + add_factory("trampoline"); + add_factory("unstable_tile"); + add_factory("weak_block"); + add_factory("wind"); + + // trigger + add_factory("climbable"); + add_factory("door"); + add_factory("scripttrigger"); + add_factory("secretarea"); + add_factory("sequencetrigger"); + add_factory("switch"); +} + +GameObject* +ObjectFactory::create(const std::string& name, const Reader& reader) +{ + Factories::iterator i = factories.find(name); + + if (i == factories.end()) + { std::stringstream msg; msg << "No factory for object '" << name << "' found."; throw std::runtime_error(msg.str()); } - - return i->second->create_object(reader); + else + { + return i->second->create(reader); + } } -GameObject* create_object(const std::string& name, const Vector& pos, const Direction dir) +GameObject* +ObjectFactory::create(const std::string& name, const Vector& pos, const Direction dir) { std::stringstream lisptext; lisptext << "((x " << pos.x << ")" @@ -45,8 +282,8 @@ GameObject* create_object(const std::string& name, const Vector& pos, const Dire lisp::Parser parser; const lisp::Lisp* lisp = parser.parse(lisptext, "create_object"); - GameObject* object = create_object(name, *(lisp->get_car())); - + + GameObject* object = create(name, *(lisp->get_car())); return object; }