Common new script interface
parent
779ad3c5c1
commit
d93a1cdf03
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#if !defined(_MSC_VER) && __cplusplus < 201402L
|
||||
namespace std
|
||||
{
|
||||
template<typename T, typename... Args>
|
||||
std::unique_ptr<T> make_unique(Args&&... args)
|
||||
{
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -1,4 +1,6 @@
|
|||
set(SCRIPT_COMMON_SOURCES
|
||||
script.cpp
|
||||
script.h
|
||||
scriptmaps.cpp
|
||||
scriptmaps.h
|
||||
)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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 <memory>
|
||||
#include <celcompat/filesystem.h>
|
||||
|
||||
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<IScript> 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;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue