Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update icon logic #525

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
43 changes: 6 additions & 37 deletions src/components/ladder/CountryRankingsGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,19 @@ import { Component, Prop, Watch } from "vue-property-decorator";
import {
Ranking,
PlayerId,
PlayerInfo,
CountryRanking,
League,
} from "@/store/ranking/types";
import { EAvatarCategory, ERaceEnum, OngoingMatches } from "@/store/typings";
import { ERaceEnum, OngoingMatches } from "@/store/typings";
import PlayerIcon from "@/components/matches/PlayerIcon.vue";
import SwordIcon from "@/components/ladder/SwordIcon.vue";
import LeagueIcon from "@/components/ladder/LeagueIcon.vue";
import PlayerRankInfo from "@/components/ladder/PlayerRankInfo.vue";
import RaceIcon from "@/components/player/RaceIcon.vue";
import CountryFlagExtended from "@/components/common/CountryFlagExtended.vue";
import { getAsset, getAvatarUrl } from "@/helpers/url-functions";
import { TranslateResult } from "vue-i18n";
import LevelProgress from "@/components/ladder/LevelProgress.vue"
import { getRaceIcon, hasSelectedIcon } from "@/helpers/ranking-icons";

@Component({
components: {
Expand Down Expand Up @@ -377,51 +376,21 @@ export default class CountryRankingsGrid extends Vue {
this.leagueMap = new Map(league?.leagues.map((l) => [l.id, l]));
}

public getRaceIcon(ranking: Ranking, playerIndex: number): string {
const playersInfo = ranking.playersInfo;
if (!playersInfo) return this.raceIcon(ERaceEnum.RANDOM);
const playerInfo = playersInfo[playerIndex];
if (CountryRankingsGrid.hasSelectedIcon(playerInfo)) {
return getAvatarUrl(
playerInfo.selectedRace,
playerInfo.pictureId,
playerInfo.isClassicPicture
);
} else {
return this.raceIcon(playerInfo.calculatedRace);
}
getRaceIcon(ranking: Ranking, playerIndex: number): string {
return getRaceIcon(ranking, playerIndex);
}

public getTitleRace(ranking: Ranking, playerIndex: number): TranslateResult {
getTitleRace(ranking: Ranking, playerIndex: number): TranslateResult {
const playersInfo = ranking.playersInfo;
if (!playersInfo) return this.$t("races.RANDOM");
const playerInfo = playersInfo[playerIndex];
if (
CountryRankingsGrid.hasSelectedIcon(playerInfo) &&
playerInfo.selectedRace <= ERaceEnum.UNDEAD
) {
if (hasSelectedIcon(playerInfo)) {
return this.$t(`races.${ERaceEnum[playerInfo.selectedRace]}`);
} else {
return this.$t(`races.${ERaceEnum[playerInfo.calculatedRace]}`);
}
}

private static hasSelectedIcon(playerInfo: PlayerInfo) {
if (
playerInfo.selectedRace !== undefined &&
playerInfo.selectedRace != null &&
playerInfo.pictureId !== undefined &&
playerInfo.pictureId != null
) {
return playerInfo.selectedRace !== EAvatarCategory.TOTAL;
}
return false;
}

raceIcon(race: ERaceEnum) {
return getAsset(`raceIcons/${ERaceEnum[race]}.jpg`);
}

isTwitchLive(ranking: Ranking): boolean {
const twitchName = ranking.playersInfo[0].twitchName;
const streamData =
Expand Down
47 changes: 6 additions & 41 deletions src/components/ladder/RankingsGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@
import Vue from "vue";
import { Component, Prop, Watch } from "vue-property-decorator";
import { Ranking, PlayerId, PlayerInfo } from "@/store/ranking/types";
import { EAvatarCategory, EGameMode, ERaceEnum, OngoingMatches } from "@/store/typings";
import { EGameMode, ERaceEnum, OngoingMatches } from "@/store/typings";
import PlayerIcon from "@/components/matches/PlayerIcon.vue";
import SwordIcon from "@/components/ladder/SwordIcon.vue";
import PlayerRankInfo from "@/components/ladder/PlayerRankInfo.vue";
import CountryFlagExtended from "@/components/common/CountryFlagExtended.vue";
import RaceIcon from "@/components/player/RaceIcon.vue";
import { getAsset, getAvatarUrl } from "@/helpers/url-functions";
import { TranslateResult } from "vue-i18n";
import LevelProgress from "@/components/ladder/LevelProgress.vue"
import { hasSelectedIcon, getRaceIcon } from "@/helpers/ranking-icons";

@Component({
components: {
Expand Down Expand Up @@ -339,56 +339,21 @@ export default class RankingsGrid extends Vue {
}, 500);
}

public getRaceIcon(ranking: Ranking, playerIndex: number): string {
const playersInfo = ranking.playersInfo;
if (!playersInfo) return this.raceIcon(ERaceEnum.RANDOM);
const playerInfo = playersInfo[playerIndex];
if (RankingsGrid.hasSelectedIcon(playerInfo)) {
return getAvatarUrl(
playerInfo.selectedRace,
playerInfo.pictureId,
playerInfo.isClassicPicture
);
} else {
return getAvatarUrl(
playerInfo.selectedRace,
playerInfo.pictureId,
playerInfo.isClassicPicture
);
// old way to get race icon: return this.raceIcon(playerInfo.calculatedRace);
}
getRaceIcon(ranking: Ranking, playerIndex: number): string {
return getRaceIcon(ranking, playerIndex);
}

public getTitleRace(ranking: Ranking, playerIndex: number): TranslateResult {
getTitleRace(ranking: Ranking, playerIndex: number): TranslateResult {
const playersInfo = ranking.playersInfo;
if (!playersInfo) return "Random";
const playerInfo = playersInfo[playerIndex];
if (
RankingsGrid.hasSelectedIcon(playerInfo) &&
playerInfo.selectedRace <= ERaceEnum.UNDEAD
) {
if (hasSelectedIcon(playerInfo)) {
return this.$t(`races.${ERaceEnum[playerInfo.selectedRace]}`);
} else {
return this.$t(`races.${ERaceEnum[playerInfo.calculatedRace]}`);
}
}

private static hasSelectedIcon(playerInfo: PlayerInfo) {
if (
playerInfo.selectedRace !== undefined &&
playerInfo.selectedRace != null &&
playerInfo.pictureId !== undefined &&
playerInfo.pictureId != null
) {
return playerInfo.selectedRace !== EAvatarCategory.TOTAL;
}
return false;
}

raceIcon(race: ERaceEnum) {
return getAsset(`raceIcons/${ERaceEnum[race]}.jpg`);
}

public isTwitchLive(ranking: Ranking, index: number): boolean {
const twitchName = ranking.playersInfo[index].twitchName;
const streamData =
Expand Down
1 change: 0 additions & 1 deletion src/components/player/PlayerHeroWinRate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ export default class PlayerHeroWinRate extends Vue {
[ERaceEnum.HUMAN]: '',
[ERaceEnum.NIGHT_ELF]: '',
[ERaceEnum.RANDOM]: '',
[ERaceEnum.STARTER]: '',
};
const filtered = item.stats
.filter((byRace) => byRace.race == this.selectedRace)[0]
Expand Down
31 changes: 31 additions & 0 deletions src/helpers/ranking-icons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { PlayerInfo, Ranking } from "@/store/ranking/types";
import { ERaceEnum } from "@/store/typings";
import { getAsset, getAvatarUrl } from "./url-functions";

export function getRaceIcon(ranking: Ranking, playerIndex: number): string {
const playersInfo = ranking.playersInfo;
if (!playersInfo) return raceIcon(ERaceEnum.RANDOM);
const playerInfo = playersInfo[playerIndex];
if (hasSelectedIcon(playerInfo)) {
return getAvatarUrl(
playerInfo.selectedRace,
playerInfo.pictureId,
playerInfo.isClassicPicture
);
} else {
return raceIcon(playerInfo.calculatedRace);
}
}

function raceIcon(race: ERaceEnum) {
return getAsset(`raceIcons/${ERaceEnum[race]}.jpg`);
}

export function hasSelectedIcon(playerInfo: PlayerInfo) {
return (
playerInfo.selectedRace !== undefined &&
playerInfo.selectedRace != null &&
playerInfo.pictureId !== undefined &&
playerInfo.pictureId != null
);
}
2 changes: 2 additions & 0 deletions src/locales/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ const data = {
NIGHT_ELF: "Night Elf",
RANDOM: "Random",
TOTAL: "Total",
SPECIAL: "Special",
STARTER: "Starter",
},
racesShort: {
ORC: "OC",
Expand Down
1 change: 0 additions & 1 deletion src/store/player/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,4 @@ export type PlayerHeroWinRateForStatisticsTab = {
[ERaceEnum.HUMAN]: string;
[ERaceEnum.NIGHT_ELF]: string;
[ERaceEnum.RANDOM]: string;
[ERaceEnum.STARTER]: string;
}
3 changes: 2 additions & 1 deletion src/store/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ export enum ERaceEnum {
NIGHT_ELF = 4,
UNDEAD = 8,
TOTAL = 16,
STARTER = 32,
SPECIAL = 32,
STARTER = 64,
}

export enum EAvatarCategory {
Expand Down