From cc6f5c24adaaf0a5eb89effbb580516bbf3e7286 Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Sun, 27 Sep 2026 02:36:09 -0700 Subject: [PATCH] Preact minor updates batch 51 - Fix Format constructor crash - Fix team privacy not being synced correctly - Fix tournament state after reconnecting - Fix Smogdex links - Support a `Config.includes.htmlDidMount` callback --- .../src/battle-dex-data.ts | 5 ++-- play.pokemonshowdown.com/src/battle-dex.ts | 18 +++++++-------- .../src/battle-team-editor.tsx | 23 +++++++++---------- play.pokemonshowdown.com/src/client-main.ts | 1 + .../src/oldclient/client-teambuilder.js | 23 +++++++++---------- play.pokemonshowdown.com/src/panel-chat.tsx | 2 ++ .../src/panel-mainmenu.tsx | 9 ++++---- play.pokemonshowdown.com/src/panel-rooms.tsx | 1 + 8 files changed, 43 insertions(+), 39 deletions(-) diff --git a/play.pokemonshowdown.com/src/battle-dex-data.ts b/play.pokemonshowdown.com/src/battle-dex-data.ts index 39d8eeebf..68a9fb7ae 100644 --- a/play.pokemonshowdown.com/src/battle-dex-data.ts +++ b/play.pokemonshowdown.com/src/battle-dex-data.ts @@ -42,7 +42,8 @@ export interface FormatData { effectType: 'Format'; } -export class Format implements FormatData { +// note: can't be called "Format" because it conflicts with some ad code +export class BattleFormat implements FormatData { id: ID; name: string; readonly effectType = 'Format'; @@ -1783,5 +1784,5 @@ if (typeof require === 'function') { global.Ability = Ability; global.Item = Item; global.Move = Move; - global.Format = Format; + global.BattleFormat = BattleFormat; } diff --git a/play.pokemonshowdown.com/src/battle-dex.ts b/play.pokemonshowdown.com/src/battle-dex.ts index 9f861546a..b71b779b6 100644 --- a/play.pokemonshowdown.com/src/battle-dex.ts +++ b/play.pokemonshowdown.com/src/battle-dex.ts @@ -21,7 +21,7 @@ import { Pokemon, type ServerPokemon } from "./battle"; import { BattleAvatarNumbers, BattleBaseSpeciesChart, BattlePokemonIconIndexes, BattlePokemonIconIndexesLeft, - Ability, Item, Move, Species, PureEffect, Format, type FormatData, type ID, type NatureEffect, type Type, + Ability, Item, Move, Species, PureEffect, BattleFormat, type FormatData, type ID, type NatureEffect, type Type, } from "./battle-dex-data"; import type * as DexData from "./battle-dex-data"; import type { Teams } from "./battle-teams"; @@ -34,7 +34,7 @@ export declare namespace Dex { export type Item = DexData.Item; export type Move = DexData.Move; export type Species = DexData.Species; - export type Format = DexData.Format; + export type Format = DexData.BattleFormat; export type Type = DexData.Type; export type Nature = DexData.Nature; export type PureEffect = DexData.PureEffect; @@ -515,20 +515,20 @@ export const Dex = new class implements ModdedDex { return this.mod(`gen${gen}` as ID); } formats = { - cache: Object.create(null) as { [id: string]: Format }, - get(name: string): Format { + cache: Object.create(null) as { [id: string]: BattleFormat }, + get(name: string): BattleFormat { const id = toID(name); - this.cache[id] ||= new Format(name, window.BattleFormats?.[id]); + this.cache[id] ||= new BattleFormat(name, window.BattleFormats?.[id]); return this.cache[id]; }, - load(data: { [id: string]: FormatData }): { [id: string]: Format } { + load(data: { [id: string]: FormatData }): { [id: string]: BattleFormat } { // Update in-place so retained references get updated too for (const id in this.cache) { - Object.assign(this.cache[id], new Format(this.cache[id].name, data[id])); + Object.assign(this.cache[id], new BattleFormat(this.cache[id].name, data[id])); } - const formats: { [id: string]: Format } = {}; + const formats: { [id: string]: BattleFormat } = {}; for (const id in data) { - const format = this.cache[id] ||= new Format(data[id].name, data[id]); + const format = this.cache[id] ||= new BattleFormat(data[id].name, data[id]); formats[id] = format; } return formats; diff --git a/play.pokemonshowdown.com/src/battle-team-editor.tsx b/play.pokemonshowdown.com/src/battle-team-editor.tsx index 18c9f84a4..cd26123a3 100644 --- a/play.pokemonshowdown.com/src/battle-team-editor.tsx +++ b/play.pokemonshowdown.com/src/battle-team-editor.tsx @@ -3352,19 +3352,18 @@ class StatForm extends preact.Component<{ } } - let generation: string; - if (editor.isChampions) { - generation = 'champions'; - } else { - let generationNumber = 9; - if (format.startsWith('gen')) { - let number = parseInt(format.charAt(3), 10); - if (1 <= number && number <= 8) { - generationNumber = number; - } - format = format.slice(4); + let generationNumber = 9; + if (format.startsWith('gen')) { + let number = parseInt(format.charAt(3), 10); + if (1 <= number && number <= 8) { + generationNumber = number; } - generation = ['rb', 'gs', 'rs', 'dp', 'bw', 'xy', 'sm', 'ss', 'sv'][generationNumber - 1]; + format = format.slice(4); + } + let generation = ['rb', 'gs', 'rs', 'dp', 'bw', 'xy', 'sm', 'ss', 'sv'][generationNumber - 1]; + if (format.startsWith('champions')) { + generation = 'champions'; + format = format.slice(9); } if (format === 'battlespotdoubles') { smogdexid += '/vgc15'; diff --git a/play.pokemonshowdown.com/src/client-main.ts b/play.pokemonshowdown.com/src/client-main.ts index 8f33f2765..8093c9b08 100644 --- a/play.pokemonshowdown.com/src/client-main.ts +++ b/play.pokemonshowdown.com/src/client-main.ts @@ -45,6 +45,7 @@ export interface PSConfig { mainmenuHTML?: string, roomlistTopHTML?: string, roomlistAfterFirstHTML?: string, + htmlDidMount?: () => void, } | null; routes: { root: string, diff --git a/play.pokemonshowdown.com/src/oldclient/client-teambuilder.js b/play.pokemonshowdown.com/src/oldclient/client-teambuilder.js index 9240cd8af..504d33672 100644 --- a/play.pokemonshowdown.com/src/oldclient/client-teambuilder.js +++ b/play.pokemonshowdown.com/src/oldclient/client-teambuilder.js @@ -2283,19 +2283,18 @@ } } - var generation; - if (this.curTeam.format.includes('champions')) { - generation = 'champions'; - } else { - var generationNumber = 9; - if (format.substr(0, 3) === 'gen') { - var number = parseInt(format.charAt(3), 10); - if (1 <= number && number <= 8) { - generationNumber = number; - } - format = format.substr(4); + var generationNumber = 9; + if (format.substr(0, 3) === 'gen') { + var number = parseInt(format.charAt(3), 10); + if (1 <= number && number <= 8) { + generationNumber = number; } - generation = ['rb', 'gs', 'rs', 'dp', 'bw', 'xy', 'sm', 'ss', 'sv'][generationNumber - 1]; + format = format.substr(4); + } + var generation = ['rb', 'gs', 'rs', 'dp', 'bw', 'xy', 'sm', 'ss', 'sv'][generationNumber - 1]; + if (format.startsWith('champions')) { + generation = 'champions'; + format = format.slice(9); } if (format === 'battlespotdoubles') { smogdexid += '/vgc15'; diff --git a/play.pokemonshowdown.com/src/panel-chat.tsx b/play.pokemonshowdown.com/src/panel-chat.tsx index 24e3b0537..adb646431 100644 --- a/play.pokemonshowdown.com/src/panel-chat.tsx +++ b/play.pokemonshowdown.com/src/panel-chat.tsx @@ -180,6 +180,8 @@ export class ChatRoom extends PSRoom { return false; } override handleReconnect(msg: string): boolean | void { + this.tour = null; + this.dismissNotification('tournament-create'); let lines = msg.split('\n'); // cut off starting lines until we get to PS.lastMessage timestamp diff --git a/play.pokemonshowdown.com/src/panel-mainmenu.tsx b/play.pokemonshowdown.com/src/panel-mainmenu.tsx index 0477003dc..5a0530e93 100644 --- a/play.pokemonshowdown.com/src/panel-mainmenu.tsx +++ b/play.pokemonshowdown.com/src/panel-mainmenu.tsx @@ -472,7 +472,7 @@ export class MainMenuRoom extends PSRoom { team.uploaded = { teamid: response.teamid, notLoaded: false, - private: response.private, + private: response.privacy, }; PS.rooms[`team-${team.key}`]?.update(null); PS.rooms.teambuilder?.update(null); @@ -481,11 +481,11 @@ export class MainMenuRoom extends PSRoom { break; case 'teamupdate': for (const team of PS.teams.list) { - if (team.teamid === response.teamid) { + if (team.teamid === Number(response.teamid)) { team.uploaded = { - teamid: response.teamid, + teamid: team.teamid, notLoaded: false, - private: response.private, + private: response.privacy, }; PS.rooms[`team-${team.key}`]?.update(null); PS.rooms.teambuilder?.update(null); @@ -559,6 +559,7 @@ class MainMenuPanel extends PSRoomPanel { override componentDidMount() { super.componentDidMount(); this.subscribeTo(PSBackground); + Config.includes?.htmlDidMount?.(); } override focus(options?: PSRoomFocusOptions) { if (!options?.preventScroll) PSView.scrollToRoom(); diff --git a/play.pokemonshowdown.com/src/panel-rooms.tsx b/play.pokemonshowdown.com/src/panel-rooms.tsx index 2c9b5a293..ae55b4968 100644 --- a/play.pokemonshowdown.com/src/panel-rooms.tsx +++ b/play.pokemonshowdown.com/src/panel-rooms.tsx @@ -60,6 +60,7 @@ class RoomsPanel extends PSRoomPanel { this.subscriptions.push(PS.user.subscribe(update => { if (!update && PS.user.named) PS.send(`/cmd rooms`); })); + Config.includes?.htmlDidMount?.(); } override componentDidUpdate() { super.componentDidUpdate();