Skip to content

Commit

Permalink
Fix set dimension of marker, progressbar and text label VirtualEntity…
Browse files Browse the repository at this point in the history
… serverside (#99)

Co-authored-by: Leon Enneken <[email protected]>
  • Loading branch information
ShortByte and Leon Enneken authored Jul 10, 2024
1 parent 7858169 commit d15f6f7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
16 changes: 9 additions & 7 deletions src/main/server/controllers/markers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as alt from 'alt-server';
import * as Utility from '@Shared/utility/index.js';
import { Marker, MarkerType } from '@Shared/types/marker.js';
import { Events } from '@Shared/events/index.js';
import { Marker, MarkerType } from '@Shared/types/marker.js';
import * as Utility from '@Shared/utility/index.js';
import * as alt from 'alt-server';

const GroupType = 'marker';
const MAX_MARKERS = 10;
Expand All @@ -28,15 +28,13 @@ export function useMarkerGlobal(marker: Marker, maxDistance: number = 50) {
marker.uid = Utility.uid.generate();
}

if (!marker.dimension) {
marker.dimension = 0;
}

let entity = new alt.VirtualEntity(markerGroup, new alt.Vector3(marker.pos), maxDistance, {
type: GroupType,
marker,
});

entity.dimension = marker.dimension ? marker.dimension : 0;

function destroy() {
try {
entity.destroy();
Expand All @@ -53,6 +51,10 @@ export function useMarkerGlobal(marker: Marker, maxDistance: number = 50) {
type: GroupType,
marker,
});

if (newMarker.dimension !== entity.dimension) {
entity.dimension = newMarker.dimension ? newMarker.dimension : 0;
}
}

return {
Expand Down
10 changes: 4 additions & 6 deletions src/main/server/controllers/progressbar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as alt from 'alt-server';
import * as Utility from '@Shared/utility/index.js';
import { Events } from '@Shared/events/index.js';
import * as Utility from '@Shared/utility/index.js';
import * as alt from 'alt-server';
import { ProgressBar } from '../../shared/types/progressBar.js';

const GroupType = 'progressbar';
Expand Down Expand Up @@ -29,10 +29,6 @@ export function useProgressbarGlobal(progressbar: ProgressBar, isTimer = false,
progressbar.uid = Utility.uid.generate();
}

if (!progressbar.dimension) {
progressbar.dimension = 0;
}

if (isTimer) {
interval = alt.setInterval(() => {
updateProgress(progressbar.value + 1);
Expand All @@ -45,6 +41,8 @@ export function useProgressbarGlobal(progressbar: ProgressBar, isTimer = false,
progressbar,
});

entity.dimension = progressbar.dimension ? progressbar.dimension : 0;

function destroy() {
try {
entity.destroy();
Expand Down
16 changes: 11 additions & 5 deletions src/main/server/controllers/textlabel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as alt from 'alt-server';
import * as Utility from '@Shared/utility/index.js';
import { TextLabel } from '@Shared/types/textLabel.js';
import { Events } from '@Shared/events/index.js';
import { TextLabel } from '@Shared/types/textLabel.js';
import * as Utility from '@Shared/utility/index.js';
import * as alt from 'alt-server';

const GroupType = 'textlabel';
const MAX_LABELS = 10;
Expand Down Expand Up @@ -29,14 +29,16 @@ export function useTextLabelGlobal(label: TextLabel, maxDistance: number = 20) {
textlabel: label,
});

entity.dimension = label.dimension ? label.dimension : 0;

function destroy() {
try {
entity.destroy();
} catch (err) {}
}

function update(newMarker: Partial<TextLabel>) {
label = Object.assign(label, newMarker);
function update(newTextLabel: Partial<TextLabel>) {
label = Object.assign(label, newTextLabel);
try {
entity.destroy();
} catch (err) {}
Expand All @@ -45,6 +47,10 @@ export function useTextLabelGlobal(label: TextLabel, maxDistance: number = 20) {
type: GroupType,
textlabel: label,
});

if (newTextLabel.dimension !== entity.dimension) {
entity.dimension = newTextLabel.dimension ? newTextLabel.dimension : 0;
}
}

return {
Expand Down

0 comments on commit d15f6f7

Please sign in to comment.