Port capture and the Route 29 catching tutorial
Checks / web (push) Canceled after 0s
Checks / web (pull_request) Canceled after 0s

Battle PACK opens the Balls pocket and runs PokeBallEffect: the Poké,
Great, Ultra and Master Ball multipliers, the original HP arithmetic
(including the overflow above 341 maximum HP), the sleep/freeze bonus
(BRN/PSN/PAR add nothing), HELD_CATCH_CHANCE and the catch draw.
GetPokeBallWobble draws per shake from WobbleProbabilities and picks the
break-free text. Trainer battles block the ball but still use it and the
turn.

A catch reloads the Pokémon as LoadEnemyMon does (the wild item roll is
redrawn, then the item restored), keeps its HP, status, item and DVs,
restores the moves and PP it appeared with, adds it to the party with
SetCaughtData, registers it and offers a nickname with InitName's
default. A catch with six Pokémon needs the PC and is refused.

catchtutorial runs BATTLETYPE_TUTORIAL as "DUDE": no send-out, an
automatic catch that keeps nothing and prompts that continue on their
own. Both Route 29 triggers, declining and the Dude's repeat offer run
from the ROM. The text reader now handles TX_LOW.

PLAN.md gains a status overview and done/remaining checklists; the
README, help dialog, routine map and handoff describe the milestone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sébastien QUEROLandClaude Opus 5.5 committed 2026-09-24 20:57:36 +02:00
1 parent dc10343520
commit 9ac111f262
20 files changed
+1101 -65

No files matched your search

+77 -40
View File
@@ -127,39 +127,48 @@ function showChoice(choice: Choice | undefined) {
);
container.firstElementChild?.setAttribute("aria-label", "Previous day");
container.children[2]?.setAttribute("aria-label", "Next day");
} else if (choice.kind === "name") {
// The naming screen: an empty name keeps the current one.
const input = document.createElement("input");
input.maxLength = choice.max;
input.placeholder = choice.current;
input.setAttribute("aria-label", `Name (empty keeps ${choice.current})`);
input.autocomplete = "off";
input.spellcheck = false;
const submit = () => {
const name = input.value.trim();
if (name && !NICKNAME_PATTERN.test(name)) {
input.setCustomValidity(
"Use letters, digits, spaces and simple punctuation.",
);
input.reportValidity();
return;
}
runtime.choose(name);
canvas.focus({ preventScroll: true });
};
input.addEventListener("input", () => input.setCustomValidity(""));
input.addEventListener("keydown", (event) => {
if (event.key === "Enter") submit();
});
const ok = document.createElement("button");
ok.type = "button";
ok.textContent = "OK";
ok.addEventListener("click", () => {
if (session.state === "playing") submit();
});
container.replaceChildren(input, ok);
queueMicrotask(() => input.focus({ preventScroll: true }));
}
} else if (choice.kind === "name")
container.replaceChildren(
...nameField(choice.current, choice.max, (name) => runtime.choose(name)),
);
}
/** The naming screen as a text field and OK: an empty name keeps the
* current one. */
function nameField(
current: string,
max: number,
answer: (name: string) => void,
): HTMLElement[] {
const input = document.createElement("input");
input.maxLength = max;
input.placeholder = current;
input.setAttribute("aria-label", `Name (empty keeps ${current})`);
input.autocomplete = "off";
input.spellcheck = false;
const submit = () => {
const name = input.value.trim();
if (name && !NICKNAME_PATTERN.test(name)) {
input.setCustomValidity(
"Use letters, digits, spaces and simple punctuation.",
);
input.reportValidity();
return;
}
answer(name);
canvas.focus({ preventScroll: true });
};
input.addEventListener("input", () => input.setCustomValidity(""));
input.addEventListener("keydown", (event) => {
if (event.key === "Enter") submit();
});
const ok = document.createElement("button");
ok.type = "button";
ok.textContent = "OK";
ok.addEventListener("click", () => {
if (session.state === "playing") submit();
});
queueMicrotask(() => input.focus({ preventScroll: true }));
return [input, ok];
}
type MartChoice = Extract<
Choice,
@@ -288,6 +297,8 @@ function drawPic(target: HTMLCanvasElement, tiles: Uint8Array, size: number, pal
const battlePics = { foe: "", player: "" };
let battleMenuKey = "";
let showMoves = false;
/** BattlePack's Balls pocket, the only pocket usable in battle so far. */
let showPack = false;
let battleCursor = 0;
let battleSelectionKey = "";
@@ -303,8 +314,8 @@ function highlightBattleChoice() {
function handleBattleInput(button: Button): boolean {
const world = runtime.world;
if (!world?.battle) return false;
if (button === "b" && showMoves) {
showMoves = false;
if (button === "b" && (showMoves || showPack)) {
showMoves = showPack = false;
return true;
}
const buttons = battleButtons();
@@ -330,7 +341,7 @@ function showBattle(world: GameWorld) {
screen.hidden = !view;
if (!view) {
battlePics.foe = battlePics.player = battleMenuKey = "";
showMoves = false;
showMoves = showPack = false;
battleCursor = 0;
battleSelectionKey = "";
return;
@@ -365,15 +376,18 @@ function showBattle(world: GameWorld) {
get("battle-player-hp-text").textContent = `${own.hp}/ ${own.maxHp}`;
setHp(get("battle-player-hp"), own.hp, own.maxHp);
}
get("battle-text").textContent = view.message?.text ?? "";
const prompt = view.prompt;
const selectionKey = `${prompt?.kind ?? "text"}:${showMoves}`;
get("battle-text").textContent =
prompt?.kind === "name" ? prompt.title : (view.message?.text ?? "");
if (prompt?.kind !== "action") showMoves = showPack = false;
const selectionKey = `${prompt?.kind ?? "text"}:${showMoves}:${showPack}`;
if (selectionKey !== battleSelectionKey) {
battleCursor = 0;
battleSelectionKey = selectionKey;
}
if (prompt?.kind === "yesno") battleCursor = view.selected === 1 ? 0 : 1;
const key = JSON.stringify([prompt, view.selected, showMoves, own?.pp, view.message?.prompt]);
const balls = world.liveState.bag.balls;
const key = JSON.stringify([prompt, view.selected, showMoves, showPack, own?.pp, balls, view.message?.prompt]);
if (key === battleMenuKey) return;
battleMenuKey = key;
const menu = get("battle-menu");
@@ -415,6 +429,21 @@ function showBattle(world: GameWorld) {
showMoves = false;
showWorld(world);
}, { wide: true }));
} else if (showPack) {
balls.forEach(({ item, quantity }, slot) =>
buttons.push(
button(data.itemName(item), () => {
showPack = false;
runtime.battleAction({ action: "item", item, slot });
}, { detail: `×${quantity}` }),
),
);
if (!balls.length)
buttons.push(button("No BALLS", () => {}, { disabled: "The BALL pocket is empty." }));
buttons.push(button("BACK", () => {
showPack = false;
showWorld(world);
}, { wide: true }));
} else {
buttons.push(
button("FIGHT", () => {
@@ -422,7 +451,10 @@ function showBattle(world: GameWorld) {
showWorld(world);
}),
button("PKMN", () => {}, { disabled: "Switching Pokémon is not ported yet." }),
button("PACK", () => {}, { disabled: "Using items in battle is not ported yet." }),
button("PACK", () => {
showPack = true;
showWorld(world);
}),
button("RUN", () => runtime.battleAction({ action: "run" })),
);
}
@@ -436,6 +468,11 @@ function showBattle(world: GameWorld) {
buttons.push(button(data.moveName(move), () => runtime.battleChoose(index))),
);
buttons.push(button("CANCEL", () => runtime.battleChoose(4), { wide: true }));
} else if (prompt?.kind === "name") {
menu.replaceChildren(
...nameField(prompt.current, prompt.max, (name) => runtime.battleName(name)),
);
return;
} else if (prompt?.kind === "stats") {
prompt.labels.forEach((label, index) =>
buttons.push(button(`${label} ${prompt.values[index]}`, () => {}, { disabled: " " })),