# Pokemon 3D Legacy Integration

`/pokemon.html` is now a browser-playable Pokemon 3D rebuild lane, not the WePayUncheeze voxel sandbox and not a hosted copy of the upstream Windows package.

## Upstream

- Repository: <https://github.com/P3D-Legacy/P3D-Legacy>
- Latest inspected release: `0.61`
- License: GPLv3
- Runtime: Visual Basic / VB.NET, .NET Framework, MonoGame 3.7.1, Windows graphics/audio/input dependencies

The upstream project is a desktop game. It cannot be dropped into a browser page as JavaScript. The web version here is a separate Three.js runtime that exports and consumes source-derived P3D-Legacy maps, scripts, encounter tables, species data, and move metadata.

## Local Setup

From the site root:

```bash
node scripts/pokemon3d-fetch-upstream.mjs --clone
```

This writes:

- `vendor/P3D-Legacy/`: shallow clone of the upstream source, ignored by git.
- `pokemon3d/upstream.latest.json`: generated metadata for the current upstream release and inspected source.

It does not mirror or host upstream release packages. The integration path is source inspection and redesign.

To regenerate the browser data consumed by `/pokemon.html`:

```bash
node scripts/pokemon3d-build-web-data.mjs
```

This writes:

- `pokemon3d/web-data/maps.json`: manifest for every exported upstream map.
- `pokemon3d/web-data/maps/*.json`: lazy-loaded per-map geometry, warps, NPCs, signs, script refs, grass zones, and source provenance.
- `pokemon3d/web-data/scripts.json`: extracted source script command inventory and dialogue text.
- `pokemon3d/web-data/encounters.json`: parsed `.poke` encounter tables with method, species, chance, daypart, and level range.
- `pokemon3d/web-data/species.json` and `pokemon3d/web-data/species/*.json`: lazy-loaded Pokemon species files parsed from `P3D/Content/Pokemon/Data`.
- `pokemon3d/web-data/moves.json`: move names, type, power, PP, and accuracy parsed from upstream VB attack classes.
- `pokemon3d/web-data/starters.json`: the current browser new-game starter set and initial fallback wild list.

## Site Contract

- The homepage points to `/pokemon.html` as the second game surface.
- `/pokemon.html` is playable in browser and lazy-loads source-derived maps, scripts, encounters, species, and move JSON.
- Map transitions use upstream `WarpBlock` targets; Route 29 grass uses the upstream `route29.poke` table; NPC/sign interactions read exported text/script data.
- The old single-sprite voxel battle mode remains in `js/pokemon/` as prior local work, but it is not presented as Pokemon 3D Legacy.

## Port Direction

The port now starts from upstream behavior:

1. Load maps, scripts, Pokemon data, battle rules, menus, saves, and progression from the P3D-Legacy source/content tree.
2. Isolate MonoGame-specific graphics, input, audio, file validation, and network calls.
3. Choose a browser runtime only after compile and content-pipeline constraints are proven against the real source.

Current browser coverage:

- Exports all 1,258 upstream map files into lazy-loaded web JSON.
- Exports 1,727 script files and shows extracted dialogue for NPCs and ScriptBlocks.
- Exports 281 `.poke` encounter tables and uses land encounters in grass zones.
- Exports 848 Pokemon species files and 581 moves.
- Supports local save/continue, starter selection, map rendering, warps, NPC/sign interaction, wild battle entry, and simple turn-based battle actions.

Current browser gaps:

- The VB ActionScript interpreter is not fully reimplemented yet; the browser reads dialogue and command inventory but does not execute every upstream side effect.
- Trainer battle AI, inventory, flags/registers, quests, menus, audio, and full story progression still need to be ported from the exported command stream into browser-native systems.
