summaryrefslogtreecommitdiffstats
path: root/src/control/MapContext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/control/MapContext.cpp')
-rw-r--r--src/control/MapContext.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/control/MapContext.cpp b/src/control/MapContext.cpp
index 6ba3b6b..f7ad2fe 100644
--- a/src/control/MapContext.cpp
+++ b/src/control/MapContext.cpp
@@ -31,10 +31,13 @@ namespace RPGEdit {
namespace Control {
-MapContext::MapContext(EventBus *eventBus0, InputHandler *inputHandler0, const std::shared_ptr<View::Window> &window, const Model::Map &map0)
- : eventBus(eventBus0), inputHandler(inputHandler0), map(map0) {
+MapContext::MapContext(EventBus *eventBus0, InputHandler *inputHandler0, ScriptContext *scriptContext0, const std::shared_ptr<View::Window> &window, const Model::Map &map0)
+ : eventBus(eventBus0), inputHandler(inputHandler0), scriptContext(scriptContext0), map(map0) {
view = std::unique_ptr<View::MapView>(new View::MapView(window, map.getTileset()));
+ Model::Entity *square = map.addEntity("square", Model::Position<int>{10, 10});
+ square->setScriptInteract("interact", "interact");
+
playerEntity = map.addEntity("square", Model::Position<int>{8, 8});
view->updateEntities(map.getEntities());
@@ -80,7 +83,12 @@ void MapContext::interact(uint64_t time) {
if (!target)
return;
- target->interact(time);
+ const std::pair<std::string, std::string> &interactScript = target->getScriptInteract();
+ if (interactScript.first.empty())
+ return;
+
+ Model::ScriptNumber scriptTime(time);
+ scriptContext->run(interactScript.first, interactScript.second, nullptr, &scriptTime);
}
void MapContext::keyPressed(uint16_t key, uint64_t time) {