diff --git a/src/celcompat/memory.h b/src/celcompat/memory.h new file mode 100644 index 00000000..65f3843b --- /dev/null +++ b/src/celcompat/memory.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +#if !defined(_MSC_VER) && __cplusplus < 201402L +namespace std +{ +template +std::unique_ptr make_unique(Args&&... args) +{ + return std::unique_ptr(new T(std::forward(args)...)); +} +} +#endif diff --git a/src/celscript/common/CMakeLists.txt b/src/celscript/common/CMakeLists.txt index b300ecf3..74a81857 100644 --- a/src/celscript/common/CMakeLists.txt +++ b/src/celscript/common/CMakeLists.txt @@ -1,4 +1,6 @@ set(SCRIPT_COMMON_SOURCES + script.cpp + script.h scriptmaps.cpp scriptmaps.h ) diff --git a/src/celscript/common/script.cpp b/src/celscript/common/script.cpp new file mode 100644 index 00000000..039f4f93 --- /dev/null +++ b/src/celscript/common/script.cpp @@ -0,0 +1,38 @@ +// script.cpp +// +// Copyright (C) 2019, the Celestia Development Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +#include "script.h" + +namespace celestia +{ +namespace scripts +{ + +bool IScript::handleMouseButtonEvent(float x, float y, int button, bool down) +{ + return false; +} + +bool IScript::charEntered(const char*) +{ + return false; +} + +bool IScript::handleKeyEvent(const char* key) +{ + return false; +} + +bool IScript::handleTickEvent(double dt) +{ + return false; +} + +} +} diff --git a/src/celscript/common/script.h b/src/celscript/common/script.h new file mode 100644 index 00000000..c05f57ff --- /dev/null +++ b/src/celscript/common/script.h @@ -0,0 +1,78 @@ +// script.h +// +// Copyright (C) 2019, the Celestia Development Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +#pragma once + +#include +#include + +class CelestiaCore; + +namespace celestia +{ +namespace scripts +{ + +class IScript +{ + public: + virtual ~IScript() = default; + + virtual bool handleMouseButtonEvent(float x, float y, int button, bool down); + virtual bool charEntered(const char*); + virtual bool handleKeyEvent(const char* key); + virtual bool handleTickEvent(double dt); + virtual bool tick(double) = 0; +}; + +class IScriptPlugin +{ + public: + IScriptPlugin() = delete; + IScriptPlugin(CelestiaCore *appcore) : m_appCore(appcore) {}; + IScriptPlugin(const IScriptPlugin&) = delete; + IScriptPlugin(IScriptPlugin&&) = delete; + IScriptPlugin& operator=(const IScriptPlugin&) = delete; + IScriptPlugin& operator=(IScriptPlugin&&) = delete; + virtual ~IScriptPlugin() = default; + + virtual bool isOurFile(const fs::path&) const = 0; + virtual std::unique_ptr loadScript(const fs::path&) = 0; + + CelestiaCore *appCore() const { return m_appCore; } + + private: + CelestiaCore *m_appCore; +}; + +class IScriptHook +{ + public: + IScriptHook() = delete; + IScriptHook(CelestiaCore *appcore) : m_appCore(appcore) {}; + IScriptHook(const IScriptHook&) = default; + IScriptHook(IScriptHook&&) = default; + IScriptHook& operator=(const IScriptHook&) = default; + IScriptHook& operator=(IScriptHook&&) = default; + virtual ~IScriptHook() = default; + + virtual bool call(const char *method) const = 0; + virtual bool call(const char *method, const char *keyName) const = 0; + virtual bool call(const char *method, float x, float y) const = 0; + virtual bool call(const char *method, float x, float y, int b) const = 0; + virtual bool call(const char *method, double dt) const = 0; + + CelestiaCore *appCore() const { return m_appCore; } + + private: + CelestiaCore *m_appCore; +}; + +} +}