-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(speedometer): ajustando logica para atualizacao de speedometer
- Loading branch information
Showing
11 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
import './dinheiro/index' | ||
import './speedometer/index' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum TipoCarro { | ||
STANDARD = 'standard', | ||
ELETRICO = 'eletrico', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |