Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Stuyk/rebar-altv
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuyk committed Jul 11, 2024
2 parents 22c74c9 + 6bf7a34 commit f73060b
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/main/client/controllers/blip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ async function handleCreate(blipData: Blip) {
blips[blipData.uid].category = blipData.category;
}

if (typeof blipData.routeColor !== "undefined") {
blips[blipData.uid].route = true;
blips[blipData.uid].routeColor = blipData.routeColor;
}

blips[blipData.uid].sprite = blipData.sprite;
blips[blipData.uid].color = blipData.color;
blips[blipData.uid].shortRange = blipData.shortRange;
Expand Down
9 changes: 7 additions & 2 deletions src/main/client/player/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ function tick() {
}

if (disableAttackControls) {
alt.log('disabling...');

// Scroll Wheel
native.disableControlAction(0, 14, true);
native.disableControlAction(0, 15, true);
Expand Down Expand Up @@ -56,6 +54,13 @@ function setAttackControlsDisabled(state: boolean) {
}
}

export const useControls = () => ({
setControls,
setCameraFrozen,
setCameraControlsDisabled,
setAttackControlsDisabled,
});

alt.onServer(Events.player.controls.set, setControls);
alt.onServer(Events.player.controls.setCameraFrozen, setCameraFrozen);
alt.onServer(Events.player.controls.setCameraControlsDisabled, setCameraControlsDisabled);
Expand Down
1 change: 1 addition & 0 deletions src/main/client/player/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './camera.js';
export * from './controls.js';
1 change: 1 addition & 0 deletions src/main/client/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ import './serverKeypress.js';
import './stats.js';
import './vehicle.js';
import './waypoint.js';
import './world.js';

alt.log('Loaded System');
17 changes: 17 additions & 0 deletions src/main/client/system/world.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as alt from 'alt-client';
import * as native from 'natives';
import { Events } from '@Shared/events/index.js';
import { getStreetInfo, getZone } from '@Client/utility/world/index.js';


alt.onRpc(Events.systems.world.pointDetails, async (point: alt.Vector3) => {
const { streetName, crossingRoad } = getStreetInfo(point);
const zone = getZone(point);
return { zone, streetName, crossingRoad };
});

alt.onRpc(Events.systems.world.travelDistance, async (point1: alt.Vector3, point2: alt.Vector3) => {
return native.calculateTravelDistanceBetweenPoints(
point1.x, point1.y, point1.z, point2.x, point2.y, point2.z
)
});
2 changes: 1 addition & 1 deletion src/main/client/virtualEntities/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function draw() {
if (!marker.scale) {
marker.scale = new alt.Vector3(1, 1, 1);
}
ScreenMarker.draw(marker.type, marker.entity.pos, marker.scale, marker.color, false, false, false);
ScreenMarker.draw(marker.type as number, marker.entity.pos, marker.scale, marker.color, marker.bobUpAndDown ?? false, marker.faceCamera ?? false, marker.rotate ?? false);
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/main/server/player/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@ export function useWorld(player: alt.Player) {
player.emit(Events.player.screen.ped.show, false);
}

async function getPointDetails(point: alt.Vector3): Promise<{
streetName: string;
zone: string;
crossingRoad: string;
}> {
if (!player || !player.valid) return;
return await player.emitRpc(Events.systems.world.pointDetails, point);
}

async function getTravelDistance(point1: alt.Vector3, point2: alt.Vector3 = undefined): Promise<number> {
if (!player || !player.valid) return;
point2 = point2 ?? player.pos;
const result = await player.emitRpc(Events.systems.world.travelDistance, point1, point2);
return result;
}

return {
clearAllScreenEffects,
clearScreenBlur,
Expand All @@ -205,5 +221,7 @@ export function useWorld(player: alt.Player) {
setTimecycle,
setWeather,
showPedOnScreen,
getPointDetails,
getTravelDistance,
};
}
4 changes: 4 additions & 0 deletions src/main/shared/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export const Events = {
},
},
systems: {
world: {
pointDetails: 'systems:world:pointDetails',
travelDistance: 'systems:world:routeLength',
},
keybinds: {
update: 'systems:keybinds:update',
invoke: 'systems:keybinds:invoke',
Expand Down
15 changes: 10 additions & 5 deletions src/main/shared/translate.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
const translations = {};

export function useTranslate(lang: string = 'en') {
function replaceVariables(text: string, vars: { [key: string]: string }): string {
return text.replace(/{{\s*([^}]+)\s*}}/g, (_, key) => vars[key.trim()] || '');
}

/**
* Translate text based on key
*
* @param {string} key
* @param context
* @return
*/
function t(key: string) {
function t(key: string, context?: Record<string, any>) {
if (!translations[lang]) {
return `${key} has no translation for '${lang}'`;
}
Expand All @@ -16,7 +21,7 @@ export function useTranslate(lang: string = 'en') {
return `${key} has no translation for '${lang}'`;
}

return translations[lang][key];
return replaceVariables(translations[lang][key], context);
}

/**
Expand Down Expand Up @@ -48,13 +53,13 @@ export function useTranslate(lang: string = 'en') {
*
* @param {{ [key: string]: Object }} data
*/
function setBulk(data: { [key: string]: Object }) {
for (let lang of Object.keys(data)) {
function setBulk(data: Record<string, Record<string, string>>) {
for (const lang of Object.keys(data)) {
if (!translations[lang]) {
translations[lang] = {};
}

for (let key of Object.keys(data[lang])) {
for (const key of Object.keys(data[lang])) {
translations[lang][key] = data[lang][key];
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/shared/types/blip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,11 @@ export type Blip = {
*
*/
category?: number;

/**
* The color of a route.
*
* @type {number}
*/
routeColor?: alt.RGBA;
};
3 changes: 3 additions & 0 deletions src/main/shared/types/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ export type MarkerBase = {

export type Marker = {
type: number | keyof typeof MarkerType;
bobUpAndDown?: boolean;
faceCamera?: boolean;
rotate?: boolean;
} & MarkerBase;

0 comments on commit f73060b

Please sign in to comment.