Skip to content

Commit

Permalink
fix: tab-menu.ts exception on maps with only placeholder suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
tsa96 committed Nov 29, 2024
1 parent bd7a153 commit 8361acf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
8 changes: 7 additions & 1 deletion scripts/common/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ export function getTier(
: getTrack(staticData, gamemode, trackType, trackNum)?.tier;
}

/** Simplified credit object, derived from either a regular credit or a placeholder suggestion */
export interface SimpleMapCredit {
alias: string;
steamID?: string;
}

/**
* Get collection of simplified credits data, optionally filtered by type.
* If the map is in submission, placeholders suggestions are included, with steamID omitted.
*/
export function getAllCredits(staticData: MMap, type?: MapCreditType): Array<{ alias: string; steamID?: string }> {
export function getAllCredits(staticData: MMap, type?: MapCreditType): SimpleMapCredit[] {
const credits = [];

let normal = staticData.credits;
Expand Down
17 changes: 8 additions & 9 deletions scripts/hud/tab-menu.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { PanelHandler } from 'util/module-helpers';
import { EndOfRunShowReason } from 'common/timer';
import { GamemodeInfo, MapCredit, MapCreditType, MMap } from 'common/web';
import { GamemodeInfo, MapCreditType, MMap } from 'common/web';
import { getNumZones, getTrack } from 'common/leaderboard';
import { getAllCredits, SimpleMapCredit } from 'common/maps';

/**
* Class for the HUD tab menu panel, which contains the leaderboards, end of run, and zoning.
Expand Down Expand Up @@ -65,34 +66,32 @@ class HudTabMenuHandler {

if (mapData && isOfficial) {
this.setMapStats(mapData.staticData);
this.setMapAuthorCredits(mapData.staticData.credits);
this.setMapAuthorCredits(getAllCredits(mapData.staticData, MapCreditType.AUTHOR));
}
}

setMapAuthorCredits(credits: MapCredit[]) {
setMapAuthorCredits(credits: SimpleMapCredit[]) {
// Delete existing name labels
for (const label of this.panels.credits.Children().slice(1) || []) {
label.DeleteAsync(0);
}

const authorCredits = credits.filter(({ type }) => type === MapCreditType.AUTHOR);

for (const credit of authorCredits) {
for (const [idx, { alias, steamID }] of credits.entries()) {
const namePanel = $.CreatePanel('Label', this.panels.credits, '', {
text: credit.user.alias
text: alias
});

namePanel.AddClass('hud-tab-menu-map-info__credits-name');

if (credit.user.steamID) {
// TODO: Perhaps better if left-click just loads momentum profile? Can access steam through that,
// and profile pages no longer require a login to view.
if (steamID) {
namePanel.SetPanelEvent('oncontextmenu', () => {
UiToolkitAPI.ShowSimpleContextMenu('', '', [
{
label: $.Localize('#Action_ShowSteamProfile'),
jsCallback: () => {
SteamOverlayAPI.OpenToProfileID(credit.user.steamID);
SteamOverlayAPI.OpenToProfileID(steamID);
}
}
]);
Expand Down

0 comments on commit 8361acf

Please sign in to comment.