Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/components/Match/StyledMatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,32 @@ export const StyledPlayersDeath = styled.div`
height: 29px;
}
`;
export const StyledDeathsSummary = styled.div`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we move away from styled-components for new code. I think we're trying to replace it with css modules

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

happy to, but i'd rather not set the pattern from a feature PR. there's no .module.css in the repo yet and the README still lists styled-components, so whatever i write here becomes the convention by default.

what stopped me is constants.ts. these styles use colorMutedLight and a css module can't read it, so converting means hardcoding rgba(255, 255, 255, 0.6) in the file.

i wrote up the longer version in #3072 along with what's changed since you opened it. would rather settle it there and keep this PR consistent with the rest of the Match components. if you'd still prefer the css module here i'll just do it.

display: flex;
flex-wrap: wrap;
gap: 4px;
max-width: 260px;

& .death {
display: flex;
flex-direction: column;
align-items: center;
width: 34px;

& img,
& svg {
height: 18px;
width: auto;
border-radius: 2px;
}

& span {
font-size: 10px;
margin-top: 1px;
color: ${constants.colorMutedLight};
}
}
`;
export const StyledEmote = styled.img.attrs<{ emote?: string }>({
alt: (props: { emote?: string }) => props.emote,
src: (props: { emote?: string }) =>
Expand Down
103 changes: 103 additions & 0 deletions src/components/Match/matchColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
StyledAbilityUpgrades,
StyledBackpack,
StyledCosmetic,
StyledDeathsSummary,
StyledDivClearBoth,
StyledPlayersDeath,
StyledRunes,
Expand All @@ -37,6 +38,8 @@ import {
StyledLevel,
StyledLineWinnerSpan,
} from "./StyledMatch";
import sword from "../Icons/Sword.svg";
import lightning from "../Icons/Lightning.svg";
import TargetsBreakdown from "./TargetsBreakdown";
import HeroImage from "./../Visualizations/HeroImage";
import ItemTooltip from "../ItemTooltip/ItemTooltip";
Expand Down Expand Up @@ -1439,6 +1442,105 @@ export default (strings: Strings, beta = false) => {
})),
);

const deathIcon = (key: string) => {
const killer = heroNames[key];
if (killer) {
return <HeroImage id={killer.id} isIcon />;
}
if (
key &&
(key.includes("tower") || key.includes("rax") || key.includes("fort"))
) {
return <img src={lightning} alt="" />;
}
return <img src={sword} alt="" />;
};

const deathsColumns = [
heroTdColumn,
{
displayName: strings.th_deaths,
field: "deaths_log",
sortFn: (row: MatchPlayer) => (row.deaths_log || []).length,
displayFn: (row: MatchPlayer, col: any, value: any) => value || "-",
relativeBars: true,
sumFn: (acc: number, row: MatchPlayer) =>
(acc || 0) + (row.deaths_log || []).length,
},
{
displayName: strings.th_gold_lost,
field: "deaths_log",
sortFn: (row: MatchPlayer) =>
(row.deaths_log || []).reduce((s, d) => s + (d.gold_lost || 0), 0),
displayFn: (row: MatchPlayer, col: any, value: any) =>
value ? abbreviateNumber(value) : "-",
relativeBars: true,
sumFn: (acc: number, row: MatchPlayer) =>
(acc || 0) +
(row.deaths_log || []).reduce((s, d) => s + (d.gold_lost || 0), 0),
},
{
displayName: strings.th_time_dead,
field: "deaths_log",
sortFn: (row: MatchPlayer) =>
(row.deaths_log || []).reduce((s, d) => s + (d.time_dead || 0), 0),
displayFn: (row: MatchPlayer, col: any, value: any) =>
value ? formatSeconds(value) : "-",
relativeBars: true,
sumFn: (acc: number, row: MatchPlayer) =>
(acc || 0) +
(row.deaths_log || []).reduce((s, d) => s + (d.time_dead || 0), 0),
displaySumFn: (total: number) => formatSeconds(total || 0),
},
{
displayName: strings.th_killed_by,
field: "deaths_log",
displayFn: (row: MatchPlayer, col: any, field: any) => {
if (!field || !field.length) {
return "-";
}
return (
<StyledDeathsSummary>
{field.map((death: any, i: number) => {
const killer = heroNames[death.key];
const killerName = killer
? killer.localized_name
: (death.key || "")
.replace(/^npc_dota_(goodguys_|badguys_)?/, "")
.replace(/_/g, " ");
const tooltip = [
formatTemplateToString(strings.tooltip_death_killed_by, {
killer: killerName,
time: formatSeconds(death.time),
}),
death.gold_lost
? formatTemplateToString(strings.tooltip_death_gold_lost, {
gold: death.gold_lost,
})
: null,
death.time_dead != null
? formatTemplateToString(strings.tooltip_death_time_dead, {
time: formatSeconds(death.time_dead),
})
: null,
]
.filter(Boolean)
.join(" · ");
return (
<Tooltip title={tooltip} key={i}>
<div className="death">
{deathIcon(death.key)}
<span>{formatSeconds(death.time)}</span>
</div>
</Tooltip>
);
})}
</StyledDeathsSummary>
);
},
},
];

const inflictorsColumns = [
heroTdColumn,
{
Expand Down Expand Up @@ -1913,6 +2015,7 @@ export default (strings: Strings, beta = false) => {
benchmarksColumns,
castsColumns,
cosmeticsColumns,
deathsColumns,
fantasyColumns,
goldReasonsColumns,
heroTd,
Expand Down
12 changes: 12 additions & 0 deletions src/components/Match/matchPages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const matchPages = (
cosmeticsColumns,
// goldReasonsColumns,
// xpReasonsColumns,
deathsColumns,
objectiveDamageColumns,
// analysisColumns,
inflictorsColumns,
Expand Down Expand Up @@ -170,6 +171,17 @@ const matchPages = (
<CrossTable match={match} field1="damage" field2="damage_taken" />
</StyledFlexElement>
</StyledFlexContainer>
{match.players.some((p) => p.deaths_log?.length) && (
<TeamTable
players={match.players}
columns={deathsColumns}
heading={strings.heading_deaths}
radiantTeam={match.radiant_team}
direTeam={match.dire_team}
radiantWin={match.radiant_win}
summable
/>
)}
<TeamTable
players={match.players}
columns={inflictorsColumns}
Expand Down
1 change: 1 addition & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type MatchPlayer = {
killed_by: Record<string, any>;
damage_taken: Record<string, number>;
kills_log: any[];
deaths_log: any[];
player_slot: number;
damage: Record<string, any>;
name: string;
Expand Down
6 changes: 6 additions & 0 deletions src/lang/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,12 @@
"th_kills_per_min": "KPM",
"th_deaths": "D",
"th_deaths_per_min": "DPM",
"th_gold_lost": "Gold Lost",
"th_time_dead": "Time Dead",
"th_killed_by": "Killed By",
"tooltip_death_killed_by": "Died to {killer} at {time}",
"tooltip_death_gold_lost": "{gold} gold lost",
"tooltip_death_time_dead": "{time} dead",
"th_assists": "A",
"th_assists_per_min": "AsPM",
"th_last_hits": "LH",
Expand Down
Loading