Preact minor updates batch 51
Some checks failed
Node.js CI / build (22.x) (push) Has been cancelled

- 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
This commit is contained in:
Guangcong Luo
2026-09-27 02:36:09 -07:00
parent c0f6bfc707
commit cc6f5c24ad
8 changed files with 43 additions and 39 deletions

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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';

View File

@@ -45,6 +45,7 @@ export interface PSConfig {
mainmenuHTML?: string,
roomlistTopHTML?: string,
roomlistAfterFirstHTML?: string,
htmlDidMount?: () => void,
} | null;
routes: {
root: string,

View File

@@ -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';

View File

@@ -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

View File

@@ -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<MainMenuRoom> {
override componentDidMount() {
super.componentDidMount();
this.subscribeTo(PSBackground);
Config.includes?.htmlDidMount?.();
}
override focus(options?: PSRoomFocusOptions) {
if (!options?.preventScroll) PSView.scrollToRoom();

View File

@@ -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();