Skip to content

Commit a748efc

Browse files
author
linyuan.yang
committed
优化资源
1 parent af48dcf commit a748efc

11 files changed

Lines changed: 53 additions & 133 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33
## Directory structure
44

55
- `packages/web/`: Vue/Vite Web package, deployable on its own.
6-
- `packages/player/`: shared NES player package with display, controls, settings, and runtime wiring.
6+
- `packages/player/`: shared NES player package with display, controls, settings, runtime wiring, and the libretro core assets.
77
- `packages/app/`: Tauri app shell for desktop, Android, and iOS. It owns its own Vue entry and can add native cache/log/file-system behavior without changing the Web package.
88
- `scripts/`: repository-level helper scripts.
99

1010
## Build
1111

1212
- `pnpm install`: install workspace dependencies.
13-
- `pnpm --filter @nes-emulator/web run sync:rom-catalog`: sync the ROM catalog into `packages/web/public/catalog.json`. By default it uses `E:\nes-roms\catalog.json` when present, otherwise it fetches the remote GitHub raw catalog.
1413
- `pnpm --filter @nes-emulator/web run build`: build the standalone Web app.
1514
- `pnpm --filter @nes-emulator/app run build:frontend`: build the App frontend into `packages/app/dist`.
1615
- `pnpm --filter @nes-emulator/app run build`: build the Tauri app shell, using `packages/app/dist`.
1716

1817
## ROM catalog
1918

20-
- Web reads `./catalog.json` from the same origin to avoid browser CORS failures on remote raw files.
21-
- ROM download URLs are used exactly as written in the synced catalog.
22-
- To switch ROM hosting, provide a catalog whose `download_url` values point at the new CORS-enabled source.
19+
- Web and App load the ROM catalog from the remote GitHub raw URL at runtime, so the large catalog is not bundled into the frontend output.
20+
- ROM download URLs are used exactly as written in the remote catalog.
21+
- To switch ROM hosting, update the catalog URL in `packages/player/src/store/romCatalog.ts`, and provide a catalog whose `download_url` values point at the new CORS-enabled source.

‎package-lock.json‎

Lines changed: 0 additions & 51 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

‎packages/player/src/components/RomStorePanel.vue‎

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,7 @@ async function play(game: RomEntry) {
250250
}
251251
}
252252
if (!bytes) {
253-
bytes = await downloadRom(game, {
254-
onProgress: (progress) => setProgress(key, progress),
255-
})
256-
await saveCachedRom(game, bytes)
253+
bytes = await downloadAndCache(game, key)
257254
}
258255
await touchCachedRom(key)
259256
await refreshCached()
@@ -267,6 +264,31 @@ async function play(game: RomEntry) {
267264
}
268265
}
269266
267+
async function downloadOnly(game: RomEntry) {
268+
if (busyKey.value !== null) return
269+
const key = romKey(game)
270+
if (cachedKeys.value.has(key)) return
271+
busyKey.value = key
272+
error.value = null
273+
try {
274+
await downloadAndCache(game, key)
275+
await refreshCached()
276+
} catch (err) {
277+
error.value = formatError(err)
278+
} finally {
279+
clearProgress(key)
280+
busyKey.value = null
281+
}
282+
}
283+
284+
async function downloadAndCache(game: RomEntry, key = romKey(game)): Promise<Uint8Array> {
285+
const bytes = await downloadRom(game, {
286+
onProgress: (progress) => setProgress(key, progress),
287+
})
288+
await saveCachedRom(game, bytes)
289+
return bytes
290+
}
291+
270292
async function playCached(rom: CachedRom) {
271293
if (busyKey.value !== null) return
272294
busyKey.value = rom.key
@@ -325,6 +347,12 @@ function playLabel(game: RomEntry): string {
325347
return cachedKeys.value.has(key) ? '启动' : '下载并启动'
326348
}
327349
350+
function downloadLabel(game: RomEntry): string {
351+
const key = romKey(game)
352+
if (busyKey.value === key) return '下载中'
353+
return '下载'
354+
}
355+
328356
function metaLine(game: RomEntry): string {
329357
const parts = [
330358
game.genre,
@@ -472,6 +500,14 @@ function formatError(err: unknown): string {
472500
<span v-if="busyKey === romKey(game) && progressLabel(game)" class="progress">
473501
{{ progressLabel(game) }}
474502
</span>
503+
<button
504+
v-if="!cachedKeys.has(romKey(game))"
505+
class="btn"
506+
:disabled="busyKey !== null"
507+
@click="downloadOnly(game)"
508+
>
509+
{{ downloadLabel(game) }}
510+
</button>
475511
<button class="btn primary" :disabled="busyKey !== null" @click="play(game)">
476512
{{ playLabel(game) }}
477513
</button>
@@ -805,7 +841,7 @@ function formatError(err: unknown): string {
805841
再隐藏次要元信息(标签 / 最后使用),让列表区至少 5-6 行可见。 */
806842
@media (orientation: landscape) and (max-height: 540px) {
807843
.store-backdrop {
808-
padding: 0;
844+
padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
809845
}
810846
.store-panel {
811847
max-height: 100%;

‎packages/player/src/emulator/runner.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
*
44
* 与旧的 jsnes 实现不同,渲染、音频、帧循环全部由 Nostalgist/RetroArch 内部接管,
55
* 本类只负责:载入 ROM、把逻辑按钮映射成 RetroArch 输入、存读档、暂停/继续、
6-
* 以及速度/音量的(降级)控制。核心文件(fceumm_libretro.js/.wasm)本地打包在
7-
* 各宿主的 public/cores/ 下,通过相对路径加载,保证离线(Tauri)与 PWA 可用。
6+
* 以及速度/音量的(降级)控制。核心文件(fceumm_libretro.js/.wasm)跟随
7+
* player 源码作为 Vite asset 打包,保证离线(Tauri)与 PWA 可用。
88
*/
99
import { Nostalgist } from 'nostalgist'
10+
import fceummCoreJsUrl from '../assets/cores/fceumm_libretro.js?url'
11+
import fceummCoreWasmUrl from '../assets/cores/fceumm_libretro.wasm?url'
1012

1113
/** 存档快照:RetroArch 的二进制 savestate(可直接存入 IndexedDB)。 */
1214
export type SaveState = Uint8Array
@@ -115,9 +117,8 @@ export class NesRunner {
115117
element: this.canvas,
116118
core: 'fceumm',
117119
rom: { fileName: 'game.nes', fileContent: new Blob([bytes as BlobPart]) },
118-
// 核心文件本地打包在 public/cores/;相对路径在 GitHub Pages 子路径与 Tauri 离线下都可解析。
119-
resolveCoreJs: (core) => `./cores/${core}_libretro.js`,
120-
resolveCoreWasm: (core) => `./cores/${core}_libretro.wasm`,
120+
resolveCoreJs: () => fceummCoreJsUrl,
121+
resolveCoreWasm: () => fceummCoreWasmUrl,
121122
// 不让 RetroArch 监听真实全局键盘,输入完全由前端自定义系统经 press/release 派发,
122123
// 避免真实按键被 RetroArch 二次捕获导致重复输入。
123124
respondToGlobalEvents: false,

‎packages/player/src/env.d.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference types="vite/client" />
2+
13
declare module '*.vue' {
24
import type { DefineComponent } from 'vue'
35
const component: DefineComponent<Record<string, unknown>, Record<string, unknown>, unknown>

‎packages/web/public/.gitkeep‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎packages/web/public/cores/fceumm_libretro.js‎

Lines changed: 0 additions & 18 deletions
This file was deleted.
-2.92 MB
Binary file not shown.

0 commit comments

Comments
 (0)