1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-28 15:17:46 +00:00

expose framework to scripts

This commit is contained in:
NotAdam 2018-11-13 20:43:29 +11:00
parent abc0960e03
commit 619f55689f
3 changed files with 39 additions and 0 deletions

View file

@ -3,6 +3,7 @@
#include <typeindex> #include <typeindex>
#include <Event/EventHandler.h> #include <Event/EventHandler.h>
#include "NativeScriptApi.h" #include "NativeScriptApi.h"
#include <cassert>
#ifdef _MSC_VER #ifdef _MSC_VER
#define EXPORT __declspec( dllexport ) #define EXPORT __declspec( dllexport )
@ -28,6 +29,17 @@ std::size_t ScriptObject::getType() const
return m_type; 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 ) : StatusEffectScript::StatusEffectScript( uint32_t effectId ) :

View file

@ -15,6 +15,11 @@
#define EVENTSCRIPT_AETHERYTE_ID 0x50000 #define EVENTSCRIPT_AETHERYTE_ID 0x50000
#define EVENTSCRIPT_AETHERNET_ID 0x50001 #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 * @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; uint32_t m_id;
std::size_t m_type; std::size_t m_type;
Core::Framework* m_framework;
public: public:
/*! /*!
* @param id an ID which uniquely identifies this script in relation to it's type * @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 * @return The hash_code of the script
*/ */
virtual std::size_t getType() const; 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;
}; };

View file

@ -2,6 +2,10 @@
#include <Crypt/md5.h> #include <Crypt/md5.h>
#include "Framework.h"
extern Core::Framework g_fw;
namespace Core { namespace Core {
namespace Scripting { namespace Scripting {
@ -29,6 +33,8 @@ bool NativeScriptMgr::loadScript( const std::string& path )
auto script = scripts[ i ]; auto script = scripts[ i ];
module->scripts.push_back( script ); module->scripts.push_back( script );
script->setFramework( &g_fw );
m_scripts[ script->getType() ][ script->getId() ] = script; m_scripts[ script->getType() ][ script->getId() ] = script;
success = true; success = true;