mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-12 02:35:42 +00:00
feat: use external services for kill data
This commit is contained in:
@@ -17,67 +17,91 @@ import { TooltipPosition } from '@/hooks/Mapper/components/ui-kit';
|
||||
import { WithClassName } from '@/hooks/Mapper/types/common.ts';
|
||||
|
||||
export type CompactKillRowProps = {
|
||||
killDetails: DetailedKill;
|
||||
killDetails?: DetailedKill | null;
|
||||
systemName: string;
|
||||
onlyOneSystem: boolean;
|
||||
} & WithClassName;
|
||||
|
||||
export const KillRowDetail = ({ killDetails, systemName, onlyOneSystem, className }: CompactKillRowProps) => {
|
||||
const {
|
||||
killmail_id = 0,
|
||||
killmail_id,
|
||||
// Victim data
|
||||
victim_char_name = 'Unknown Pilot',
|
||||
victim_alliance_ticker = '',
|
||||
victim_corp_ticker = '',
|
||||
victim_ship_name = 'Unknown Ship',
|
||||
victim_corp_name = '',
|
||||
victim_alliance_name = '',
|
||||
victim_char_id = 0,
|
||||
victim_corp_id = 0,
|
||||
victim_alliance_id = 0,
|
||||
victim_ship_type_id = 0,
|
||||
// Attacker data
|
||||
final_blow_char_id = 0,
|
||||
final_blow_char_name = '',
|
||||
final_blow_alliance_ticker = '',
|
||||
final_blow_alliance_name = '',
|
||||
final_blow_alliance_id = 0,
|
||||
final_blow_corp_ticker = '',
|
||||
final_blow_corp_id = 0,
|
||||
final_blow_corp_name = '',
|
||||
final_blow_ship_type_id = 0,
|
||||
kill_time = '',
|
||||
total_value = 0,
|
||||
} = killDetails || {};
|
||||
|
||||
const attackerIsNpc = final_blow_char_id === 0;
|
||||
|
||||
// Define victim affiliation ticker.
|
||||
const victimAffiliationTicker = victim_alliance_ticker || victim_corp_ticker || 'No Ticker';
|
||||
|
||||
const killValueFormatted = total_value != null && total_value > 0 ? `${formatISK(total_value)} ISK` : null;
|
||||
const killTimeAgo = kill_time ? formatTimeMixed(kill_time) : '0h ago';
|
||||
|
||||
const attackerSubscript = getAttackerSubscript(killDetails);
|
||||
|
||||
const { victimCorpLogoUrl, victimAllianceLogoUrl, victimShipUrl } = buildVictimImageUrls({
|
||||
victim_char_name,
|
||||
victim_alliance_ticker,
|
||||
victim_corp_ticker,
|
||||
victim_ship_name,
|
||||
victim_corp_name,
|
||||
victim_alliance_name,
|
||||
victim_char_id,
|
||||
victim_ship_type_id,
|
||||
victim_corp_id,
|
||||
victim_alliance_id,
|
||||
victim_ship_type_id,
|
||||
// Attacker data
|
||||
final_blow_char_id,
|
||||
final_blow_char_name,
|
||||
final_blow_alliance_ticker,
|
||||
final_blow_alliance_name,
|
||||
final_blow_alliance_id,
|
||||
final_blow_corp_ticker,
|
||||
final_blow_corp_id,
|
||||
final_blow_corp_name,
|
||||
final_blow_ship_type_id,
|
||||
kill_time,
|
||||
total_value,
|
||||
} = killDetails || {};
|
||||
|
||||
// Apply fallback values using nullish coalescing to handle both null and undefined
|
||||
const safeKillmailId = killmail_id ?? 0;
|
||||
const safeVictimCharName = victim_char_name ?? 'Unknown Pilot';
|
||||
const safeVictimAllianceTicker = victim_alliance_ticker ?? '';
|
||||
const safeVictimCorpTicker = victim_corp_ticker ?? '';
|
||||
const safeVictimShipName = victim_ship_name ?? 'Unknown Ship';
|
||||
const safeVictimCorpName = victim_corp_name ?? '';
|
||||
const safeVictimAllianceName = victim_alliance_name ?? '';
|
||||
const safeVictimCharId = victim_char_id ?? 0;
|
||||
const safeVictimCorpId = victim_corp_id ?? 0;
|
||||
const safeVictimAllianceId = victim_alliance_id ?? 0;
|
||||
const safeVictimShipTypeId = victim_ship_type_id ?? 0;
|
||||
const safeFinalBlowCharId = final_blow_char_id ?? 0;
|
||||
const safeFinalBlowCharName = final_blow_char_name ?? '';
|
||||
const safeFinalBlowAllianceTicker = final_blow_alliance_ticker ?? '';
|
||||
const safeFinalBlowAllianceName = final_blow_alliance_name ?? '';
|
||||
const safeFinalBlowAllianceId = final_blow_alliance_id ?? 0;
|
||||
const safeFinalBlowCorpTicker = final_blow_corp_ticker ?? '';
|
||||
const safeFinalBlowCorpId = final_blow_corp_id ?? 0;
|
||||
const safeFinalBlowCorpName = final_blow_corp_name ?? '';
|
||||
const safeFinalBlowShipTypeId = final_blow_ship_type_id ?? 0;
|
||||
const safeKillTime = kill_time ?? '';
|
||||
const safeTotalValue = total_value ?? 0;
|
||||
|
||||
const attackerIsNpc = safeFinalBlowCharId === 0;
|
||||
|
||||
// Define victim affiliation ticker.
|
||||
const victimAffiliationTicker = safeVictimAllianceTicker || safeVictimCorpTicker || 'No Ticker';
|
||||
|
||||
const killValueFormatted = safeTotalValue != null && safeTotalValue > 0 ? `${formatISK(safeTotalValue)} ISK` : null;
|
||||
const killTimeAgo = safeKillTime ? formatTimeMixed(safeKillTime) : '0h ago';
|
||||
|
||||
const attackerSubscript = killDetails ? getAttackerSubscript(killDetails) : undefined;
|
||||
|
||||
const { victimCorpLogoUrl, victimAllianceLogoUrl, victimShipUrl } = buildVictimImageUrls({
|
||||
victim_char_id: safeVictimCharId,
|
||||
victim_ship_type_id: safeVictimShipTypeId,
|
||||
victim_corp_id: safeVictimCorpId,
|
||||
victim_alliance_id: safeVictimAllianceId,
|
||||
});
|
||||
|
||||
const { attackerCorpLogoUrl, attackerAllianceLogoUrl } = buildAttackerImageUrls({
|
||||
final_blow_char_id,
|
||||
final_blow_corp_id,
|
||||
final_blow_alliance_id,
|
||||
final_blow_char_id: safeFinalBlowCharId,
|
||||
final_blow_corp_id: safeFinalBlowCorpId,
|
||||
final_blow_alliance_id: safeFinalBlowAllianceId,
|
||||
});
|
||||
|
||||
const { url: victimPrimaryLogoUrl, tooltip: victimPrimaryTooltip } = getPrimaryLogoAndTooltip(
|
||||
victimAllianceLogoUrl,
|
||||
victimCorpLogoUrl,
|
||||
victim_alliance_name,
|
||||
victim_corp_name,
|
||||
safeVictimAllianceName,
|
||||
safeVictimCorpName,
|
||||
'Victim',
|
||||
);
|
||||
|
||||
@@ -87,25 +111,25 @@ export const KillRowDetail = ({ killDetails, systemName, onlyOneSystem, classNam
|
||||
attackerIsNpc,
|
||||
attackerAllianceLogoUrl,
|
||||
attackerCorpLogoUrl,
|
||||
final_blow_alliance_name,
|
||||
final_blow_corp_name,
|
||||
final_blow_ship_type_id,
|
||||
safeFinalBlowAllianceName,
|
||||
safeFinalBlowCorpName,
|
||||
safeFinalBlowShipTypeId,
|
||||
),
|
||||
[
|
||||
attackerAllianceLogoUrl,
|
||||
attackerCorpLogoUrl,
|
||||
attackerIsNpc,
|
||||
final_blow_alliance_name,
|
||||
final_blow_corp_name,
|
||||
final_blow_ship_type_id,
|
||||
safeFinalBlowAllianceName,
|
||||
safeFinalBlowCorpName,
|
||||
safeFinalBlowShipTypeId,
|
||||
],
|
||||
);
|
||||
|
||||
// Define attackerTicker to use the alliance ticker if available, otherwise the corp ticker.
|
||||
const attackerTicker = attackerIsNpc ? '' : final_blow_alliance_ticker || final_blow_corp_ticker || '';
|
||||
const attackerTicker = attackerIsNpc ? '' : safeFinalBlowAllianceTicker || safeFinalBlowCorpTicker || '';
|
||||
|
||||
// For the attacker image link: if the attacker is not an NPC, link to the character page; otherwise, link to the kill page.
|
||||
const attackerLink = attackerIsNpc ? zkillLink('kill', killmail_id) : zkillLink('character', final_blow_char_id);
|
||||
const attackerLink = attackerIsNpc ? zkillLink('kill', safeKillmailId) : zkillLink('character', safeFinalBlowCharId);
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -121,7 +145,7 @@ export const KillRowDetail = ({ killDetails, systemName, onlyOneSystem, classNam
|
||||
{victimShipUrl && (
|
||||
<div className="relative shrink-0 w-8 h-8 overflow-hidden">
|
||||
<a
|
||||
href={zkillLink('kill', killmail_id)}
|
||||
href={zkillLink('kill', safeKillmailId)}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="block w-full h-full"
|
||||
@@ -137,7 +161,7 @@ export const KillRowDetail = ({ killDetails, systemName, onlyOneSystem, classNam
|
||||
{victimPrimaryLogoUrl && (
|
||||
<WdTooltipWrapper content={victimPrimaryTooltip} position={TooltipPosition.top}>
|
||||
<a
|
||||
href={zkillLink('kill', killmail_id)}
|
||||
href={zkillLink('kill', safeKillmailId)}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="relative block shrink-0 w-8 h-8 overflow-hidden"
|
||||
@@ -153,12 +177,12 @@ export const KillRowDetail = ({ killDetails, systemName, onlyOneSystem, classNam
|
||||
</div>
|
||||
<div className="flex flex-col ml-2 flex-1 min-w-0 overflow-hidden leading-[1rem]">
|
||||
<div className="truncate text-stone-200">
|
||||
{victim_char_name}
|
||||
{safeVictimCharName}
|
||||
<span className="text-stone-400"> / {victimAffiliationTicker}</span>
|
||||
</div>
|
||||
<div className="truncate text-stone-300 flex items-center gap-1">
|
||||
<span className="text-stone-400 overflow-hidden text-ellipsis whitespace-nowrap max-w-[140px]">
|
||||
{victim_ship_name}
|
||||
{safeVictimShipName}
|
||||
</span>
|
||||
{killValueFormatted && (
|
||||
<>
|
||||
@@ -170,9 +194,9 @@ export const KillRowDetail = ({ killDetails, systemName, onlyOneSystem, classNam
|
||||
</div>
|
||||
<div className="flex items-center ml-auto gap-2">
|
||||
<div className="flex flex-col items-end flex-1 min-w-0 overflow-hidden text-right leading-[1rem]">
|
||||
{!attackerIsNpc && (final_blow_char_name || attackerTicker) && (
|
||||
{!attackerIsNpc && (safeFinalBlowCharName || attackerTicker) && (
|
||||
<div className="truncate text-stone-200">
|
||||
{final_blow_char_name}
|
||||
{safeFinalBlowCharName}
|
||||
{!attackerIsNpc && attackerTicker && <span className="ml-1 text-stone-400">/ {attackerTicker}</span>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -33,7 +33,10 @@ export function formatISK(value: number): string {
|
||||
return Math.round(value).toString();
|
||||
}
|
||||
|
||||
export function getAttackerSubscript(kill: DetailedKill) {
|
||||
export function getAttackerSubscript(kill: DetailedKill | undefined) {
|
||||
if (!kill) {
|
||||
return null;
|
||||
}
|
||||
if (kill.npc) {
|
||||
return { label: 'npc', cssClass: 'text-purple-400' };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user