diff --git a/src/engine/internal/engine.cpp b/src/engine/internal/engine.cpp index 8f1d49e9..b9d48496 100644 --- a/src/engine/internal/engine.cpp +++ b/src/engine/internal/engine.cpp @@ -179,8 +179,9 @@ void Engine::frame() void Engine::start() { - if (m_running) - finalize(); + // NOTE: Running scripts should be deleted, but this method will probably be removed anyway + /*if (m_running) + finalize();*/ deleteClones(); @@ -425,11 +426,32 @@ void Engine::setKeyState(const std::string &name, bool pressed) { KeyEvent event(name); m_keyMap[event.name()] = pressed; + + // Start "when key pressed" scripts + if (pressed) { + auto it = m_whenKeyPressedScripts.find(event.name()); + + if (it != m_whenKeyPressedScripts.cend()) + startWhenKeyPressedScripts(it->second); + + it = m_whenKeyPressedScripts.find("any"); + + if (it != m_whenKeyPressedScripts.cend()) + startWhenKeyPressedScripts(it->second); + } } void Engine::setAnyKeyPressed(bool pressed) { m_anyKeyPressed = pressed; + + // Start "when key pressed" scripts + if (pressed) { + auto it = m_whenKeyPressedScripts.find("any"); + + if (it != m_whenKeyPressedScripts.cend()) + startWhenKeyPressedScripts(it->second); + } } double Engine::mouseX() const @@ -947,3 +969,19 @@ void Engine::updateFrameDuration() { m_frameDuration = std::chrono::milliseconds(static_cast(1000 / m_fps)); } + +void Engine::startWhenKeyPressedScripts(const std::vector