Preact minor updates batch 26

- Don't cut off joinLeave batch for uhtml changes
- Don't autoclose expired rooms
- Fix crash when importing/exporting certain teams
- Fix room focus when closing popups
- Don't highlight for `/uhtml` and `/uhtmlchange`
This commit is contained in:
Guangcong Luo 2025-06-04 00:35:11 +00:00
parent a7466affc0
commit 775743cd33
6 changed files with 27 additions and 9 deletions

View File

@ -143,7 +143,6 @@ export class BattleLog {
let divClass = 'chat';
let divHTML = '';
let noNotify: boolean | undefined;
if (!['join', 'j', 'leave', 'l'].includes(args[0])) this.joinLeave = null;
if (!['name', 'n'].includes(args[0])) this.lastRename = null;
switch (args[0]) {
case 'chat': case 'c': case 'c:':
@ -332,9 +331,13 @@ export class BattleLog {
default:
this.addBattleMessage(args, kwArgs);
this.joinLeave = null;
return;
}
if (divHTML) this.addDiv(divClass, divHTML, preempt);
if (divHTML) {
this.addDiv(divClass, divHTML, preempt);
this.joinLeave = null;
}
}
addBattleMessage(args: Args, kwArgs?: KWArgs) {
switch (args[0]) {

View File

@ -693,6 +693,7 @@ export class TeamEditor extends preact.Component<{
override render() {
this.editor ||= new TeamEditorState(this.props.team);
const editor = this.editor;
window.editor = editor; // debug
editor.setReadonly(!!this.props.readOnly);
editor.narrow = this.props.narrow ?? document.body.offsetWidth < 500;
if (this.props.team.format !== editor.format) {

View File

@ -155,6 +155,7 @@ export const Teams = new class {
const team = [];
let i = 0;
let j = 0;
let lastI = 0;
while (true) {
const set: Teams.PokemonSet = {} as any;
@ -263,8 +264,9 @@ export const Teams = new class {
set.dynamaxLevel = (misc[4] ? Number(misc[4]) : undefined);
set.teraType = misc[5] || undefined;
}
if (j < 0) break;
i = j + 1;
if (j < 0 || i <= lastI) break;
lastI = i;
}
return team;
@ -274,6 +276,7 @@ export const Teams = new class {
const team = [];
let i = 0;
let lastI = 0;
while (true) {
const name = buf.slice(i, buf.indexOf('|', i));
@ -287,7 +290,8 @@ export const Teams = new class {
i = buf.indexOf(']', i) + 1;
if (i < 1) break;
if (i < 1 || i <= lastI) break;
lastI = i;
}
return team;

View File

@ -2067,7 +2067,7 @@ export const PS = new class extends PSModel {
continue;
} case 'deinit': {
room = PS.rooms[roomid2];
if (room) {
if (room && room.connected !== 'expired') {
room.connected = false;
this.removeRoom(room);
}
@ -2589,8 +2589,15 @@ export const PS = new class extends PSModel {
if (this.popups.length && room.id === this.popups[this.popups.length - 1]) {
this.popups.pop();
PS.room = this.popups.length ? PS.rooms[this.popups[this.popups.length - 1]]! :
PS.rooms[room.parentRoomid ?? PS.panel.id] || PS.panel;
if (this.popups.length) {
// focus topmost popup
PS.room = PS.rooms[this.popups[this.popups.length - 1]]!;
} else {
// if popup parent is a mini-window, focus popup parent
PS.room = PS.rooms[room.parentRoomid ?? PS.panel.id] || PS.panel;
// otherwise focus current panel
if (PS.room.location !== 'mini-window' || PS.panel !== PS.mainmenu) PS.room = PS.panel;
}
}
if (wasFocused) {

View File

@ -260,7 +260,9 @@ export class ChatRoom extends PSRoom {
message = args[2];
}
if (toID(name) === PS.user.userid) return false;
if (message.startsWith(`/raw `)) return false;
if (message.startsWith(`/raw `) || message.startsWith(`/uhtml`) || message.startsWith(`/uhtmlchange`)) {
return false;
}
const lastMessageDates = Dex.prefs('logtimes') || (PS.prefs.set('logtimes', {}), Dex.prefs('logtimes'));
if (!lastMessageDates[PS.server.id]) lastMessageDates[PS.server.id] = {};

View File

@ -129,7 +129,8 @@ export class PSTeambuilder {
if (line.startsWith('Move:')) line = line.slice(4);
line = line.slice(line.charAt(1) === ' ' ? 2 : 1);
if (line.startsWith('Hidden Power [')) {
const hpType = line.slice(14, -1) as Dex.TypeName;
let hpType = line.slice(14, line.indexOf(']')) as Dex.TypeName;
if (hpType.includes(']') || hpType.includes('[')) hpType = '' as any;
line = 'Hidden Power ' + hpType;
set.hpType = hpType;
}