Skip to content

Commit

Permalink
Merge pull request #68 from xadamxk/feature/recently-played-additions
Browse files Browse the repository at this point in the history
Add champion name to recently played entry
  • Loading branch information
xadamxk authored Jul 17, 2021
2 parents a05a363 + 2e9fcb1 commit 4503a63
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lcu-enhancement-suite",
"version": "1.1.0",
"version": "1.1.1",
"description": "Enhancements for the League of Legends client.",
"author": "xadamxk",
"contributors": [
Expand Down Expand Up @@ -116,4 +116,4 @@
"webpack-cli": "3.3.12",
"zone.js": "0.11.1"
}
}
}
5 changes: 5 additions & 0 deletions src/electron/core/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ declare module '../../connector' {
changeAvailability(availability: LOLChatAvailability): Promise<Response>;
getCurrentVersion(): Promise<Response>;
getChampionIcon(championId: number): Promise<Response>;
getChampionSelectChampions(): Promise<Response>;
}
}

Expand Down Expand Up @@ -93,3 +94,7 @@ LeagueConnection.prototype.getCurrentVersion = async function(this): Promise<Res
LeagueConnection.prototype.getChampionIcon = async function(championId): Promise<Response> {
return await this.get(`/lol-game-data/assets/v1/champion-icons/${championId}.png`);
};

LeagueConnection.prototype.getChampionSelectChampions = async function(): Promise<Response> {
return await this.get(Endpoints.CHAMPION_SELECT_ALL_CHAMPS);
};
1 change: 1 addition & 0 deletions src/electron/enums/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum Endpoints {
CHAMPION_SELECT_ALL_CHAMPS = '/lol-champ-select/v1/all-grid-champions',
CHAT_ME = '/lol-chat/v1/me',
END_OF_GAME_STATS = '/lol-end-of-game/v1/eog-stats-block',
INVITATIONS = '/lol-lobby/v2/lobby/invitations',
Expand Down
30 changes: 30 additions & 0 deletions src/electron/models/cs-champion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Model } from '../api';

export class CSChampion extends Model {
disabled: boolean;
freeToPlay: boolean;
freeToPlayForQueue: boolean;
freeToPlayReward: boolean;
id: number;
masteryChestGranted: boolean;
masteryLevel: number;
masteryPoints: number;
name: string;
owned: boolean;
positionsFavorited: any[];
rented: boolean;
roles: string[];
selectionStatus: SelectionStatus;
squarePortraitPath: string;
}

class SelectionStatus {
banIntented: boolean;
banIntentedByMe: boolean;
isBanned: boolean;
pickIntented: boolean;
pickIntentedByMe: boolean;
pickIntentedPosition: string;
pickedByOtherOrBanned: boolean;
selectedByMe: boolean;
}
1 change: 1 addition & 0 deletions src/electron/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from './eog-data';
export * from './eog-player';
export * from './eog-stats';
export * from './eog-team';
export * from './cs-champion';
12 changes: 10 additions & 2 deletions src/electron/modules/recently-played.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StatusCode } from '../../connector';
import { WebSocketModule } from '../api';
import { connection } from '../core';
import { Endpoints, GameflowPhase } from '../enums';
import { RecentlyPlayedSummoner } from '../models';
import { RecentlyPlayedSummoner, CSChampion } from '../models';
import { GameflowPhaseSubscription } from '../subscriptions';

export class RecentlyPlayedModule extends WebSocketModule {
Expand All @@ -30,6 +30,8 @@ export class RecentlyPlayedModule extends WebSocketModule {
submenu: submenu
});

const champions: CSChampion[] = await (await connection.getChampionSelectChampions()).json();

await this.updateMenu(menuItem);

const response = await connection.get(Endpoints.RECENTLY_PLAYED_SUMMONERS);
Expand Down Expand Up @@ -58,8 +60,14 @@ export class RecentlyPlayedModule extends WebSocketModule {
Object.keys(summonersByGame).reverse().forEach((gameId, index, reversedGameIds) => {
// append each unique player in game
summonersByGame[gameId].forEach(async(summoner: RecentlyPlayedSummoner) => {
const championNameMatch = champions.filter((champion: CSChampion) => {
return champion.id == summoner.championId;
});

const championName = championNameMatch ? championNameMatch[0].name : 'N/A';

submenu.append(new MenuItem({
label: summoner.summonerName,
label: `${summoner.summonerName} (${championName})`,
sublabel: `Played: ${summoner.gameCreationDate.fromNow()}`,
click: async() => {
const response = await connection.inviteSummoners(summoner.summonerId);
Expand Down

0 comments on commit 4503a63

Please sign in to comment.