import React from 'react'; import { Bomb } from 'csgogsi-socket'; import maps, { ScaleConfig, MapConfig, ZoomAreas } from './maps'; import './index.css'; import { RadarPlayerObject, RadarGrenadeObject } from './interface'; import config from './config'; interface IProps { players: RadarPlayerObject[]; grenades: RadarGrenadeObject[]; bomb?: Bomb | null; mapName: string; zoom?: ZoomAreas; mapConfig: MapConfig, reverseZoom: string, parsePosition: (position: number[], size: number, config: ScaleConfig) => number[] } const isShooting = (lastShoot: number) => (new Date()).getTime() - lastShoot <= 250; class App extends React.Component { constructor(props: IProps) { super(props); this.state = { players: [], grenades: [], bomb: null } } renderGrenade = (grenade: RadarGrenadeObject) => { if ("flames" in grenade) { return null; } const { reverseZoom } = this.props; return (
) } renderDot = (player: RadarPlayerObject) => { const { reverseZoom } = this.props; return (
{player.label}
) } renderBomb = () => { const { bomb, mapConfig, reverseZoom } = this.props; if(!bomb) return null; if(bomb.state === "carried" || bomb.state === "planting") return null; if("config" in mapConfig){ const position = this.props.parsePosition(bomb.position, 30, mapConfig.config); if(!position) return null; return (
) } return mapConfig.configs.map(config => { const position = this.props.parsePosition(bomb.position, 30, config.config); if(!position) return null; return (
) }); } render() { const { players, grenades, zoom } = this.props; const style: React.CSSProperties = { backgroundImage: `url(${maps[this.props.mapName].file})` } if(zoom){ style.transform = `scale(${zoom.zoom})`; style.transformOrigin = `${zoom.origin[0]}px ${zoom.origin[1]}px`; } //if(players.length === 0) return null; return
{players.map(this.renderDot)} {grenades.map(this.renderGrenade)} {this.renderBomb()}
; } } export default App;