kill search

This commit is contained in:
Robin Appelman 2024-12-07 00:11:41 +01:00
commit 72c4b6ee08
10 changed files with 413 additions and 117 deletions

View file

@ -1,68 +1,89 @@
import {Kill, PlayerState} from "../Data/Parser";
import {killAlias} from "./killAlias";
import {For, Show} from "solid-js";
export interface KillFeedProps {
kills: Kill[],
tick: number;
players: PlayerState[];
kills: Kill[],
tick: number;
players: PlayerState[];
}
export function KillFeed(props: KillFeedProps) {
const {kills} = props;
const relevantKills = () => kills.filter(kill => kill.tick <= props.tick && kill.tick >= (props.tick - 30 * 10));
const {kills} = props;
const relevantKills = () => kills.filter(kill => kill.tick <= props.tick && kill.tick >= (props.tick - 30 * 10));
return <div class="killfeed">
<For each={relevantKills()}>{(kill) =>
<KillFeedItem kill={kill} players={props.players}/>
}</For>
</div>
return <ul class="killfeed">
<For each={relevantKills()}>{(kill) =>
<KillFeedItem kill={kill} players={props.players}/>
}</For>
</ul>
}
const teamMap = {
0: 'unknown',
2: 'red',
3: 'blue'
0: 'unknown',
2: 'red',
3: 'blue'
};
export function KillFeedItem({kill, players}: { kill: Kill, players: PlayerState[] }) {
const alias = killAlias[kill.weapon] ? killAlias[kill.weapon] : kill.weapon;
const attacker = getPlayer(players, kill.attacker);
const assister = getPlayer(players, kill.assister);
let victim = getPlayer(players, kill.victim);
let killIcon;
try {
killIcon = `/images/kill_icons/${alias}.png`;
} catch (e) {
console.log(alias);
killIcon = `/images/kill_icons/skull.png`;
}
if (!victim) {
victim = {
team: 0,
info: {
name: 'Missing player'
}
};
}
return <div class="kill">
{(attacker && kill.attacker !== kill.victim) ?
<span class={"player " + teamMap[attacker.team]}>
{attacker.info.name}
</span> : ''}
{(assister && kill.assister !== kill.victim) ?
<span class={teamMap[assister.team]}></span> : ''}
{(assister && kill.assister !== kill.victim) ?
(<span class={"player " + teamMap[assister.team]}>
{assister.info.name}
</span>) : ''}
<img src={killIcon} class={`kill-icon ${kill.weapon}`}/>
<span class={"player " + teamMap[victim.team]}>
{victim.info.name}
</span>
</div>
interface KillFeedItemProps {
kill: Kill;
players: PlayerState[];
}
function getPlayer(players: PlayerState[], entityId: number): PlayerState {
return players.find(player => player.info.userId == entityId);
export function KillFeedItem(props: KillFeedItemProps) {
const attacker = getPlayer(props.players, props.kill.attacker);
const assister = getPlayer(props.players, props.kill.assister);
let victim = getPlayer(props.players, props.kill.victim);
return <li class="kill">
<PlayerNames players={[attacker, assister]}/>
<KillIcon kill={props.kill}/>
<PlayerName player={victim}/>
</li>
}
interface KillIconProps {
kill: Kill;
}
export function KillIcon(props: KillIconProps) {
const alias = killAlias[props.kill.weapon] ? killAlias[props.kill.weapon] : props.kill.weapon;
let killIcon;
try {
killIcon = `/images/kill_icons/${alias}.png`;
} catch (e) {
console.log(alias);
killIcon = `/images/kill_icons/skull.png`;
}
return <img src={killIcon} class={`kill-icon ${props.kill.weapon}`}/>
}
interface PlayerNameProps {
player: PlayerState | null
}
export function PlayerName(props: PlayerNameProps) {
return <Show when={props.player}>
<span className={"player " + teamMap[props.player.team]}>
{props.player.info.name}
</span>
</Show>
}
interface PlayerNamesProps {
players: (PlayerState | null)[]
}
export function PlayerNames(props: PlayerNamesProps) {
return <For each={props.players}>{(player, i) => <>
<Show when={i() > 0 && player}>
<span className={teamMap[player.team]}>+</span>
</Show>
<PlayerName player={player}/>
</>}</For>
}
export function getPlayer(players: PlayerState[], entityId: number): PlayerState | null {
return players.find(player => player.info.userId == entityId);
}

View file

@ -1,38 +1,39 @@
export const killAlias = {
'world': 'skull',
'player': 'skull',
'telefrag': 'skull',
'shotgun_pyro': 'shotgun',
'tf_projectile_pipe_remote': 'stickybomb_launcher',
'the_classic': 'classic',
'tf_projectile_arrow': 'huntsman',
'club': 'kukri',
'shotgun_primary': 'shotgun',
'shotgun_soldier': 'shotgun',
'shotgun_hwg': 'shotgun',
'pickaxe': 'escape_plan',
'tf_projectile_pipe': 'grenade_launcher',
'obj_sentrygun': 'sentrygun1',
'steel_fists': 'fists_of_steel',
'tf_projectile_rocket': 'rocket_launcher',
'obj_sentrygun3': 'sentrygun3',
'obj_sentrygun2': 'sentrygun2',
'worldspawn': 'skull',
'nonnonviolent_protest': 'conscientious_objector',
'deflect_promode': 'deflect_rocket',
'trigger_hurt': 'bleed',
'quake_rl': 'original',
'wrangler_kill': 'wrangler',
'obj_minisentry': 'minisentry',
'pistol_scout': 'pistol',
'bleed_kill': 'bleed',
'maxgun': 'lugermorph',
'rocketlauncher_directhit': 'direct_hit',
'frontier_kill': 'frontier_justice',
'robot_arm_kill': 'gunslinger',
'wrench_jag': 'jag',
'loose_cannon_explosion': 'loose_cannon',
'samrevolver': 'big_kill',
'long_heatmaker': 'huo-long_heater',
'pep_pistol': 'pistol'
'world': 'skull',
'player': 'skull',
'telefrag': 'skull',
'shotgun_pyro': 'shotgun',
'tf_projectile_pipe_remote': 'stickybomb_launcher',
'the_classic': 'classic',
'tf_projectile_arrow': 'huntsman',
'club': 'kukri',
'shotgun_primary': 'shotgun',
'shotgun_soldier': 'shotgun',
'shotgun_hwg': 'shotgun',
'pickaxe': 'escape_plan',
'tf_projectile_pipe': 'grenade_launcher',
'obj_sentrygun': 'sentrygun1',
'steel_fists': 'fists_of_steel',
'tf_projectile_rocket': 'rocket_launcher',
'obj_sentrygun3': 'sentrygun3',
'obj_sentrygun2': 'sentrygun2',
'worldspawn': 'skull',
'nonnonviolent_protest': 'conscientious_objector',
'deflect_promode': 'deflect_rocket',
'trigger_hurt': 'bleed',
'quake_rl': 'original',
'wrangler_kill': 'wrangler',
'obj_minisentry': 'minisentry',
'pistol_scout': 'pistol',
'bleed_kill': 'bleed',
'maxgun': 'lugermorph',
'rocketlauncher_directhit': 'direct_hit',
'frontier_kill': 'frontier_justice',
'robot_arm_kill': 'gunslinger',
'wrench_jag': 'jag',
'loose_cannon_explosion': 'loose_cannon',
'samrevolver': 'big_kill',
'long_heatmaker': 'huo-long_heater',
'pep_pistol': 'pistol',
'ai_flamethrower': 'flamethrower',
};