Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing VirtualEntity and VirtualEntityGroup static methods #300

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions shared/bindings/VirtualEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,46 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_BIND_BASE_OBJECT(virtualEntity, "Failed to create virtual entity");
}

static void StaticGetByID(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_CHECK_ARGS_LEN(1);

V8_ARG_TO_INT(1, id);

alt::IBaseObject* entity = alt::ICore::Instance().GetBaseObjectByID(alt::IBaseObject::Type::VIRTUAL_ENTITY, id);

if(entity)
{
V8_RETURN_BASE_OBJECT(entity);
return;
}

V8_RETURN_NULL();
}

#ifdef ALT_CLIENT_API

static void StaticGetByRemoteId(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_CHECK_ARGS_LEN(1);

V8_ARG_TO_INT32(1, id);

alt::IBaseObject* entity = alt::ICore::Instance().GetBaseObjectByRemoteID(alt::IBaseObject::Type::VIRTUAL_ENTITY, id);

if(entity)
{
V8_RETURN_BASE_OBJECT(entity);
return;
}

V8_RETURN_NULL();
}

#endif

static void AllGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
Expand Down Expand Up @@ -197,6 +237,11 @@ extern V8Class v8VirtualEntity("VirtualEntity",
{
v8::Isolate* isolate = v8::Isolate::GetCurrent();

V8Helpers::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID);
#ifdef ALT_CLIENT_API
V8Helpers::SetStaticMethod(isolate, tpl, "getByRemoteID", StaticGetByRemoteId);
#endif

V8Helpers::SetStaticAccessor(isolate, tpl, "all", AllGetter);

V8Helpers::SetAccessor<IVirtualEntity, IVirtualEntityGroup*, &IVirtualEntity::GetGroup>(isolate, tpl, "group");
Expand Down
45 changes: 45 additions & 0 deletions shared/bindings/VirtualEntityGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,47 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_BIND_BASE_OBJECT(virtualEntityGroup, "Failed to create virtual entity group");
}

static void StaticGetByID(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_CHECK_ARGS_LEN(1);

V8_ARG_TO_INT(1, id);

alt::IBaseObject* entity = alt::ICore::Instance().GetBaseObjectByID(alt::IBaseObject::Type::VIRTUAL_ENTITY_GROUP, id);

if(entity)
{
V8_RETURN_BASE_OBJECT(entity);
return;
}

V8_RETURN_NULL();
}

#ifdef ALT_CLIENT_API

/* NOTE (xLuxy): Client's are not aware of remote groups (yet?)
static void StaticGetByRemoteId(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_CHECK_ARGS_LEN(1);

V8_ARG_TO_INT32(1, id);

alt::IBaseObject* entity = alt::ICore::Instance().GetBaseObjectByRemoteID(alt::IBaseObject::Type::VIRTUAL_ENTITY_GROUP, id);

if(entity)
{
V8_RETURN_BASE_OBJECT(entity);
return;
}

V8_RETURN_NULL();
}*/

#endif

static void AllGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
Expand Down Expand Up @@ -97,6 +138,10 @@ extern V8Class v8VirtualEntityGroup("VirtualEntityGroup",
{
v8::Isolate* isolate = v8::Isolate::GetCurrent();

V8Helpers::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID);
#ifdef ALT_CLIENT_API
// V8Helpers::SetStaticMethod(isolate, tpl, "getByRemoteID", StaticGetByRemoteId);
#endif
V8Helpers::SetStaticAccessor(isolate, tpl, "all", AllGetter);

V8Helpers::SetMethod(isolate, tpl, "hasMeta", HasMeta);
Expand Down
Loading