diff --git a/client/src/events/Resource.cpp b/client/src/events/Resource.cpp deleted file mode 100644 index 9b74fe05..00000000 --- a/client/src/events/Resource.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "V8ResourceImpl.h" -#include "V8Helpers.h" - -#include "cpp-sdk/events/CResourceStartEvent.h" -#include "cpp-sdk/events/CResourceStopEvent.h" -#include "cpp-sdk/events/CResourceErrorEvent.h" - -#include "cpp-sdk/SDK.h" - -using alt::CEvent; -using EventType = CEvent::Type; - -V8_LOCAL_EVENT_HANDLER anyResourceStart(EventType::RESOURCE_START, "anyResourceStart", [](V8ResourceImpl* resource, const alt::CEvent* e, std::vector>& args) { - auto ev = static_cast(e); - v8::Isolate* isolate = resource->GetIsolate(); - - args.push_back(V8Helpers::JSValue(ev->GetResource()->GetName().c_str())); -}); - -V8_LOCAL_EVENT_HANDLER anyResourceStop(EventType::RESOURCE_STOP, "anyResourceStop", [](V8ResourceImpl* resource, const alt::CEvent* e, std::vector>& args) { - auto ev = static_cast(e); - v8::Isolate* isolate = resource->GetIsolate(); - - args.push_back(V8Helpers::JSValue(ev->GetResource()->GetName().c_str())); -}); - -V8_LOCAL_EVENT_HANDLER anyResourceError(EventType::RESOURCE_ERROR, "anyResourceError", [](V8ResourceImpl* resource, const alt::CEvent* e, std::vector>& args) { - auto ev = static_cast(e); - v8::Isolate* isolate = resource->GetIsolate(); - - args.push_back(V8Helpers::JSValue(ev->GetResource()->GetName().c_str())); -}); diff --git a/server/src/events/Main.cpp b/server/src/events/Main.cpp index ad893d8f..2b578c6f 100644 --- a/server/src/events/Main.cpp +++ b/server/src/events/Main.cpp @@ -116,21 +116,6 @@ V8Helpers::LocalEventHandler args.push_back(V8Helpers::JSValue(ev->GetWeaponHash())); }); -V8Helpers::LocalEventHandler resourceStart(EventType::RESOURCE_START, "anyResourceStart", [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { - auto ev = static_cast(e); - args.push_back(V8Helpers::JSValue(ev->GetResource()->GetName())); -}); - -V8Helpers::LocalEventHandler resourceStop(EventType::RESOURCE_STOP, "anyResourceStop", [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { - auto ev = static_cast(e); - args.push_back(V8Helpers::JSValue(ev->GetResource()->GetName())); -}); - -V8Helpers::LocalEventHandler resourceError(EventType::RESOURCE_ERROR, "anyResourceError", [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { - auto ev = static_cast(e); - args.push_back(V8Helpers::JSValue(ev->GetResource()->GetName())); -}); - V8Helpers::LocalEventHandler syncedMetaChange(EventType::SYNCED_META_CHANGE, "syncedMetaChange", [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { auto ev = static_cast(e); diff --git a/shared/events/Resource.cpp b/shared/events/Resource.cpp new file mode 100644 index 00000000..fc901e79 --- /dev/null +++ b/shared/events/Resource.cpp @@ -0,0 +1,42 @@ +#include "V8ResourceImpl.h" +#include "V8Helpers.h" + +#include "cpp-sdk/events/CResourceStartEvent.h" +#include "cpp-sdk/events/CResourceStopEvent.h" +#include "cpp-sdk/events/CResourceErrorEvent.h" +#include "cpp-sdk/SDK.h" + +using EventType = alt::CEvent::Type; + +V8_EVENT_HANDLER anyResourceStart( + EventType::RESOURCE_START, + [](V8ResourceImpl* resource, const alt::CEvent* e) { + auto ev = static_cast(e); + + return resource->GetLocalHandlers("anyResourceStart"); + }, + [](V8ResourceImpl* resource, const alt::CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + + args.push_back(V8Helpers::JSValue(ev->GetResource()->GetName())); + }); + +V8_EVENT_HANDLER anyResourceStop( + EventType::RESOURCE_STOP, + [](V8ResourceImpl* resource, const alt::CEvent* e) { + auto ev = static_cast(e); + + return resource->GetLocalHandlers("anyResourceStop"); + }, + [](V8ResourceImpl* resource, const alt::CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + + args.push_back(V8Helpers::JSValue(ev->GetResource()->GetName())); + }); + +V8_LOCAL_EVENT_HANDLER anyResourceError(EventType::RESOURCE_ERROR, "anyResourceError", [](V8ResourceImpl* resource, const alt::CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + v8::Isolate* isolate = resource->GetIsolate(); + + args.push_back(V8Helpers::JSValue(ev->GetResource()->GetName())); +});