Skip to content

Commit

Permalink
fix(client): Fix various FocusData stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
xLuxy committed Sep 8, 2024
1 parent d937261 commit a996704
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
19 changes: 17 additions & 2 deletions client/js/compatibility/classes/focusData.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,27 @@
const { isVector3 } = requireBinding("shared/utils.js");

class FocusData {
static get isFocusOverriden() {
return alt.FocusData.isFocusOverriden;
}

static get focusOverridePos() {
return alt.FocusData.focusOverridePos;
}

static get focusOverrideOffset() {
return alt.FocusData.focusOverrideOffset;
}

static get focusOverrideEntity() {
return alt.FocusData.focusOverrideEntity;
}

static overrideFocus(value, focusOffset) {
if (isVector3(value)) {
focusOffset ??= { x: 0, y: 0, z: 0 };

alt.FocusData.focusOverridePos = value;
alt.FocusData.focusOverrideOffset = focusOffset;
alt.FocusData.overrideFocus(value, focusOffset);
return;
}

Expand Down
14 changes: 10 additions & 4 deletions client/src/namespaces/FocusDataNamespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ static void FocusOverridePosGetter(js::PropertyContext& ctx)
ctx.Return(alt::ICore::Instance().GetFocusOverridePos());
}

static void FocusOverridePosSetter(js::PropertyContext& ctx)
static void OverrideFocus(js::FunctionContext& ctx)
{
if (!ctx.CheckArgCount(1, 2)) return;

alt::Position pos;
if(!ctx.GetValue(pos)) return;
if (!ctx.GetArg(0, pos)) return;

auto offset = ctx.GetArg<alt::Vector3f>(1, { 0, 0, 0 });

alt::ICore::Instance().OverrideFocusPosition(pos);
alt::ICore::Instance().OverrideFocusPosition(pos, offset);
}

static void FocusOverrideEntityGetter(js::PropertyContext& ctx)
Expand Down Expand Up @@ -44,9 +48,11 @@ static void ClearFocusOverride(js::FunctionContext& ctx)
// clang-format off
extern js::Namespace focusDataNamespace("FocusData", [](js::NamespaceTemplate& tpl) {
tpl.StaticProperty("isFocusOverriden", FocusOverridenGetter);
tpl.StaticProperty("focusOverridePos", FocusOverridePosGetter, FocusOverridePosSetter);
tpl.StaticProperty("focusOverridePos", FocusOverridePosGetter);
tpl.StaticProperty("focusOverrideEntity", FocusOverrideEntityGetter, FocusOverrideEntitySetter);
tpl.StaticProperty("focusOverrideOffset", FocusOverrideOffsetGetter);


tpl.StaticFunction("overrideFocus", OverrideFocus);
tpl.StaticFunction("clearFocusOverride", ClearFocusOverride);
});
3 changes: 2 additions & 1 deletion types/client/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2112,10 +2112,11 @@ declare module "@altv/client" {

export namespace FocusData {
export const isFocusOverriden: boolean;
export let focusOverridePos: altShared.Vector3;
export const focusOverridePos: altShared.Vector3;
export let focusOverrideEntity: Entity | null;
export const focusOverrideOffset: altShared.Vector3;

export function overrideFocus(pos: altShared.IVector3, offset?: altShared.IVector3): void;
export function clearFocusOverride(): void;
}

Expand Down
2 changes: 1 addition & 1 deletion types/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@altv/client",
"version": "0.0.44",
"version": "0.0.45",
"description": "This package contains the type definitions for the alt:V JS module v2 client types",
"types": "index.d.ts",
"files": [
Expand Down

0 comments on commit a996704

Please sign in to comment.