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:
parent
abc0960e03
commit
619f55689f
3 changed files with 39 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <typeindex>
|
||||
#include <Event/EventHandler.h>
|
||||
#include "NativeScriptApi.h"
|
||||
#include <cassert>
|
||||
|
||||
#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 ) :
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
#include <Crypt/md5.h>
|
||||
|
||||
#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;
|
||||
|
|
Loading…
Add table
Reference in a new issue