mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-10-10 09:28:06 +00:00
Initial work on LUA scripting.
This LUA scripting implementation uses the sol header only C++ wrapper for the native LUA libraries. The API does not follow the original LU scripting. Each instance of a script is in its own LUA-State, and has 'self' as a global. There are hooks to all the implemented CppScript methods, as well as a subset of the entity functionallity. Has to be expanded upon. This is local work which has been sitting for awhile; thought someone might like to take a look at it.
This commit is contained in:
@@ -812,6 +812,10 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr
|
||||
return script;
|
||||
}
|
||||
|
||||
CppScripts::Script* CppScripts::GetInvalidScript() {
|
||||
return invalidToReturn;
|
||||
}
|
||||
|
||||
std::vector<CppScripts::Script*> CppScripts::GetEntityScripts(Entity* entity) {
|
||||
std::vector<CppScripts::Script*> scripts;
|
||||
std::vector<ScriptComponent*> comps = entity->GetScriptComponents();
|
||||
|
@@ -320,6 +320,7 @@ namespace CppScripts {
|
||||
float_t pathTime, float_t totalTime, int32_t waypoint) {};
|
||||
};
|
||||
|
||||
Script* GetInvalidScript();
|
||||
Script* GetScript(Entity* parent, const std::string& scriptName);
|
||||
std::vector<Script*> GetEntityScripts(Entity* entity);
|
||||
};
|
@@ -14,11 +14,22 @@ ScriptComponent::ScriptComponent(Entity* parent, std::string scriptName, bool se
|
||||
SetScript(scriptName);
|
||||
}
|
||||
|
||||
ScriptComponent::ScriptComponent(Entity* parent, bool serialized, bool client) : Component(parent) {
|
||||
m_Serialized = serialized;
|
||||
m_Client = client;
|
||||
|
||||
m_Script = nullptr;
|
||||
}
|
||||
|
||||
ScriptComponent::~ScriptComponent() {
|
||||
|
||||
}
|
||||
|
||||
void ScriptComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
if (!m_Serialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (bIsInitialUpdate) {
|
||||
const auto& networkSettings = m_Parent->GetNetworkSettings();
|
||||
auto hasNetworkSettings = !networkSettings.empty();
|
||||
@@ -55,3 +66,7 @@ void ScriptComponent::SetScript(const std::string& scriptName) {
|
||||
|
||||
m_Script = CppScripts::GetScript(m_Parent, scriptName);
|
||||
}
|
||||
|
||||
void ScriptComponent::SetScript(CppScripts::Script* script) {
|
||||
m_Script = script;
|
||||
}
|
||||
|
@@ -20,7 +20,8 @@ class Entity;
|
||||
class ScriptComponent : public Component {
|
||||
public:
|
||||
static const uint32_t ComponentType = COMPONENT_TYPE_SCRIPT;
|
||||
|
||||
|
||||
ScriptComponent(Entity* parent, bool serialized, bool client = false);
|
||||
ScriptComponent(Entity* parent, std::string scriptName, bool serialized, bool client = false);
|
||||
~ScriptComponent() override;
|
||||
|
||||
@@ -44,6 +45,12 @@ public:
|
||||
*/
|
||||
void SetScript(const std::string& scriptName);
|
||||
|
||||
/**
|
||||
* Sets the script directly
|
||||
* @param script the script to set
|
||||
*/
|
||||
void SetScript(CppScripts::Script* script);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user