Skip to content

Commit

Permalink
Merge pull request #31 from LeonMrBonnie/dlc-clothes-props
Browse files Browse the repository at this point in the history
Add props methods and dlc clothes/props support

Former-commit-id: bb9ee20
  • Loading branch information
FabianTerhorst authored Jan 26, 2021
2 parents e83e455 + 5dc8b2b commit c0073e7
Showing 1 changed file with 90 additions and 9 deletions.
99 changes: 90 additions & 9 deletions src/bindings/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,41 +194,119 @@ static void HwidExHashGetter(v8::Local<v8::String> name, const v8::PropertyCallb
static void SetClothes(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN2(3, 4);
V8_CHECK_ARGS_LEN_MIN_MAX(3, 5);
V8_GET_THIS_BASE_OBJECT(player, IPlayer);

V8_ARG_TO_INTEGER(1, component);
V8_ARG_TO_INTEGER(2, drawable);
V8_ARG_TO_INTEGER(3, texture);

if(info.Length() == 4)
if(info.Length() == 3)
{
player->SetClothes(component, drawable, texture, 2);
}
else if(info.Length() == 4)
{
V8_ARG_TO_INTEGER(4, palette);
player->SetClothes(component, drawable, texture, palette);
}
else
else if(info.Length() == 5)
{
player->SetClothes(component, drawable, texture, 2);
V8_ARG_TO_INTEGER(4, palette);
V8_ARG_TO_INTEGER(5, dlc);
player->SetDlcClothes(component, drawable, texture, palette, dlc);
}
}

static void GetClothes(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN(1);
V8_CHECK_ARGS_LEN2(1, 2);
V8_GET_THIS_BASE_OBJECT(player, IPlayer);

V8_ARG_TO_INTEGER(1, component);

auto cloth = player->GetClothes(component);
bool dlcCloth = false;
if(info.Length() == 2)
{
V8_ARG_TO_BOOLEAN(2, dlc);
dlcCloth = dlc;
}

V8_NEW_OBJECT(clothes);
V8_OBJECT_SET_INTEGER(clothes, "drawable", cloth.drawableId);
V8_OBJECT_SET_INTEGER(clothes, "texture", cloth.textureId);
V8_OBJECT_SET_INTEGER(clothes, "palette", cloth.paletteId);
if(!dlcCloth)
{
auto cloth = player->GetClothes(component);
V8_OBJECT_SET_INTEGER(clothes, "drawable", cloth.drawableId);
V8_OBJECT_SET_INTEGER(clothes, "texture", cloth.textureId);
V8_OBJECT_SET_INTEGER(clothes, "palette", cloth.paletteId);
}
else
{
auto cloth = player->GetDlcClothes(component);
V8_OBJECT_SET_INTEGER(clothes, "drawable", cloth.drawableId);
V8_OBJECT_SET_INTEGER(clothes, "texture", cloth.textureId);
V8_OBJECT_SET_INTEGER(clothes, "palette", cloth.paletteId);
V8_OBJECT_SET_INTEGER(clothes, "dlc", cloth.dlc);
}

V8_RETURN(clothes);
}

static void SetProps(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN_MIN_MAX(3, 4);
V8_GET_THIS_BASE_OBJECT(player, IPlayer);

V8_ARG_TO_INTEGER(1, component);
V8_ARG_TO_INTEGER(2, drawable);
V8_ARG_TO_INTEGER(3, texture);

if(info.Length() == 3)
{
player->SetProps(component, drawable, texture);
}
else if(info.Length() == 4)
{
V8_ARG_TO_INTEGER(4, dlc);
player->SetDlcProps(component, drawable, texture, dlc);
}
}

static void GetProps(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN2(1, 2);
V8_GET_THIS_BASE_OBJECT(player, IPlayer);

V8_ARG_TO_INTEGER(1, component);

bool dlcProp = false;
if(info.Length() == 2)
{
V8_ARG_TO_BOOLEAN(2, dlc);
dlcProp = dlc;
}

V8_NEW_OBJECT(prop);
if(!dlcProp)
{
auto props = player->GetProps(component);
V8_OBJECT_SET_INTEGER(prop, "drawable", props.drawableId);
V8_OBJECT_SET_INTEGER(prop, "texture", props.textureId);
}
else
{
auto props = player->GetDlcProps(component);
V8_OBJECT_SET_INTEGER(prop, "drawable", props.drawableId);
V8_OBJECT_SET_INTEGER(prop, "texture", props.textureId);
V8_OBJECT_SET_INTEGER(prop, "dlc", props.dlc);
}

V8_RETURN(prop);
}

static void IsEntityInStreamRange(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
Expand Down Expand Up @@ -323,4 +401,7 @@ extern V8Class v8Player("Player", v8Entity, nullptr, [](v8::Local<v8::FunctionTe

V8::SetMethod(isolate, tpl, "setClothes", &SetClothes);
V8::SetMethod(isolate, tpl, "getClothes", &GetClothes);

V8::SetMethod(isolate, tpl, "setProp", &SetProps);
V8::SetMethod(isolate, tpl, "getProp", &GetProps);
});

0 comments on commit c0073e7

Please sign in to comment.