mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-06 10:44:08 +00:00
Continued re-integration of Entity::Initialize
This commit is contained in:
@@ -5,18 +5,15 @@
|
||||
|
||||
#include "Entity.h"
|
||||
#include "ScriptComponent.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "CDScriptComponentTable.h"
|
||||
#include "CDZoneTableTable.h"
|
||||
#include "dZoneManager.h"
|
||||
|
||||
ScriptComponent::ScriptComponent(Entity* parent, std::string scriptName, bool serialized, bool client) : Component(parent) {
|
||||
m_Serialized = serialized;
|
||||
m_Client = client;
|
||||
|
||||
ScriptComponent::ScriptComponent(Entity* parent, std::string scriptName) : Component(parent) {
|
||||
SetScript(scriptName);
|
||||
}
|
||||
|
||||
ScriptComponent::~ScriptComponent() {
|
||||
|
||||
}
|
||||
|
||||
void ScriptComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
if (bIsInitialUpdate) {
|
||||
const auto& networkSettings = m_ParentEntity->GetNetworkSettings();
|
||||
@@ -46,11 +43,30 @@ CppScripts::Script* ScriptComponent::GetScript() {
|
||||
}
|
||||
|
||||
void ScriptComponent::SetScript(const std::string& scriptName) {
|
||||
//we don't need to delete the script because others may be using it :)
|
||||
/*if (m_Client) {
|
||||
m_Script = new InvalidScript();
|
||||
return;
|
||||
}*/
|
||||
|
||||
m_Script = CppScripts::GetScript(m_ParentEntity, scriptName);
|
||||
}
|
||||
|
||||
const std::string ScriptComponent::GetScriptName(Entity* parentEntity, const uint32_t componentId) {
|
||||
if (!parentEntity) return "";
|
||||
// LDF key script overrides script component Id
|
||||
const auto customScriptServer = parentEntity->GetVarAsString(u"custom_script_server");
|
||||
if (!customScriptServer.empty() || componentId == 0) return customScriptServer;
|
||||
|
||||
auto* scriptCompTable = CDClientManager::Instance().GetTable<CDScriptComponentTable>();
|
||||
CDScriptComponent scriptCompData = scriptCompTable->GetByID(componentId);
|
||||
return scriptCompData.script_name;
|
||||
}
|
||||
|
||||
const std::string ScriptComponent::GetZoneScriptName(const uint32_t componentId) {
|
||||
auto* zoneTable = CDClientManager::Instance().GetTable<CDZoneTableTable>();
|
||||
const auto zoneID = dZoneManager::Instance()->GetZoneID();
|
||||
const auto* zoneData = zoneTable->Query(zoneID.GetMapID());
|
||||
|
||||
if (!zoneData) return "";
|
||||
|
||||
int zoneScriptID = zoneData->scriptID;
|
||||
if (zoneScriptID == -1) return "";
|
||||
auto* scriptCompTable = CDClientManager::Instance().GetTable<CDScriptComponentTable>();
|
||||
const auto& zoneScriptData = scriptCompTable->GetByID(zoneScriptID);
|
||||
return zoneScriptData.script_name;
|
||||
}
|
||||
|
@@ -21,8 +21,7 @@ class ScriptComponent : public Component {
|
||||
public:
|
||||
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::SCRIPT;
|
||||
|
||||
ScriptComponent(Entity* parent, std::string scriptName, bool serialized, bool client = false);
|
||||
~ScriptComponent() override;
|
||||
ScriptComponent(Entity* parent, std::string scriptName);
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
|
||||
@@ -32,34 +31,23 @@ public:
|
||||
*/
|
||||
CppScripts::Script* GetScript();
|
||||
|
||||
/**
|
||||
* Sets whether the entity should be serialized, unused
|
||||
* @param var whether the entity should be serialized
|
||||
*/
|
||||
void SetSerialized(const bool var) { m_Serialized = var; }
|
||||
|
||||
/**
|
||||
* Sets the script using a path by looking through dScripts for a script that matches
|
||||
* @param scriptName the name of the script to find
|
||||
*/
|
||||
void SetScript(const std::string& scriptName);
|
||||
|
||||
// Get the script attached to the provided component id.
|
||||
// LDF key custom_script_server overrides component id script.
|
||||
static const std::string GetScriptName(Entity* parentEntity, const uint32_t componentId = 0);
|
||||
|
||||
static const std::string GetZoneScriptName(const uint32_t componentId);
|
||||
private:
|
||||
|
||||
/**
|
||||
* The script attached to this entity
|
||||
*/
|
||||
CppScripts::Script* m_Script;
|
||||
|
||||
/**
|
||||
* Whether or not the comp should be serialized, unused
|
||||
*/
|
||||
bool m_Serialized;
|
||||
|
||||
/**
|
||||
* Whether or not this script is a client script
|
||||
*/
|
||||
bool m_Client;
|
||||
};
|
||||
|
||||
#endif // SCRIPTCOMPONENT_H
|
||||
|
Reference in New Issue
Block a user