Skip to content

Commit

Permalink
Added shooting & flashed indicator to radar
Browse files Browse the repository at this point in the history
  • Loading branch information
osztenkurden committed Feb 18, 2022
1 parent d4a7534 commit 7b301b8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/HUD/Radar/LexoRadar/LexoRadar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class App extends React.Component<IProps> {
renderDot = (player: RadarPlayerObject) => {
return (
<div key={player.id}
className={`player ${player.side} ${player.hasBomb ? 'hasBomb':''} ${player.isActive ? 'active' : ''} ${!player.isAlive ? 'dead' : ''} ${player.visible ? 'visible':'hidden'}`}
className={`player ${player.shooting? 'shooting':''} ${player.side} ${player.hasBomb ? 'hasBomb':''} ${player.isActive ? 'active' : ''} ${!player.isAlive ? 'dead' : ''} ${player.visible ? 'visible':'hidden'}`}
style={{
transform: `translateX(${player.position[0]}px) translateY(${player.position[1]}px) translateZ(10px)`,
width: config.playerSize,
Expand Down
28 changes: 26 additions & 2 deletions src/HUD/Radar/LexoRadar/LexoRadarContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import config from './config';

let playersStates: Player[][] = [];
let grenadesStates: ExtendedGrenade[][] = [];
const directions: { [key: string]: number } = {};
const directions: Record<string, number> = {};
type ShootingState = {
ammo: number,
weapon: string,
lastShoot: number
}
let shootingState: Record<string, ShootingState> = {};

const calculateDirection = (player: Player) => {
if (directions[player.steamid] && !player.state.health) return directions[player.steamid];
Expand Down Expand Up @@ -116,6 +122,22 @@ class App extends React.Component<IProps> {
if (!(this.props.mapName in maps)) {
return null;
}

const weapons = player.weapons ? Object.values(player.weapons) : [];
const weapon = weapons.find(weapon => weapon.state === "active" && weapon.type !== "C4" && weapon.type !== "Knife" && weapon.type !== "Grenade");

const shooting: ShootingState = { ammo: weapon && weapon.ammo_clip || 0, weapon: weapon && weapon.name || '', lastShoot: 0 };

const lastShoot = shootingState[player.steamid] || shooting;

let isShooting = false;

if(shooting.weapon === lastShoot.weapon && shooting.ammo < lastShoot.ammo){
isShooting = true;
}

shootingState[player.steamid] = shooting;

const map = maps[this.props.mapName];
const playerObject: RadarPlayerObject = {
id: player.steamid,
Expand All @@ -127,7 +149,9 @@ class App extends React.Component<IProps> {
forward: 0,
steamid: player.steamid,
isAlive: player.state.health > 0,
hasBomb: !!Object.values(player.weapons).find(weapon => weapon.type === "C4")
hasBomb: !!Object.values(player.weapons).find(weapon => weapon.type === "C4"),
flashed: player.state.flashed > 35,
shooting: isShooting
}
if ("config" in map) {
const position = this.getPosition(player, map.config);
Expand Down
19 changes: 19 additions & 0 deletions src/HUD/Radar/LexoRadar/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,29 @@ html, body, .map-container {
.map .player:not(.dead) {
z-index: 2;
}

.map .player.flashed.CT:not(.dead) .label {
background: rgb(159 197 255);
}
.map .player.flashed.T:not(.dead) .label {
background: rgb(255 219 165);
}
.map .player.active .background {
width:120%;
height:120%;
}


.map .player.shooting .background {
width: 110%;
height: 110%;
}

.map .player.active.shooting .background {
width: 132%;
height: 132%;
}

.map .player.active {
width:120%;
height:120%;
Expand Down
2 changes: 2 additions & 0 deletions src/HUD/Radar/LexoRadar/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export interface RadarPlayerObject {
isAlive: boolean,
steamid: string,
hasBomb: boolean,
flashed: boolean,
shooting: boolean
}

export interface RadarGrenadeObject {
Expand Down

0 comments on commit 7b301b8

Please sign in to comment.