aboutsummaryrefslogtreecommitdiff
path: root/TileBehaviorFactory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'TileBehaviorFactory.cpp')
-rw-r--r--TileBehaviorFactory.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/TileBehaviorFactory.cpp b/TileBehaviorFactory.cpp
new file mode 100644
index 0000000..99301ac
--- /dev/null
+++ b/TileBehaviorFactory.cpp
@@ -0,0 +1,20 @@
+#include "TileBehaviorFactory.h"
+#include "Exception.h"
+
+using namespace std;
+
+TileBehavior & TileBehaviorFactory::get_strategy(string type) {
+ auto & type_map = TileBehaviorFactory::get_collection();
+
+ if (type_map.contains(type))
+ return *type_map.at(type);
+
+ throw Exception("unknown behavior for tile type \"%s\"", type.c_str());
+}
+
+void TileBehaviorFactory::register_strategy(string type, TileBehavior * strategy) {
+ auto & type_map = TileBehaviorFactory::get_collection();
+
+ type_map[type] = strategy;
+}
+