From 619f55689f3185d5359f78f3dc20a6a5c88bae96 Mon Sep 17 00:00:00 2001 From: NotAdam Date: Tue, 13 Nov 2018 20:43:29 +1100 Subject: [PATCH] expose framework to scripts --- .../sapphire_zone/Script/NativeScriptApi.cpp | 12 +++++++++++ .../sapphire_zone/Script/NativeScriptApi.h | 21 +++++++++++++++++++ .../sapphire_zone/Script/NativeScriptMgr.cpp | 6 ++++++ 3 files changed, 39 insertions(+) diff --git a/src/servers/sapphire_zone/Script/NativeScriptApi.cpp b/src/servers/sapphire_zone/Script/NativeScriptApi.cpp index 3963f7aa..7cc06012 100644 --- a/src/servers/sapphire_zone/Script/NativeScriptApi.cpp +++ b/src/servers/sapphire_zone/Script/NativeScriptApi.cpp @@ -3,6 +3,7 @@ #include #include #include "NativeScriptApi.h" +#include #ifdef _MSC_VER #define EXPORT __declspec( dllexport ) @@ -28,6 +29,17 @@ std::size_t ScriptObject::getType() const return m_type; } +void ScriptObject::setFramework( Core::Framework* fw ) +{ + assert( fw ); + m_framework = fw; +} + +Core::Framework* ScriptObject::getFramework() const +{ + return m_framework; +} + /////////////////////////////////////////////////////////////////// StatusEffectScript::StatusEffectScript( uint32_t effectId ) : diff --git a/src/servers/sapphire_zone/Script/NativeScriptApi.h b/src/servers/sapphire_zone/Script/NativeScriptApi.h index 64c8e79a..f5701a07 100644 --- a/src/servers/sapphire_zone/Script/NativeScriptApi.h +++ b/src/servers/sapphire_zone/Script/NativeScriptApi.h @@ -15,6 +15,11 @@ #define EVENTSCRIPT_AETHERYTE_ID 0x50000 #define EVENTSCRIPT_AETHERNET_ID 0x50001 +namespace Core +{ + class Framework; +} + /*! * @brief The base class that any script should inherit from and set the type param accordingly */ @@ -24,6 +29,8 @@ protected: uint32_t m_id; std::size_t m_type; + Core::Framework* m_framework; + public: /*! * @param id an ID which uniquely identifies this script in relation to it's type @@ -44,6 +51,20 @@ public: * @return The hash_code of the script */ virtual std::size_t getType() const; + + /*! + * @brief Sets the ptr to the framework for use inside scripts + * + * @param fw The ptr to g_fw (Core::Framework) + */ + virtual void setFramework( Core::Framework* fw ); + + /*! + * @brief Returns the current ptr to framework set for the current script + * + * @return A pointer to Core::Framework + */ + virtual Core::Framework* getFramework() const; }; diff --git a/src/servers/sapphire_zone/Script/NativeScriptMgr.cpp b/src/servers/sapphire_zone/Script/NativeScriptMgr.cpp index ac7a1f7f..d7bd0139 100644 --- a/src/servers/sapphire_zone/Script/NativeScriptMgr.cpp +++ b/src/servers/sapphire_zone/Script/NativeScriptMgr.cpp @@ -2,6 +2,10 @@ #include +#include "Framework.h" + +extern Core::Framework g_fw; + namespace Core { namespace Scripting { @@ -29,6 +33,8 @@ bool NativeScriptMgr::loadScript( const std::string& path ) auto script = scripts[ i ]; module->scripts.push_back( script ); + script->setFramework( &g_fw ); + m_scripts[ script->getType() ][ script->getId() ] = script; success = true;