diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-21 14:02:34 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-21 14:02:34 +0200 |
commit | fe8f7273f0efdfe319a0d3e3b2fc2847992745af (patch) | |
tree | 9f56560c8a35c3e281881fa48cd79b26f8e8de7e /TileBehaviorFactory.cpp | |
parent | 4cb7ca42003c177e3acc80075d7594e555966106 (diff) |
fix more design
Diffstat (limited to 'TileBehaviorFactory.cpp')
-rw-r--r-- | TileBehaviorFactory.cpp | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/TileBehaviorFactory.cpp b/TileBehaviorFactory.cpp index 99301ac..b795578 100644 --- a/TileBehaviorFactory.cpp +++ b/TileBehaviorFactory.cpp @@ -1,20 +1,30 @@ +#include <memory> + #include "TileBehaviorFactory.h" -#include "Exception.h" +#include "CreateArtistTileBehavior.h" +#include "DeleteArtistTileBehavior.h" +#include "NullTileBehavior.h" +#include "SetNeighborTileBehavior.h" +#include "StepTileBehavior.h" using namespace std; -TileBehavior & TileBehaviorFactory::get_strategy(string type) { - auto & type_map = TileBehaviorFactory::get_collection(); +TileBehaviorFactory::TileBehaviorFactory(Museum & m) : museum(m) {}; - if (type_map.contains(type)) - return *type_map.at(type); - - throw Exception("unknown behavior for tile type \"%s\"", type.c_str()); -} +unique_ptr<TileBehavior> TileBehaviorFactory::create(string type) { + TileBehavior * out = nullptr; -void TileBehaviorFactory::register_strategy(string type, TileBehavior * strategy) { - auto & type_map = TileBehaviorFactory::get_collection(); + if (type == SetNeighborTileBehavior::type) + out = new SetNeighborTileBehavior(this->museum); + else if (type == CreateArtistTileBehavior::type) + out = new CreateArtistTileBehavior(this->museum); + else if (type == StepTileBehavior::type) + out = new StepTileBehavior(this->museum); + else if (type == DeleteArtistTileBehavior::type) + out = new DeleteArtistTileBehavior(this->museum); - type_map[type] = strategy; + if (out == nullptr) + out = new NullTileBehavior(this->museum); + return unique_ptr<TileBehavior>(out); } |