Skip to content

Commit

Permalink
feat(speedometer): ajustando logica para atualizacao de speedometer
Browse files Browse the repository at this point in the history
  • Loading branch information
gregsnn committed Jul 3, 2023
1 parent 75a66fe commit 9bd58a5
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/core/client/menu/staff/spawn-carros-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function spawnCarrosItem(): NativeMenuItem {
Zentorno: 'zentorno',
Osiris: 'osiris',
Deluxo: 'deluxo',
Neon: 'neon',
}

let spawnItem = new NativeUI.UIMenuListItem(
Expand Down
1 change: 1 addition & 0 deletions src/core/client/rmlui/fonts/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import alt from 'alt-client'

alt.loadRmlFont('./pricedown.otf', 'pricedown')
alt.loadRmlFont('./impact.ttf', 'impact')
1 change: 1 addition & 0 deletions src/core/client/rmlui/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import './dinheiro/index'
import './speedometer/index'
78 changes: 78 additions & 0 deletions src/core/client/rmlui/speedometer/index.rml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<rml>

<head>
<title>Speedometer</title>
<style>
* {
margin: 0;
padding: 0;
}

body {
height: 100%;
width: 100%;
}

#speedometer-container {
width: 180px;
height: 75px;

position: absolute;

bottom: 10px;
right: 0;

font-family: impact;
}

#gear {
position: relative;
bottom: 0;

font-size: 24px;
padding: 0 11px;
font-weight: bold;

font-family: impact;
}

.speed {
position: relative;
right: 0;
top: 0;
width: 150px;
font-size: 80px;
color: #b7b7b7;

font-family: impact;
}

#unit {
position: absolute;
right: 0;
top: 0;
font-weight: 400;
font-size: 16px;
color: #dedede;

font-family: impact;
}

.hide {
display: none;
}
</style>
</head>

<body>
<div id="speedometer-container" class="hide">
<div class='speed'>
<div id='gear'></div>

<span id='speed'></span>

<div id='unit'>kmh</div>
</div>
</div>
</body>
</rml>
52 changes: 52 additions & 0 deletions src/core/client/rmlui/speedometer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as alt from 'alt-client'
import {
velocidadeParaString,
converterVelocidadeParaKmh,
definirRmlui,
isEletrico,
marcha,
velocidade,
velocidadeRML,
conditions,
} from '@lg-client/rmlui/speedometer/veiculo/functions'
import { MARCHA } from '@lg-client/rmlui/speedometer/veiculo/marcha'
import { Marcha, Veiculo } from '@lg-client/rmlui/speedometer/veiculo/types'
import { TipoCarro } from '@lg-client/rmlui/speedometer/veiculo/enums'

const document = new alt.RmlDocument('./index.rml')
const rootElement = document.getElementByID('speedometer-container')
const gear = document.getElementByID('gear')
const speed = document.getElementByID('speed')

let intervalo: number

alt.on('enteredVehicle', (vehicle, seat) => {
intervalo = alt.setInterval(() => {
if (vehicle && seat === 1) {
rootElement!.removeClass('hide')

const modeloVeiculo: Veiculo = isEletrico(vehicle.model) ? TipoCarro.ELETRICO : TipoCarro.STANDARD

const atualVelocidade = converterVelocidadeParaKmh(vehicle.speed)

let atualMarcha = vehicle.gear
let ordemMarcha: Marcha = MARCHA[modeloVeiculo]
let indexMarcha: number

indexMarcha = conditions(atualVelocidade, atualMarcha)

atualMarcha = ordemMarcha[indexMarcha]

definirRmlui(marcha(gear!, atualMarcha), velocidade(speed!, velocidadeRML(atualVelocidade)))
}
}, 500)
})

alt.on('leftVehicle', () => {
alt.clearInterval(intervalo)

gear!.innerRML = 'N'
speed!.innerRML = '000'

rootElement!.addClass('hide')
})
4 changes: 4 additions & 0 deletions src/core/client/rmlui/speedometer/veiculo/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum TipoCarro {
STANDARD = 'standard',
ELETRICO = 'eletrico',
}
42 changes: 42 additions & 0 deletions src/core/client/rmlui/speedometer/veiculo/functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as alt from 'alt-client'
import { CARROS_ELETRICOS } from '@lg-client/rmlui/speedometer/veiculo/tipo'
import { Marcha, Rml } from '@lg-client/rmlui/speedometer/veiculo/types'
import { MARCHA } from '@lg-client/rmlui/speedometer/veiculo/marcha'

export const converterVelocidadeParaKmh = (speed: number): number => {
return speed * 3.6 * 1.60934421012
}

export const velocidadeParaString = (speed: number): string => {
return speed.toFixed(0)
}

export const isEletrico = (model: number): boolean => {
return CARROS_ELETRICOS.includes(model)
}

export const definirRmlui = (marcha: Rml, velocidade: Rml): void => {
marcha.id.innerRML = marcha.atual
velocidade.id.innerRML = velocidade.atual.toString()
}

export const velocidadeRML = (atualVelocidade): string => {
const velocidadeString = velocidadeParaString(atualVelocidade)
const velocidadeComprimento = velocidadeString.length
const comprimentoDesejado = Math.max(1, velocidadeComprimento)
return velocidadeString.padStart(comprimentoDesejado, '0')
}

export const marcha = (id, atual): Rml => ({ id, atual })

export const velocidade = (id, atual): Rml => ({ id, atual })

export const conditions = (atualVelocidade: number, atualMarcha: number) => {
const conditions = {
0: atualVelocidade === 0 ? 1 : atualVelocidade > 0 ? 0 : 1,
1: 2,
6: 7,
}

return conditions.hasOwnProperty(atualMarcha) ? conditions[atualMarcha] : atualMarcha + 1
}
6 changes: 6 additions & 0 deletions src/core/client/rmlui/speedometer/veiculo/marcha.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Marcha } from '@lg-client/rmlui/speedometer/veiculo/types'

export const MARCHA: Marcha = {
standard: ['R', 'N', 1, 2, 3, 4, 5, 6],
eletrico: ['R', 'N', 'D'],
}
14 changes: 14 additions & 0 deletions src/core/client/rmlui/speedometer/veiculo/tipo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const CARROS_ELETRICOS: number[] = [
2445973230, // neon
1560980623, // airtug
1147287684, // caddy1
3757070668, // caddy2
3525819835, // caddy3
3164157193, // dilettante
2400073108, // surge
544021352, // khamelion
2672523198, // voltic
1031562256, // tezeract
1392481335, // cyclone
2765724541, // raiden
]
10 changes: 10 additions & 0 deletions src/core/client/rmlui/speedometer/veiculo/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { RmlElement } from 'alt-client'

export type Marcha = { standard: (string | number)[] } | { eletrico: string[] }

export type Veiculo = 'standard' | 'eletrico'

export type Rml = {
id: RmlElement
atual: string
}

0 comments on commit 9bd58a5

Please sign in to comment.