diff --git a/shared/bindings/VirtualEntity.cpp b/shared/bindings/VirtualEntity.cpp index 349c18a1..13bddc20 100644 --- a/shared/bindings/VirtualEntity.cpp +++ b/shared/bindings/VirtualEntity.cpp @@ -35,6 +35,46 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_BIND_BASE_OBJECT(virtualEntity, "Failed to create virtual entity"); } +static void StaticGetByID(const v8::FunctionCallbackInfo& 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& 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 name, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -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(isolate, tpl, "group"); diff --git a/shared/bindings/VirtualEntityGroup.cpp b/shared/bindings/VirtualEntityGroup.cpp index 3151abbc..29a2ae24 100644 --- a/shared/bindings/VirtualEntityGroup.cpp +++ b/shared/bindings/VirtualEntityGroup.cpp @@ -17,6 +17,47 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_BIND_BASE_OBJECT(virtualEntityGroup, "Failed to create virtual entity group"); } +static void StaticGetByID(const v8::FunctionCallbackInfo& 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& 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 name, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -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);