-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
517 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
#include "../CV8Resource.h" | ||
#include "V8Class.h" | ||
|
||
static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info) | ||
{ | ||
V8_GET_ISOLATE_CONTEXT(); | ||
V8_CHECK_CONSTRUCTOR(); | ||
|
||
V8_CHECK_ARGS_LEN(1); | ||
V8_ARG_TO_UINT(1, interiorId); | ||
|
||
std::shared_ptr<alt::IInterior> interior = alt::ICore::Instance().GetInterior(interiorId); | ||
V8_CHECK(interior, "interior doesn't exist"); | ||
|
||
V8Helpers::SetObjectClass(info.GetIsolate(), info.This(), V8Class::ObjectClass::INTERIOR); | ||
info.This()->SetInternalField(1, info[0]); | ||
} | ||
|
||
static void GetForInteriorID(const v8::FunctionCallbackInfo<v8::Value>& info) | ||
{ | ||
V8_GET_ISOLATE_CONTEXT(); | ||
|
||
V8_CHECK_ARGS_LEN(1); | ||
V8_ARG_TO_UINT(1, interiorId); | ||
std::vector<v8::Local<v8::Value>> args{ V8Helpers::JSValue(interiorId) }; | ||
|
||
extern V8Class v8Interior; | ||
V8_RETURN(v8Interior.New(isolate->GetEnteredOrMicrotaskContext(), args)); | ||
} | ||
|
||
static void RoomCountGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) | ||
{ | ||
V8_GET_ISOLATE_CONTEXT(); | ||
V8_GET_THIS_INTERNAL_FIELD_UINT32(1, interiorId); | ||
|
||
auto interior = alt::ICore::Instance().GetInterior(interiorId); | ||
V8_CHECK(interior, "interior doesn't exist"); | ||
|
||
V8_RETURN_UINT(interior->GetRoomCount()); | ||
} | ||
|
||
static void PortalCountGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) | ||
{ | ||
V8_GET_ISOLATE_CONTEXT(); | ||
V8_GET_THIS_INTERNAL_FIELD_UINT32(1, interiorId); | ||
|
||
auto interior = alt::ICore::Instance().GetInterior(interiorId); | ||
V8_CHECK(interior, "interior doesn't exist"); | ||
|
||
V8_RETURN_UINT(interior->GetPortalCount()); | ||
} | ||
|
||
static void PositionGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) | ||
{ | ||
V8_GET_ISOLATE_CONTEXT_RESOURCE(); | ||
V8_GET_THIS_INTERNAL_FIELD_UINT32(1, interiorId); | ||
|
||
auto interior = alt::ICore::Instance().GetInterior(interiorId); | ||
V8_CHECK(interior, "interior doesn't exist"); | ||
|
||
V8_RETURN_VECTOR3(interior->GetPosition()); | ||
} | ||
|
||
static void RotationGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) | ||
{ | ||
V8_GET_ISOLATE_CONTEXT_RESOURCE(); | ||
V8_GET_THIS_INTERNAL_FIELD_UINT32(1, interiorId); | ||
|
||
auto interior = alt::ICore::Instance().GetInterior(interiorId); | ||
V8_CHECK(interior, "interior doesn't exist"); | ||
|
||
V8_RETURN_VECTOR3(interior->GetRotation()); | ||
} | ||
|
||
static void EntitiesExtentsGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) | ||
{ | ||
V8_GET_ISOLATE_CONTEXT_RESOURCE(); | ||
V8_GET_THIS_INTERNAL_FIELD_UINT32(1, interiorId); | ||
|
||
auto interior = alt::ICore::Instance().GetInterior(interiorId); | ||
V8_CHECK(interior, "interior doesn't exist"); | ||
|
||
auto extentInfo = interior->GetEntitiesExtents(); | ||
INTERIOR_EXTENT_TO_OBJECT(extentInfo, obj); | ||
V8_RETURN(obj); | ||
} | ||
|
||
static void GetRoomByHash(const v8::FunctionCallbackInfo<v8::Value>& info) | ||
{ | ||
V8_GET_ISOLATE_CONTEXT(); | ||
V8_GET_THIS_INTERNAL_FIELD_UINT32(1, interiorId); | ||
|
||
auto interior = alt::ICore::Instance().GetInterior(interiorId); | ||
V8_CHECK(interior, "interior doesn't exist"); | ||
|
||
V8_CHECK_ARGS_LEN(1); | ||
V8_ARG_TO_UINT(1, roomHash); | ||
|
||
// 3 args: (interiorId: uint, value: uint, valueIsRoomIndex: bool) | ||
std::vector<v8::Local<v8::Value>> args{ V8Helpers::JSValue(interiorId), V8Helpers::JSValue(roomHash), V8Helpers::JSValue(false) }; | ||
|
||
extern V8Class v8InteriorRoom; | ||
V8_RETURN(v8InteriorRoom.New(isolate->GetEnteredOrMicrotaskContext(), args)); | ||
} | ||
|
||
static void GetRoomByIndex(const v8::FunctionCallbackInfo<v8::Value>& info) | ||
{ | ||
V8_GET_ISOLATE_CONTEXT(); | ||
V8_GET_THIS_INTERNAL_FIELD_UINT32(1, interiorId); | ||
|
||
auto interior = alt::ICore::Instance().GetInterior(interiorId); | ||
V8_CHECK(interior, "interior doesn't exist"); | ||
|
||
V8_CHECK_ARGS_LEN(1); | ||
V8_ARG_TO_UINT(1, roomIndex); | ||
|
||
// 3 args: (interiorId: uint, value: uint, valueIsRoomIndex: bool) | ||
std::vector<v8::Local<v8::Value>> args{ V8Helpers::JSValue(interiorId), V8Helpers::JSValue(roomIndex), V8Helpers::JSValue(true) }; | ||
|
||
extern V8Class v8InteriorRoom; | ||
V8_RETURN(v8InteriorRoom.New(isolate->GetEnteredOrMicrotaskContext(), args)); | ||
} | ||
|
||
static void GetPortalByIndex(const v8::FunctionCallbackInfo<v8::Value>& info) | ||
{ | ||
V8_GET_ISOLATE_CONTEXT(); | ||
V8_GET_THIS_INTERNAL_FIELD_UINT32(1, interiorId); | ||
|
||
auto interior = alt::ICore::Instance().GetInterior(interiorId); | ||
V8_CHECK(interior, "interior doesn't exist"); | ||
|
||
V8_CHECK_ARGS_LEN(1); | ||
V8_ARG_TO_UINT(1, portalIndex); | ||
|
||
std::vector<v8::Local<v8::Value>> args{ V8Helpers::JSValue(interiorId), V8Helpers::JSValue(portalIndex) }; | ||
|
||
extern V8Class v8InteriorPortal; | ||
V8_RETURN(v8InteriorPortal.New(isolate->GetEnteredOrMicrotaskContext(), args)); | ||
} | ||
|
||
static void IdGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) | ||
{ | ||
V8_GET_ISOLATE_CONTEXT(); | ||
V8_GET_THIS_INTERNAL_FIELD_UINT32(1, interiorId); | ||
V8_RETURN_UINT(interiorId); | ||
} | ||
|
||
extern V8Class v8Interior("Interior", | ||
Constructor, | ||
[](v8::Local<v8::FunctionTemplate> tpl) | ||
{ | ||
v8::Isolate* isolate = v8::Isolate::GetCurrent(); | ||
|
||
tpl->InstanceTemplate()->SetInternalFieldCount(static_cast<int>(V8Class::InternalFields::COUNT)); | ||
|
||
V8Helpers::SetMethod(isolate, tpl, "getRoomByHash", &GetRoomByHash); | ||
V8Helpers::SetMethod(isolate, tpl, "getRoomByIndex", &GetRoomByIndex); | ||
V8Helpers::SetMethod(isolate, tpl, "getPortalByIndex", &GetPortalByIndex); | ||
|
||
V8Helpers::SetAccessor(isolate, tpl, "roomCount", &RoomCountGetter); | ||
V8Helpers::SetAccessor(isolate, tpl, "portalCount", &PortalCountGetter); | ||
V8Helpers::SetAccessor(isolate, tpl, "pos", &PositionGetter); | ||
V8Helpers::SetAccessor(isolate, tpl, "rot", &RotationGetter); | ||
V8Helpers::SetAccessor(isolate, tpl, "entitiesExtents", &EntitiesExtentsGetter); | ||
V8Helpers::SetAccessor(isolate, tpl, "id", &IdGetter); | ||
|
||
V8Helpers::SetStaticMethod(isolate, tpl, "getForInteriorID", &GetForInteriorID); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
#include "../CV8Resource.h" | ||
#include "V8Class.h" | ||
#include "cpp-sdk/script-objects/IInteriorPortal.h" | ||
|
||
static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info) | ||
{ | ||
V8_GET_ISOLATE_CONTEXT(); | ||
V8_CHECK_CONSTRUCTOR(); | ||
|
||
V8_CHECK_ARGS_LEN(2); | ||
V8_ARG_TO_UINT(1, interiorId); | ||
V8_ARG_TO_UINT(2, portalIndex); | ||
|
||
std::shared_ptr<alt::IInterior> interior = alt::ICore::Instance().GetInterior(interiorId); | ||
V8_CHECK(interior, "interior doesn't exist"); | ||
|
||
std::shared_ptr<alt::IInteriorPortal> portal = interior->GetPortalByIndex(portalIndex); | ||
V8_CHECK(portal, "interior portal doesn't exist"); | ||
|
||
V8Helpers::SetObjectClass(info.GetIsolate(), info.This(), V8Class::ObjectClass::INTERIOR_PORTAL); | ||
info.This()->SetInternalField(1, info[0]); | ||
info.This()->SetInternalField(2, info[1]); | ||
} | ||
|
||
static void IndexGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) | ||
{ | ||
V8_GET_ISOLATE_CONTEXT(); | ||
V8_GET_THIS_INTERNAL_FIELD_UINT32(2, portalIndex); | ||
V8_RETURN_UINT(portalIndex); | ||
} | ||
|
||
static void RoomFromGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) | ||
{ | ||
GET_THIS_INTERIOR_PORTAL(portal); | ||
|
||
// TODO: is is expected that it returns uint but setter takes int? (and same for RoomTo, same for Flag) | ||
V8_RETURN_INT(portal->GetRoomFrom()); | ||
} | ||
|
||
static void RoomFromSetter(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) | ||
{ | ||
GET_THIS_INTERIOR_PORTAL(portal); | ||
|
||
V8_TO_UINT(value, roomFrom); | ||
portal->SetRoomFrom(roomFrom); | ||
} | ||
|
||
static void RoomToGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) | ||
{ | ||
GET_THIS_INTERIOR_PORTAL(portal); | ||
|
||
V8_RETURN_INT(portal->GetRoomTo()); | ||
} | ||
|
||
static void RoomToSetter(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) | ||
{ | ||
GET_THIS_INTERIOR_PORTAL(portal); | ||
|
||
V8_TO_UINT(value, roomTo); | ||
portal->SetRoomTo(roomTo); | ||
} | ||
|
||
static void FlagGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) | ||
{ | ||
GET_THIS_INTERIOR_PORTAL(portal); | ||
|
||
V8_RETURN_INT(portal->GetFlag()); | ||
} | ||
|
||
static void FlagSetter(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) | ||
{ | ||
GET_THIS_INTERIOR_PORTAL(portal); | ||
|
||
V8_TO_UINT(value, flag); | ||
portal->SetFlag(flag); | ||
} | ||
|
||
static void CornerCountGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) | ||
{ | ||
GET_THIS_INTERIOR_PORTAL(portal); | ||
|
||
V8_RETURN_UINT(portal->GetCornerCount()); | ||
} | ||
|
||
static void GetEntityArchetype(const v8::FunctionCallbackInfo<v8::Value>& info) | ||
{ | ||
GET_THIS_INTERIOR_PORTAL(portal); | ||
|
||
V8_CHECK_ARGS_LEN(1); | ||
V8_ARG_TO_UINT(1, entityIndex); | ||
V8_RETURN_UINT(portal->GetEntityArcheType(entityIndex)); | ||
} | ||
|
||
static void GetEntityFlag(const v8::FunctionCallbackInfo<v8::Value>& info) | ||
{ | ||
GET_THIS_INTERIOR_PORTAL(portal); | ||
|
||
V8_CHECK_ARGS_LEN(1); | ||
V8_ARG_TO_INT(1, entityIndex); | ||
V8_RETURN_INT(portal->GetEntityFlag(entityIndex)); | ||
} | ||
|
||
static void SetEntityFlag(const v8::FunctionCallbackInfo<v8::Value>& info) | ||
{ | ||
GET_THIS_INTERIOR_PORTAL(portal); | ||
|
||
V8_CHECK_ARGS_LEN(2); | ||
V8_ARG_TO_INT(1, entityIndex); | ||
V8_ARG_TO_INT(2, flag); | ||
portal->SetEntityFlag(entityIndex, flag); | ||
} | ||
|
||
static void GetEntityPos(const v8::FunctionCallbackInfo<v8::Value>& info) | ||
{ | ||
GET_THIS_INTERIOR_PORTAL(portal); | ||
|
||
V8_CHECK_ARGS_LEN(1); | ||
V8_ARG_TO_INT(1, entityIndex); | ||
V8_GET_RESOURCE(); | ||
V8_RETURN_VECTOR3(portal->GetEntityPosition(entityIndex)); | ||
} | ||
|
||
static void GetEntityRot(const v8::FunctionCallbackInfo<v8::Value>& info) | ||
{ | ||
GET_THIS_INTERIOR_PORTAL(portal); | ||
|
||
V8_CHECK_ARGS_LEN(1); | ||
V8_ARG_TO_INT(1, entityIndex); | ||
V8_GET_RESOURCE(); | ||
V8_RETURN_VECTOR3(portal->GetEntityRotation(entityIndex)); | ||
} | ||
|
||
static void GetCornerPos(const v8::FunctionCallbackInfo<v8::Value>& info) | ||
{ | ||
GET_THIS_INTERIOR_PORTAL(portal); | ||
|
||
V8_CHECK_ARGS_LEN(1); | ||
V8_ARG_TO_UINT(1, cornerIndex); | ||
V8_GET_RESOURCE(); | ||
V8_RETURN_VECTOR3(portal->GetCornerPosition(cornerIndex)); | ||
} | ||
|
||
|
||
static void EntityCountGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) | ||
{ | ||
GET_THIS_INTERIOR_PORTAL(portal); | ||
|
||
V8_RETURN_UINT(portal->GetEntityCount()); | ||
} | ||
|
||
static void SetCornerPos(const v8::FunctionCallbackInfo<v8::Value>& info) | ||
{ | ||
GET_THIS_INTERIOR_PORTAL(portal); | ||
|
||
V8_CHECK_ARGS_LEN(2); | ||
V8_ARG_TO_INT(1, cornerIndex); | ||
V8_ARG_TO_VECTOR3(2, pos); | ||
portal->SetCornerPosition(cornerIndex, pos); | ||
} | ||
|
||
extern V8Class v8InteriorPortal("InteriorPortal", | ||
Constructor, | ||
[](v8::Local<v8::FunctionTemplate> tpl) | ||
{ | ||
v8::Isolate* isolate = v8::Isolate::GetCurrent(); | ||
|
||
// TODO: not sure about this one | ||
tpl->InstanceTemplate()->SetInternalFieldCount(3); | ||
|
||
V8Helpers::SetAccessor(isolate, tpl, "index", &IndexGetter); | ||
V8Helpers::SetAccessor(isolate, tpl, "cornerCount", &CornerCountGetter); | ||
V8Helpers::SetAccessor(isolate, tpl, "roomFrom", &RoomFromGetter, &RoomFromSetter); | ||
V8Helpers::SetAccessor(isolate, tpl, "roomTo", &RoomToGetter, &RoomToSetter); | ||
V8Helpers::SetAccessor(isolate, tpl, "flag", &FlagGetter, &FlagSetter); | ||
V8Helpers::SetAccessor(isolate, tpl, "entityCount", &EntityCountGetter); | ||
|
||
V8Helpers::SetMethod(isolate, tpl, "getCornerPos", &GetCornerPos); | ||
V8Helpers::SetMethod(isolate, tpl, "getEntityArchetype", &GetEntityArchetype); | ||
V8Helpers::SetMethod(isolate, tpl, "getEntityFlag", &GetEntityFlag); | ||
V8Helpers::SetMethod(isolate, tpl, "setEntityFlag", &SetEntityFlag); | ||
V8Helpers::SetMethod(isolate, tpl, "getEntityPos", &GetEntityPos); | ||
V8Helpers::SetMethod(isolate, tpl, "getEntityRot", &GetEntityRot); | ||
|
||
V8Helpers::SetMethod(isolate, tpl, "setCornerPos", &SetCornerPos); | ||
}); |
Oops, something went wrong.