Skip to content

Commit

Permalink
merge release into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
C0kkie committed Dec 20, 2022
2 parents 52524dd + 33d13a8 commit fc30394
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 34 deletions.
11 changes: 7 additions & 4 deletions shared/bindings/RGBA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
V8Helpers::DefineOwnProperty(isolate, ctx, info.This(), V8Helpers::RGBA_AKey(isolate), V8Helpers::JSValue(a), v8::PropertyAttribute::ReadOnly);
}

extern V8Class v8RGBA("RGBA", &Constructor, [](v8::Local<v8::FunctionTemplate> tpl) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
extern V8Class v8RGBA("RGBA",
&Constructor,
[](v8::Local<v8::FunctionTemplate> tpl)
{
v8::Isolate* isolate = v8::Isolate::GetCurrent();

tpl->InstanceTemplate()->SetInternalFieldCount(1); // !! Needs to be set so V8 knows its a custom class !!
});
tpl->InstanceTemplate()->SetInternalFieldCount(1); // !! Needs to be set so V8 knows its a custom class !!
});
20 changes: 11 additions & 9 deletions shared/bindings/Resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ static void CurrentGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<
V8_RETURN(resource->GetOrCreateResourceObject(resource->GetResource()));
}

extern V8Class v8Resource("Resource", [](v8::Local<v8::FunctionTemplate> tpl) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
extern V8Class v8Resource("Resource",
[](v8::Local<v8::FunctionTemplate> tpl)
{
v8::Isolate* isolate = v8::Isolate::GetCurrent();

tpl->InstanceTemplate()->SetInternalFieldCount(2); // Set it to 2, so that our check for V8 entities works (as this isn't a base object)
tpl->InstanceTemplate()->SetInternalFieldCount(2); // Set it to 2, so that our check for V8 entities works (as this isn't a base object)

V8Helpers::SetAccessor(isolate, tpl, "isStarted", &IsStartedGetter);
V8Helpers::SetAccessor(isolate, tpl, "type", &TypeGetter);
Expand All @@ -185,11 +187,11 @@ extern V8Class v8Resource("Resource", [](v8::Local<v8::FunctionTemplate> tpl) {
V8Helpers::SetAccessor(isolate, tpl, "optionalPermissions", &OptionalPermissionsGetter);
V8Helpers::SetAccessor(isolate, tpl, "valid", &ValidGetter);
#ifdef ALT_SERVER_API
V8Helpers::SetAccessor(isolate, tpl, "path", &PathGetter);
V8Helpers::SetAccessor(isolate, tpl, "config", &ConfigGetter);
V8Helpers::SetAccessor(isolate, tpl, "path", &PathGetter);
V8Helpers::SetAccessor(isolate, tpl, "config", &ConfigGetter);
#endif

V8Helpers::SetStaticMethod(isolate, tpl, "getByName", &GetByName);
V8Helpers::SetStaticAccessor(isolate, tpl, "all", &AllGetter);
V8Helpers::SetStaticAccessor(isolate, tpl, "current", &CurrentGetter);
});
V8Helpers::SetStaticMethod(isolate, tpl, "getByName", &GetByName);
V8Helpers::SetStaticAccessor(isolate, tpl, "all", &AllGetter);
V8Helpers::SetStaticAccessor(isolate, tpl, "current", &CurrentGetter);
});
13 changes: 8 additions & 5 deletions shared/bindings/Vector2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,11 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
V8Helpers::DefineOwnProperty(isolate, ctx, _this, V8Helpers::Vector3_YKey(isolate), y, v8::PropertyAttribute::ReadOnly);
}

extern V8Class v8Vector2("Vector2", Constructor, [](v8::Local<v8::FunctionTemplate> tpl) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();

tpl->InstanceTemplate()->SetInternalFieldCount(1); // !! Needs to be set so V8 knows its a custom class !!
});
extern V8Class v8Vector2("Vector2",
Constructor,
[](v8::Local<v8::FunctionTemplate> tpl)
{
v8::Isolate* isolate = v8::Isolate::GetCurrent();

tpl->InstanceTemplate()->SetInternalFieldCount(1); // !! Needs to be set so V8 knows its a custom class !!
});
13 changes: 8 additions & 5 deletions shared/bindings/Vector3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,11 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
V8Helpers::DefineOwnProperty(isolate, ctx, _this, V8Helpers::Vector3_ZKey(isolate), z, v8::PropertyAttribute::ReadOnly);
}

extern V8Class v8Vector3("Vector3", Constructor, [](v8::Local<v8::FunctionTemplate> tpl) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();

tpl->InstanceTemplate()->SetInternalFieldCount(1); // !! Needs to be set so V8 knows its a custom class !!
});
extern V8Class v8Vector3("Vector3",
Constructor,
[](v8::Local<v8::FunctionTemplate> tpl)
{
v8::Isolate* isolate = v8::Isolate::GetCurrent();

tpl->InstanceTemplate()->SetInternalFieldCount(1); // !! Needs to be set so V8 knows its a custom class !!
});
30 changes: 19 additions & 11 deletions shared/events/Resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@

using EventType = alt::CEvent::Type;

V8_LOCAL_EVENT_HANDLER anyResourceStart(EventType::RESOURCE_START, "anyResourceStart", [](V8ResourceImpl* resource, const alt::CEvent* e, std::vector<v8::Local<v8::Value>>& args) {
auto ev = static_cast<const alt::CResourceStartEvent*>(e);
V8_LOCAL_EVENT_HANDLER anyResourceStart(EventType::RESOURCE_START,
"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()));
});
args.push_back(V8Helpers::JSValue(ev->GetResource()->GetName()));
});

V8_EVENT_HANDLER anyResourceStop(
EventType::RESOURCE_STOP,
[](V8ResourceImpl* resource, const alt::CEvent* e) {
[](V8ResourceImpl* resource, const alt::CEvent* e)
{
auto ev = static_cast<const alt::CResourceStopEvent*>(e);
for(alt::IResource* res : alt::ICore::Instance().GetAllResources())
{
Expand All @@ -25,15 +29,19 @@ V8_EVENT_HANDLER anyResourceStop(
}
return resource->GetLocalHandlers("anyResourceStop");
},
[](V8ResourceImpl* resource, const alt::CEvent* e, std::vector<v8::Local<v8::Value>>& args) {
[](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();
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()));
});
args.push_back(V8Helpers::JSValue(ev->GetResource()->GetName()));
});

0 comments on commit fc30394

Please sign in to comment.