Skip to content

Commit

Permalink
client/server/shared: Move resource events to shared
Browse files Browse the repository at this point in the history
Former-commit-id: 8b1c0e4
  • Loading branch information
LeonMrBonnie committed May 16, 2022
1 parent 6b674e6 commit 80d8fc7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 47 deletions.
32 changes: 0 additions & 32 deletions client/src/events/Resource.cpp

This file was deleted.

15 changes: 0 additions & 15 deletions server/src/events/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<v8::Local<v8::Value>>& args) {
auto ev = static_cast<const alt::CResourceStartEvent*>(e);
args.push_back(V8Helpers::JSValue(ev->GetResource()->GetName()));
});

V8Helpers::LocalEventHandler resourceStop(EventType::RESOURCE_STOP, "anyResourceStop", [](V8ResourceImpl* resource, const CEvent* e, std::vector<v8::Local<v8::Value>>& args) {
auto ev = static_cast<const alt::CResourceStopEvent*>(e);
args.push_back(V8Helpers::JSValue(ev->GetResource()->GetName()));
});

V8Helpers::LocalEventHandler resourceError(EventType::RESOURCE_ERROR, "anyResourceError", [](V8ResourceImpl* resource, const CEvent* e, std::vector<v8::Local<v8::Value>>& args) {
auto ev = static_cast<const alt::CResourceErrorEvent*>(e);
args.push_back(V8Helpers::JSValue(ev->GetResource()->GetName()));
});

V8Helpers::LocalEventHandler syncedMetaChange(EventType::SYNCED_META_CHANGE, "syncedMetaChange", [](V8ResourceImpl* resource, const CEvent* e, std::vector<v8::Local<v8::Value>>& args) {
auto ev = static_cast<const alt::CSyncedMetaDataChangeEvent*>(e);

Expand Down
42 changes: 42 additions & 0 deletions shared/events/Resource.cpp
Original file line number Diff line number Diff line change
@@ -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<const alt::CResourceStartEvent*>(e);

return resource->GetLocalHandlers("anyResourceStart");
},
[](V8ResourceImpl* resource, const alt::CEvent* e, std::vector<v8::Local<v8::Value>>& args) {
auto ev = static_cast<const alt::CResourceStartEvent*>(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<const alt::CResourceStopEvent*>(e);

return resource->GetLocalHandlers("anyResourceStop");
},
[](V8ResourceImpl* resource, const alt::CEvent* e, std::vector<v8::Local<v8::Value>>& args) {
auto ev = static_cast<const alt::CResourceStopEvent*>(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<v8::Local<v8::Value>>& args) {
auto ev = static_cast<const alt::CResourceErrorEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();

args.push_back(V8Helpers::JSValue(ev->GetResource()->GetName()));
});

0 comments on commit 80d8fc7

Please sign in to comment.