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

Most of these were found by andrebastosdias (thanks!)

Teambuilder
- SpA/SpD columns weren't appearing in gen 2
- buggy behavior with EVs in gen 1-2 or Let's Go
- save teams after doing things (Fixes #2493)
- import old box syntax

UI
- layout breaking when resizing
This commit is contained in:
Guangcong Luo 2025-11-02 15:16:50 +00:00
parent 96c625ae97
commit 64e79f49eb
5 changed files with 41 additions and 21 deletions

View File

@ -128,8 +128,8 @@ export class PSSearchResults extends preact.Component<{
<span class="col statcol"><em>HP</em><br />{stats.hp}</span>
<span class="col statcol"><em>Atk</em><br />{stats.atk}</span>
<span class="col statcol"><em>Def</em><br />{stats.def}</span>
{search.dex.gen > 2 && <span class="col statcol"><em>SpA</em><br />{stats.spa}</span>}
{search.dex.gen > 2 && <span class="col statcol"><em>SpD</em><br />{stats.spd}</span>}
{search.dex.gen >= 2 && <span class="col statcol"><em>SpA</em><br />{stats.spa}</span>}
{search.dex.gen >= 2 && <span class="col statcol"><em>SpD</em><br />{stats.spd}</span>}
{search.dex.gen < 2 && <span class="col statcol"><em>Spc</em><br />{stats.spa}</span>}
<span class="col statcol"><em>Spe</em><br />{stats.spe}</span>
<span class="col bstcol"><em>BST<br />{bst}</em></span>

View File

@ -314,6 +314,7 @@ export class TeamEditorState extends PSModel {
const sets = Teams.unpack(team.packedTeam);
sets.splice(source, 1);
team.packedTeam = Teams.pack(sets);
team.iconCache = null;
}
}
}
@ -335,6 +336,7 @@ export class TeamEditorState extends PSModel {
index++;
}
TeamEditorState.clipboard = null;
this.save();
}
static pasteTeam(index: number, isMove?: boolean, folder = '') {
if (!TeamEditorState.clipboard) return;
@ -656,9 +658,7 @@ export class TeamEditorState extends PSModel {
}
}
getStat(stat: StatName, set: Dex.PokemonSet, ivOverride: number, evOverride?: number, natureOverride?: number) {
const team = this.team;
const supportsEVs = !team.format.includes('letsgo');
const supportsEVs = !this.isLetsGo;
const supportsAVs = !supportsEVs;
// do this after setting set.evs because it's assumed to exist
@ -1195,6 +1195,7 @@ class TeamTextbox extends preact.Component<{
this.replace(paste.paste.replace(/\r\n/g, '\n'), valueIndex, valueIndex + value.length);
} else {
this.editor.import(pasteTxt);
this.props.onChange?.();
}
const notes = paste["notes"] as string;
if (notes.startsWith("Format: ")) {
@ -2457,14 +2458,13 @@ class StatForm extends preact.Component<{
onChange: () => void,
}> {
static renderStatGraph(set: Dex.PokemonSet, editor: TeamEditorState, evs?: boolean) {
// const supportsEVs = !team.format.includes('letsgo');
const defaultEV = (editor.gen > 2 ? 0 : 252);
const ivs = editor.getIVs(set);
return Dex.statNames.map(statID => {
if (statID === 'spd' && editor.gen === 1) return null;
const stat = editor.getStat(statID, set, ivs[statID]);
let ev: number | string = set.evs?.[statID] ?? defaultEV;
let ev: number | string = set.evs ? (set.evs[statID] || 0) : defaultEV;
let width = stat * 75 / 504;
if (statID === 'hp') width = stat * 75 / 704;
if (width > 75) width = 75;
@ -2746,7 +2746,11 @@ class StatForm extends preact.Component<{
if (isNaN(value)) {
if (set.evs) delete set.evs[statID];
} else {
set.evs ||= {};
if (this.maxEVs() < 6 * 252 || this.props.editor.isLetsGo) {
set.evs ||= {};
} else {
set.evs ||= { hp: 252, atk: 252, def: 252, spa: 252, spd: 252, spe: 252 };
}
set.evs[statID] = value;
}
@ -2844,20 +2848,19 @@ class StatForm extends preact.Component<{
this.props.onChange();
};
maxEVs() {
const team = this.props.editor.team;
const useEVs = !team.format.includes('letsgo');
const editor = this.props.editor;
const useEVs = !editor.isLetsGo && editor.gen >= 3;
return useEVs ? 510 : Infinity;
}
override render() {
const { editor, set } = this.props;
const team = editor.team;
const species = editor.dex.species.get(set.species);
const baseStats = species.baseStats;
const nature = BattleNatures[set.nature || 'Serious'];
const useEVs = !team.format.includes('letsgo');
const useEVs = !editor.isLetsGo;
// const useAVs = !useEVs && team.format.endsWith('norestrictions');
const maxEV = useEVs ? 252 : 200;
const stepEV = useEVs ? 4 : 1;
@ -2881,14 +2884,14 @@ class StatForm extends preact.Component<{
] as const);
let remaining = null;
const maxEv = this.maxEVs();
if (maxEv < 6 * 252) {
const maxEVs = this.maxEVs();
if (maxEVs < 6 * 252) {
let totalEv = 0;
for (const ev of Object.values(set.evs || {})) totalEv += ev;
if (totalEv <= maxEv) {
remaining = (totalEv > (maxEv - 2) ? 0 : (maxEv - 2) - totalEv);
if (totalEv <= maxEVs) {
remaining = (totalEv > (maxEVs - 2) ? 0 : (maxEVs - 2) - totalEv);
} else {
remaining = maxEv - totalEv;
remaining = maxEVs - totalEv;
}
remaining ||= null;
}

View File

@ -73,11 +73,15 @@ class TeambuilderRoom extends PSRoom {
} else {
PS.teams.unshift(this.createTeam(null, isBox));
}
PS.teams.save();
this.update(null);
},
'deleteteam'(target) {
const team = PS.teams.byKey[target];
if (team) PS.teams.delete(team);
if (!team) return this.errorReply(`Team not found: ${target}`);
PS.teams.delete(team);
PS.teams.save();
this.update(null);
},
'copyteam'(target) {
@ -96,12 +100,14 @@ class TeambuilderRoom extends PSRoom {
const index = team ? PS.teams.list.indexOf(team) : PS.teams.list.length;
const folder = this.curFolder?.endsWith('/') ? this.curFolder.slice(0, -1) : '';
TeamEditorState.pasteTeam(index, cmd === 'moveteamabove', folder);
PS.teams.save();
PS.update();
this.update(null);
},
'undeleteteam'() {
PS.teams.undelete();
PS.teams.save();
this.update(null);
},
'backup'() {
@ -421,6 +427,9 @@ class TeambuilderPanel extends PSRoomPanel<TeambuilderRoom> {
this.forceUpdate();
};
static handleDrop(ev: DragEvent) {
if (PS.dragging?.type === 'team' && typeof PS.dragging?.team === 'object') {
PS.teams.save();
}
return !!this.addDraggedTeam(ev, (PS.rooms['teambuilder'] as TeambuilderRoom)?.curFolder);
}
updateSearch = (ev: KeyboardEvent) => {
@ -499,7 +508,7 @@ class TeambuilderPanel extends PSRoomPanel<TeambuilderRoom> {
const room = this.props.room;
room.exportMode = false;
PS.teams.update('team');
PS.teams.save();
room.update(null);
};
renameFolder = (ev: MouseEvent) => {

View File

@ -62,9 +62,16 @@ export class PSTeambuilder {
line = line.slice(3, -3).trim();
[curTeam.format, line] = this.splitPrefix(line, ']', 1) as [ID, string];
if (!curTeam.format) curTeam.format = 'gen8' as ID;
else if (!curTeam.format.startsWith('gen')) curTeam.format = `gen6${curTeam.format}` as ID;
if (!curTeam.format) {
curTeam.format = 'gen8' as ID;
} else if (curTeam.format.endsWith('-box')) {
curTeam.format = curTeam.format.slice(0, -4) as ID;
curTeam.isBox = true;
}
if (curTeam.format.startsWith('[')) curTeam.format = curTeam.format.slice(1) as ID;
if (!curTeam.format.startsWith('gen')) curTeam.format = `gen6${curTeam.format}` as ID;
line = line.trim();
[curTeam.folder, curTeam.name] = this.splitPrefix(line, '/');
} else if (line.includes('|')) {
if (curTeam) {

View File

@ -175,6 +175,7 @@ export class PSHeader extends preact.Component {
}
if (PSView.narrowMode) {
document.documentElement.classList?.remove('scroll-snap-enabled');
document.documentElement.style.width = 'auto';
PSView.narrowMode = false;
}