mirror of
https://codeberg.org/demostf/frontend.git
synced 2026-06-03 18:24:12 +02:00
show projectiles in viewer
This commit is contained in:
parent
213d2c6753
commit
22ad43a4b7
7 changed files with 215 additions and 89 deletions
51
script/viewer/Analyse/Render/Projectile.tsx
Normal file
51
script/viewer/Analyse/Render/Projectile.tsx
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import {ProjectileState, ProjectileType, Team, WorldBoundaries} from "../Data/Parser";
|
||||
import {Show} from "solid-js";
|
||||
|
||||
export interface ProjectileProp {
|
||||
projectile: ProjectileState;
|
||||
mapBoundary: WorldBoundaries;
|
||||
targetSize: {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
scale: number;
|
||||
}
|
||||
|
||||
export function Projectile(props: ProjectileProp) {
|
||||
const worldWidth = props.mapBoundary.boundary_max.x - props.mapBoundary.boundary_min.x;
|
||||
const worldHeight = props.mapBoundary.boundary_max.y - props.mapBoundary.boundary_min.y;
|
||||
const x = () => props.projectile.position.x - props.mapBoundary.boundary_min.x;
|
||||
const y = () => props.projectile.position.y - props.mapBoundary.boundary_min.y;
|
||||
const scaledX = () => x() / worldWidth * props.targetSize.width;
|
||||
const scaledY = () => (worldHeight - y()) / worldHeight * props.targetSize.height;
|
||||
const teamColor = () => (props.projectile.team === Team.Red) ? '#a75d50' : '#5b818f';
|
||||
|
||||
const transform = () => `translate(${scaledX()} ${scaledY()}) scale(${1 / props.scale})`;
|
||||
const rotate = () => `rotate(${270 - props.projectile.angle})`;
|
||||
try {
|
||||
return <g transform={transform()}>
|
||||
<Show when={projectileIsAngled(props.projectile.projectileType)}>
|
||||
<polygon points="-3,-4 0,0 3,-4 0,8" stroke="white" fill={teamColor()}
|
||||
transform={rotate()}/>
|
||||
</Show>
|
||||
<Show when={!projectileIsAngled(props.projectile.projectileType)}>
|
||||
<circle r={3} stroke-width={1} stroke="white" fill={teamColor()}/>
|
||||
</Show>
|
||||
</g>
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function projectileIsAngled(type: ProjectileType): boolean {
|
||||
switch (type) {
|
||||
case ProjectileType.Flare:
|
||||
case ProjectileType.HealingArrow:
|
||||
case ProjectileType.Rocket:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue