diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eda1af39..fbb680239 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to WittyMediaServer. Versions follow [semantic versioning](h ## Unreleased +- **Choosing a core is one picker.** On a game's page, **Change core** beside the core that plays it; in **Settings → Consoles & cores**, **Change core** on each console. Each core says what it's good at (accuracy, speed or a balance of the two), where it runs and how it draws on your server, whether it needs a BIOS file of your own and whether it's installed. Choosing one that isn't installed installs it, with its progress, then uses it. It works on a phone, with a mouse, and with a TV remote or controller, and closes with ×, Escape, B or Back, or a tap outside. A game's own core is set the same way, or left to its console's. During a game, the player can open the same picker (`chooseCore`), which offers to restart on the new core: in-game saves stay, and save states stay with the core that made them. +- **Nine more cores to choose from**, each offered only where a build is published: QuickNES for NES; today's bsnes for Super Nintendo; Gearboy for Game Boy; VBA-M and gpSP for Game Boy Advance; Beetle PCE and Beetle SuperGrafx for PC Engine; Beetle Lynx for Lynx (which needs your own `lynxboot.img`); and RACE for Neo Geo Pocket. They come with the next WittyPlay. bsnes played 16 retail Super Nintendo games here, special chips included, with no firmware files. +- **For apps:** `GET /gaming/consoles/{console}/core` and `GET /gaming/games/{id}/core` give the picker's `choices`, and `GET /gaming/cores/{id}/install` how far an install has got. `GET /games/consoles` gives each core's `coreAbout`. See [Choosing a core](docs/GAMING-API.md#choosing-a-core). + - **WittyTV keeps playing in the background.** Switching to another tab or minimising the window no longer stops a channel: the guide's preview carries on with its sound, and a player that goes quiet in the background tells the server it's still there, so the channel isn't stopped behind it. **Keep playing when this tab is in the background**, in WittyTV's look and in the player's settings, turns it off for one device; then a channel stops when you switch away, freeing a tuner, and starts again when you come back. Administrators choose what new devices start with under **Options**. Apps get the same default as `backgroundPlay` in the guide and tune answers. - **On a Mac whose WittyPlay can use the graphics card, PlayStation 2 plays on Play!, on the card.** LRPS2 comes first for PlayStation 2, but can't use a Mac's card, so it would still have drawn on the processor, which can't keep a Gran Turismo 4 race at full speed. A game Play! can't open still goes on to LRPS2, and someone who chose LRPS2 keeps it. - **Comics whose pages are PNGs called .jpg get their cover.** Several public-domain comics name their PNG pages `000.jpg`, and the server's picture tool chose how to read a picture by its name, so their covers failed during scans ("bits 193 is invalid", "unsupported coding type") and the comics had none. It now reads what a picture really is from its first bytes, for every book and comic cover. diff --git a/docs/CLIENT-API.md b/docs/CLIENT-API.md index c3362feae..fc0379783 100644 --- a/docs/CLIENT-API.md +++ b/docs/CLIENT-API.md @@ -1791,6 +1791,7 @@ See [LIBRARY-TRANSCODING.md](LIBRARY-TRANSCODING.md). | `GET /play/{sid}/screenshot` | user | The current picture as a PNG. | | `GET /gaming` | admin | Gaming. | | `POST /gaming/cores/{id}/install` | admin | Core install. | +| `GET /gaming/cores/{id}/install` | admin | How far an install under way has got: `{installing, received, total}` in bytes, `total` 0 when the download server gave no size. An older WittyPlay always answers `installing: false`. | | `DELETE /gaming/cores/{id}` | admin | Core remove. | | `DELETE /gaming/unpacked` | admin | Empty the unpacked games cache. | | `GET /gaming/custom` | admin | Custom cores and consoles: whether they're on, what's here, the cores folder and the audit log. | @@ -1808,8 +1809,9 @@ See [LIBRARY-TRANSCODING.md](LIBRARY-TRANSCODING.md). | `POST /gaming/custom/consoles` | admin | Add a custom console. | | `PUT /gaming/custom/consoles/{id}` | admin | Change a custom console. | | `DELETE /gaming/custom/consoles/{id}` | admin | Remove a custom console. | +| `GET /gaming/consoles/{console}/core` | admin | A console's cores for the core picker, installed or not, and its default: see [Choosing a core](GAMING-API.md#choosing-a-core). | | `PUT /gaming/consoles/{console}/core` | admin | Choose a console's core. | -| `GET /gaming/games/{id}/core` | admin | What plays a game, and how each core has gone on it. | +| `GET /gaming/games/{id}/core` | admin | What plays a game, and how each core has gone on it: the picker's `choices`, and `options`, the installed ones, for older clients. | | `PUT /gaming/games/{id}/core` | admin | Choose a core for one game. | | `GET /reach/{nonce}` | none | Reach. | | `DELETE /users/{id}/2fa` | admin | User two factor reset. | diff --git a/docs/GAMES.md b/docs/GAMES.md index 7caff79e1..057331024 100644 --- a/docs/GAMES.md +++ b/docs/GAMES.md @@ -126,7 +126,9 @@ The core downloads from buildbot.libretro.com, the libretro project's build serv Cores on this list that are already in a RetroArch folder on the same machine are found and used. -If a game won't load on the chosen core, the other installed cores for that console are tried. To change a console's core, use the choice on its card. Administrators can pick a core for one game on that game's page, which also shows how each core has gone on it. +If a game won't load on the chosen core, the other installed cores for that console are tried. + +**Choosing another core.** Press **Change core** on a console's card, or beside the core on a game's page to change it for that game alone. Each core says what it's good at (accuracy, speed or a balance of the two), how it draws on your server and where else it runs, whether it needs a BIOS file of your own, and whether it's installed. Choose one that isn't, read its license, and press **Install and use**: it downloads, with its progress, and plays from the next start. On a game's page the picker also shows how each core has gone on that game. Your in-game saves stay whichever core plays a game, but a save state only loads in the core that made it, so states from another core wait until you switch back. | Console | First choice | Needs a graphics card | BIOS file | |---|---|---|---| @@ -151,7 +153,27 @@ If a game won't load on the chosen core, the other installed cores for that cons | Dreamcast | Flycast | Yes | Optional | | Nintendo 3DS | Azahar | Yes | No | -Each card lists the other cores offered, with their licenses. Non-commercial cores are never offered. +Each card lists the other cores offered, with their licenses: + +| Console | Other cores | +|---|---| +| NES, Famicom | Nestopia UE, Mesen, QuickNES | +| Super Nintendo | bsnes 2014 Performance, Mesen-S, bsnes | +| Game Boy, Color | SameBoy, mGBA, Gearboy | +| Game Boy Advance | VBA Next, VBA-M, gpSP | +| Mega Drive, Genesis | ClownMDEmu | +| Master System, Game Gear | SMS Plus GX | +| PlayStation | Beetle PSX, SwanStation, Beetle PSX HW (the last three need a BIOS file) | +| PC Engine | Beetle PCE, Beetle SuperGrafx | +| Atari 2600 | Stella | +| Lynx | Beetle Lynx (needs `lynxboot.img`) | +| Neo Geo Pocket | RACE | +| Nintendo DS | DeSmuME | +| Nintendo 64 | ParaLLEl N64 | +| PlayStation 2 | Play! | +| Nintendo 3DS | Panda3DS | + +Non-commercial cores, such as Snes9x, Genesis Plus GX and PicoDrive, are never offered. Each core also says which server platforms it runs on, and how it draws on yours: on a graphics card, by the processor, or not at all. A core that isn't published for your server's platform isn't offered to install: Beetle Supafaust, for example, has no build for macOS, so a Mac server suggests bsnes 2014 Performance for Super Nintendo instead. Every device plays whatever your server can run, since the server runs the game and streams it. @@ -185,13 +207,13 @@ You can also put files straight in the BIOS folder named on that page. A PlaySta | Console | File names | Used for | |---|---|---| | PlayStation 2 | `scph39001.bin`, or any other model's BIOS image | LRPS2 needs one, and any region will do. With a whole set, a game starts on one from its own region, or a late first-generation US model | -| PlayStation | `scph5501.bin`, `scph5500.bin`, `scph5502.bin` | US, Japanese and European consoles. PCSX ReARMed runs most games without one | +| PlayStation | `scph5501.bin`, `scph5500.bin`, `scph5502.bin` | US, Japanese and European consoles. PCSX ReARMed runs most games without one; Beetle PSX and SwanStation need one | | NES | `disksys.rom` | Famicom Disk System games | | Super Nintendo | `BS-X.bin` | Satellaview games in `.bs` files, on Mesen-S | | Game Boy Advance | `gba_bios.bin` | Better accuracy | | PC Engine | `syscard3.pce` | CD games | | Atari 7800 | `7800 BIOS (U).rom` | The start-up screen | -| Lynx | `lynxboot.img` | Most games | +| Lynx | `lynxboot.img` | Most games on Handy; Beetle Lynx needs it | | Nintendo DS | `bios7.bin`, `bios9.bin`, `firmware.bin` | Accuracy, and the start-up menu, on melonDS | | Dreamcast | `dc/dc_boot.bin`, `dc/dc_flash.bin` | Better compatibility, and the console's settings | diff --git a/docs/GAMING-API.md b/docs/GAMING-API.md index 625e5acf6..7fe58bbc7 100644 --- a/docs/GAMING-API.md +++ b/docs/GAMING-API.md @@ -138,6 +138,44 @@ with no build for this server answers 409 `{error, noBuild: true, platform, alte `macos/arm64` and `alternative` is `{id, name, console}`: a core that plays the same console here. If the download server answers 404 anyway, the answer is 502 with the same fields. +### Choosing a core + +What a core picker needs, for an administrator: a console's default (`GET /gaming/consoles/{console}/core`) or one +game's own core (`GET /gaming/games/{id}/core`). Both answer: + +| Field | Meaning | +|---|---| +| `console` | The console's id | +| `choice` | The core chosen at this level (the game's own, or the console's default), or `""` for none | +| `consoleDefault` | For a game: its console's default, or none | +| `effective` | The core that plays now, once a missing BIOS or graphics card is taken into account; `""` when none would | +| `canDownload` | This server's platform has prebuilt cores to install | +| `choices` | Every core that can play the console, in the server's order of preference, then the administrator's own | + +Each choice is `{id, name, license, installed, source, canInstall, recommended, strength, about, support, bios}`: + +| Field | Meaning | +|---|---| +| `installed`, `source` | It's on this server, and from where: `installed`, `retroarch`, `system` or `custom` | +| `canInstall` | It isn't installed, and installing it here would work: published for this platform, able to draw here, and this platform has downloads | +| `recommended` | The one this server would pick: the first published for this platform that can draw here | +| `strength` | What it's chosen for beside the console's other cores: `accuracy`, `speed` or `balanced`. None for a console's only core, or a custom one | +| `about` | One line on what it's good at, such as "The most accurate, and plays every game. Uses more of the processor." | +| `support` | `{here, platforms}`, as `coreSupport` above | +| `bios` | When it won't start without a BIOS file of the owner's own: `{files, found}`, any one of `files` | +| `starts`, `failures`, `seconds`, `lastError`, `best` | For a game: how it has gone on that game | + +`GET /games/consoles` gives the same `strength` and `about` for each core as `coreAbout`, for anyone. + +To choose a core that isn't installed: `POST /gaming/cores/{id}/install`, then the `PUT` beside the `GET` with +`{core}`, which only takes an installed core. While the install runs, `GET /gaming/cores/{id}/install` answers +`{installing, received, total}` in bytes (`total` 0 when the download server gave no size; a core with support files, +such as PPSSPP, counts again from 0 for those). The website asks about four times a second. An older WittyPlay module +always answers `installing: false`; show the install as under way without a size. + +A save state is made by one core and only loads in that core; in-game saves (battery saves and memory cards) stay with +the game. `GET /games/{id}/saves` says which core made each state (`core`, its name). + **A game in an archive** has to be unpacked before it starts, which can take minutes for a large disc on a small server. `POST /games/{id}/play` takes that long, which is fine as long as your HTTP client's timeout allows it. To show progress, call `POST /games/{id}/prepare` about once a second until `state` is `ready`, and then call play: diff --git a/docs/SECURITY-ROUTES.md b/docs/SECURITY-ROUTES.md index f8342e731..1cda45b3d 100644 --- a/docs/SECURITY-ROUTES.md +++ b/docs/SECURITY-ROUTES.md @@ -497,6 +497,7 @@ Every `/api/...` route is also served as `/api/v1/...`. `HEAD` is served whereve | `PUT /api/game-background/image` | Signed-in | own. PNG, JPEG or WebP of at most 10 MB and 24 megapixels, drawn again as a new JPEG | | `GET /api/gaming` | Admin | Nothing further | | `POST /api/gaming/cores/{id}/install` | Admin | Core id format. Offered by this server | +| `GET /api/gaming/cores/{id}/install` | Admin | Core id format. Reads only how far its download has got | | `DELETE /api/gaming/cores/{id}` | Admin | Core id format. Installed by this server | | `DELETE /api/gaming/unpacked` | Admin | Nothing further | | `GET /api/games/settings/schema` | Signed-in | Nothing: fixed description | @@ -533,6 +534,7 @@ Every `/api/...` route is also served as `/api/v1/...`. `HEAD` is served whereve | `POST /api/gaming/custom/consoles` | Admin | Custom cores on. Console JSON size and fields | | `PUT /api/gaming/custom/consoles/{id}` | Admin | Custom cores on. Console JSON size and fields | | `DELETE /api/gaming/custom/consoles/{id}` | Admin | No library is set to it | +| `GET /api/gaming/consoles/{console}/core` | Admin | Known console | | `PUT /api/gaming/consoles/{console}/core` | Admin | Known console. Core allowed for it | | `GET /api/gaming/games/{id}/core` | Admin | A game | | `PUT /api/gaming/games/{id}/core` | Admin | A game. Core allowed for it | diff --git a/docs/openapi.json b/docs/openapi.json index c91d3c73d..7e5789b21 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -17546,6 +17546,44 @@ } }, "/gaming/consoles/{console}/core": { + "get": { + "operationId": "getGamingConsolesConsoleCore", + "parameters": [ + { + "in": "path", + "name": "console", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "choice, effective, canDownload and choices: see GAMING-API.md, Choosing a core." + }, + "default": { + "$ref": "#/components/responses/Error" + } + }, + "security": [ + { + "bearer": [] + } + ], + "summary": "A console's cores for the core picker, installed or not, and its default.", + "tags": [ + "Games" + ], + "x-wms-auth": "admin" + }, "put": { "operationId": "putGamingConsolesConsoleCore", "parameters": [ @@ -17639,6 +17677,44 @@ } }, "/gaming/cores/{id}/install": { + "get": { + "operationId": "getGamingCoresIdInstall", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "installing, received and total, in bytes." + }, + "default": { + "$ref": "#/components/responses/Error" + } + }, + "security": [ + { + "bearer": [] + } + ], + "summary": "How far an install under way has got.", + "tags": [ + "Server" + ], + "x-wms-auth": "admin" + }, "post": { "operationId": "postGamingCoresIdInstall", "parameters": [ diff --git a/internal/play/cores/gen.go b/internal/play/cores/gen.go index abdb980e0..836f0bc17 100644 --- a/internal/play/cores/gen.go +++ b/internal/play/cores/gen.go @@ -352,6 +352,18 @@ func (m *Manager) Install(ctx context.Context, id string) (*Core, error) { return r0, err } +// InstallProgress says how far an Install under way has got with the file it's fetching now: +// the bytes received, and the size the download server gave, 0 when it didn't give one. A core +// with support files fetches those after itself, and the count starts again for them. ok is +// false when the core isn't being installed. +func (m *Manager) InstallProgress(id string) (int64, int64, bool) { + var r0 int64 + var r1 int64 + var r2 bool + _ = service.Call(context.Background(), "wittyplay", "cores.Manager.InstallProgress", m, m, []any{id}, []any{&r0, &r1, &r2}) + return r0, r1, r2 +} + // List returns the cores here. A core installed through us wins over the same // core elsewhere. func (m *Manager) List() []Core { diff --git a/internal/server/api_games.go b/internal/server/api_games.go index 1fd12acaa..91a91a4b5 100644 --- a/internal/server/api_games.go +++ b/internal/server/api_games.go @@ -71,6 +71,7 @@ func (s *Server) gameRoutes(m routes) { s.gameProfileRoutes(m) m.Handle("GET /api/gaming", s.requireAdmin(s.handleGaming)) m.Handle("POST /api/gaming/cores/{id}/install", s.requireAdmin(s.handleCoreInstall)) + m.Handle("GET /api/gaming/cores/{id}/install", s.requireAdmin(s.handleCoreInstallProgress)) m.Handle("DELETE /api/gaming/cores/{id}", s.requireAdmin(s.handleCoreRemove)) m.Handle("DELETE /api/gaming/unpacked", s.requireAdmin(s.handleUnpackedClear)) s.gameOptionRoutes(m) @@ -333,7 +334,10 @@ type consoleView struct { // CoreSupport is, for each core on offer, the server platforms it runs on and how it draws // on each, and here. Every device plays what any of them runs: the server streams it. CoreSupport map[string]coreSupport `json:"coreSupport,omitempty"` - Pad wittyplay.PadLayout `json:"pad"` + // CoreAbout is, for each core on offer, what it's good at beside the console's others + // (core_notes.go). + CoreAbout map[string]coreNote `json:"coreAbout,omitempty"` + Pad wittyplay.PadLayout `json:"pad"` // Count: with ?library=, how many games that library holds for this console. Count int `json:"count,omitempty"` // Era, years, how its games come and what it can do (game_traits.go). @@ -391,6 +395,12 @@ func (s *Server) consoleViews(ctx context.Context) []consoleView { noGPU = *gpuWhy } v.CoreSupport[want.ID] = coreSupportFor(want.ID, gpuCore, noGPU) + if n := coreNoteFor(want.ID); n != nil { + if v.CoreAbout == nil { + v.CoreAbout = map[string]coreNote{} + } + v.CoreAbout[want.ID] = *n + } } v.NeedsGPU = len(c.Cores) > 0 && len(v.GPUCores) == len(c.Cores) for _, got := range all { diff --git a/internal/server/api_games_custom.go b/internal/server/api_games_custom.go index 6235c6e22..32e0266b8 100644 --- a/internal/server/api_games_custom.go +++ b/internal/server/api_games_custom.go @@ -77,6 +77,7 @@ func (s *Server) customRoutes(m routes) { m.Handle("POST /api/gaming/custom/consoles", s.requireAdmin(on(s.handleCustomConsolePost))) m.Handle("PUT /api/gaming/custom/consoles/{id}", s.requireAdmin(on(s.handleCustomConsolePut))) m.Handle("DELETE /api/gaming/custom/consoles/{id}", s.requireAdmin(s.handleCustomConsoleDelete)) + m.Handle("GET /api/gaming/consoles/{console}/core", s.requireAdmin(s.handleConsoleCoreGet)) m.Handle("PUT /api/gaming/consoles/{console}/core", s.requireAdmin(s.handleConsoleCore)) m.Handle("GET /api/gaming/games/{id}/core", s.requireAdmin(s.handleGameCoreGet)) m.Handle("PUT /api/gaming/games/{id}/core", s.requireAdmin(s.handleGameCorePut)) @@ -1696,7 +1697,8 @@ type GameCoreOption struct { Here *platformSupport `json:"here,omitempty"` } -// GET /api/gaming/games/{id}/core: what would play this game, and what else could. +// GET /api/gaming/games/{id}/core: what would play this game, and what else could: choices for +// the picker (core_choices.go), and options, the installed ones, for clients from before it. func (s *Server) handleGameCoreGet(w http.ResponseWriter, r *http.Request) { it, ok := s.gameItem(r) if !ok { @@ -1705,8 +1707,8 @@ func (s *Server) handleGameCoreGet(w http.ResponseWriter, r *http.Request) { } ctx := r.Context() options := []GameCoreOption{} - var effective string - if console := wittyplay.ByID(it.Console); console != nil { + console := wittyplay.ByID(it.Console) + if console != nil { g := s.games() noGPU, asked := "", false for _, c := range g.cores.List() { @@ -1723,12 +1725,16 @@ func (s *Server) handleGameCoreGet(w http.ResponseWriter, r *http.Request) { options = append(options, o) } } - if core := g.cores.ForConsole(console, s.preferredCore(ctx, console, it.ID)); core != nil { - effective = core.ID - } s.markBestCore(ctx, it.ID, options) } - writeJSON(w, 200, map[string]any{"choice": s.gameCoreChoice(ctx, it.ID), "effective": effective, "options": options}) + // The picker's view of the same, with the cores that aren't installed yet. options stays for + // clients from before it: only the installed ones. + out := map[string]any{"choice": s.gameCoreChoice(ctx, it.ID), "effective": "", "options": options, "choices": []coreChoice{}} + if console != nil { + v := s.coreChoices(ctx, console, it.ID) + out["effective"], out["consoleDefault"], out["choices"], out["canDownload"], out["console"] = v.Effective, v.ConsoleDefault, v.Choices, v.CanDownload, v.Console + } + writeJSON(w, 200, out) } // markBestCore fills in how each core has done on this game, and marks the one that has diff --git a/internal/server/core_choices.go b/internal/server/core_choices.go new file mode 100644 index 000000000..660695dcb --- /dev/null +++ b/internal/server/core_choices.go @@ -0,0 +1,177 @@ +package server + +import ( + "context" + "net/http" + "os" + "path/filepath" + "slices" + + wittyplay "github.com/wittywilla/wittymediaserver/internal/play" + "github.com/wittywilla/wittymediaserver/internal/play/cores" +) + +// The core picker: every core that can play a console, installed or not, with what each is good +// at, where it runs and how it draws, whether it needs a BIOS, and whether it can be installed +// here. One answer for a console's default (GET /gaming/consoles/{console}/core) and for one game +// (GET /gaming/games/{id}/core, beside its older options). Choosing one that isn't installed +// installs it first (POST /gaming/cores/{id}/install, with GET for its progress), then sets it +// with the PUT beside each GET, which only takes an installed core. + +// coreChoice is one core in the picker. +type coreChoice struct { + ID string `json:"id"` + Name string `json:"name"` + License string `json:"license"` + NonCommercial bool `json:"nonCommercial,omitempty"` + // Installed: it's on this server, and Source says from where (installed, retroarch, system or + // custom). CanInstall: it isn't, and installing it here would work. + Installed bool `json:"installed"` + Source string `json:"source,omitempty"` + CanInstall bool `json:"canInstall,omitempty"` + // Recommended is the core this server would pick for the console: the first in its list that's + // published for this platform and can draw here. + Recommended bool `json:"recommended,omitempty"` + // Strength is accuracy, speed or balanced, beside the console's other cores, and About is a + // line on what it's good at (core_notes.go). Neither is there for a custom core. + Strength string `json:"strength,omitempty"` + About string `json:"about,omitempty"` + // Support is where it runs and how it draws, here and on every platform, as in + // GET /games/consoles. Not for a custom core. + Support *coreSupport `json:"support,omitempty"` + // BIOS, when it won't start without a file of the owner's own: any one of Files, and whether + // this server has one. + BIOS *coreBIOSNeed `json:"bios,omitempty"` + // For one game: how the core has gone on it. + Starts int `json:"starts,omitempty"` + Failures int `json:"failures,omitempty"` + Seconds float64 `json:"seconds,omitempty"` + LastError string `json:"lastError,omitempty"` + Best bool `json:"best,omitempty"` +} + +type coreBIOSNeed struct { + Files []string `json:"files"` + Found bool `json:"found"` +} + +// coreChoicesView is the picker's answer. +type coreChoicesView struct { + Console string `json:"console"` + // Choice is what was chosen at this level: the game's own core, or the console's default; "" + // for none. ConsoleDefault, for a game, is its console's. + Choice string `json:"choice"` + ConsoleDefault string `json:"consoleDefault,omitempty"` + // Effective is what plays now, after a missing BIOS or graphics card is taken into account; + // "" when nothing would. + Effective string `json:"effective"` + CanDownload bool `json:"canDownload"` + Choices []coreChoice `json:"choices"` +} + +// coreChoices lists a console's cores for the picker; itemID is 0 for the console's default. +func (s *Server) coreChoices(ctx context.Context, console *wittyplay.Console, itemID int64) coreChoicesView { + g := s.games() + systemDir := g.systemDir() + out := coreChoicesView{Console: console.ID, CanDownload: cores.CanDownload(), Choices: []coreChoice{}} + prefs := s.preferredCores(ctx) + if itemID != 0 { + out.Choice, out.ConsoleDefault = s.gameCoreChoice(ctx, itemID), prefs[console.ID] + } else { + out.Choice = prefs[console.ID] + } + if pick := s.pickCore(ctx, console, itemID, systemDir); pick.core != nil { + out.Effective = pick.core.ID + } + have := map[string]cores.Core{} + for _, c := range g.cores.List() { + if !c.Unapproved { + have[c.ID] = c + } + } + noGPU, asked := "", false + recommended := false + for _, want := range console.Cores { + gpuCore := wittyplay.Traits(want.ID).GPU + if gpuCore && !asked { + noGPU, asked = s.gpuMissing(ctx), true + } + support := coreSupportFor(want.ID, gpuCore, noGPU) + c := coreChoice{ID: want.ID, Name: want.Name, License: want.License, Support: &support} + if got, ok := have[want.ID]; ok { + c.Installed, c.Source = true, got.Source + } + playsHere := support.Here.Build && support.Here.Draws != drawsNone + c.CanInstall = !c.Installed && out.CanDownload && playsHere && cores.Offered(want.ID) + if playsHere && !recommended { + c.Recommended, recommended = true, true + } + if n := coreNoteFor(want.ID); n != nil { + c.Strength, c.About = n.Strength, n.About + } + c.BIOS = coreBIOS(want.ID, systemDir) + out.Choices = append(out.Choices, c) + } + // An administrator's own cores for this console, which are installed by being added. + for _, c := range g.cores.List() { + if c.Source != cores.SourceCustom || c.Unapproved || !slices.Contains(c.Consoles, console.ID) || consoleListsCore(console, c.ID) { + continue + } + out.Choices = append(out.Choices, coreChoice{ID: c.ID, Name: c.Name, License: c.License, NonCommercial: c.NonCommercial, Installed: true, Source: c.Source}) + } + if itemID != 0 { + options := make([]GameCoreOption, len(out.Choices)) + for i, c := range out.Choices { + options[i].ID = c.ID + } + s.markBestCore(ctx, itemID, options) + for i, o := range options { + c := &out.Choices[i] + c.Starts, c.Failures, c.Seconds, c.LastError, c.Best = o.Starts, o.Failures, o.Seconds, o.LastError, o.Best && c.Installed + } + } + return out +} + +// coreBIOS is the BIOS a core won't start without, from its traits in the module or its note +// here, and whether this server has one; nil for a core that starts without. +func coreBIOS(id, systemDir string) *coreBIOSNeed { + if rule := wittyplay.Traits(id).RequiredBIOS; rule != nil { + return &coreBIOSNeed{Files: []string{rule.Example}, Found: wittyplay.MissingBIOS(id, systemDir) == ""} + } + n := coreNoteFor(id) + if n == nil || len(n.BIOS) == 0 { + return nil + } + need := &coreBIOSNeed{Files: n.BIOS} + for _, f := range n.BIOS { + if st, err := os.Stat(filepath.Join(systemDir, filepath.FromSlash(f))); err == nil && st.Mode().IsRegular() { + need.Found = true + break + } + } + return need +} + +// GET /api/gaming/consoles/{console}/core: the console's cores for the picker, and its default. +func (s *Server) handleConsoleCoreGet(w http.ResponseWriter, r *http.Request) { + console := s.gameConsole(r.PathValue("console")) + if console == nil { + writeErr(w, 404, "not found") + return + } + writeJSON(w, 200, s.coreChoices(r.Context(), console, 0)) +} + +// GET /api/gaming/cores/{id}/install: how far an install of this core has got, while one is +// under way: bytes received and the download's size (0 when the download server didn't say). +// A module from before this was asked answers as though nothing were installing. +func (s *Server) handleCoreInstallProgress(w http.ResponseWriter, r *http.Request) { + id := r.PathValue("id") + if !coreIDRe.MatchString(id) { + writeErr(w, 404, "not found") + return + } + got, total, ok := s.games().cores.InstallProgress(id) + writeJSON(w, 200, map[string]any{"installing": ok, "received": got, "total": total}) +} diff --git a/internal/server/core_choices_test.go b/internal/server/core_choices_test.go new file mode 100644 index 000000000..0931e0e1c --- /dev/null +++ b/internal/server/core_choices_test.go @@ -0,0 +1,144 @@ +package server + +import ( + "encoding/json" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/wittywilla/wittymediaserver/internal/modules/modtest" + "github.com/wittywilla/wittymediaserver/internal/play/cores" +) + +// Every core the server knows where to download has a line saying what it's good at, and no +// line is for a core it doesn't know. +func TestEveryCoreHasANote(t *testing.T) { + for id := range coreBuilds { + n, ok := coreNotes[id] + if !ok { + t.Errorf("%s has no note in core_notes.go", id) + continue + } + if n.About == "" || !strings.HasSuffix(n.About, ".") { + t.Errorf("%s: %q should be a sentence", id, n.About) + } + switch n.Strength { + case "", strengthAccuracy, strengthSpeed, strengthBalanced: + default: + t.Errorf("%s: strength %q", id, n.Strength) + } + } + for id := range coreNotes { + if _, ok := coreBuilds[id]; !ok { + t.Errorf("%s has a note, and no line in corebuilds.txt", id) + } + } +} + +// The picker's view of a console: every core it can play on, installed or not, with what each is +// good at, where it runs, and whether it can be installed here; and only for administrators. +func TestCoreChoicesForAConsole(t *testing.T) { + modtest.Need(t, "wittyplay") + g := newGameServer(t) + for _, c := range []struct{ method, path string }{ + {"GET", "/api/gaming/consoles/nes/core"}, {"GET", "/api/gaming/cores/fceumm/install"}, + } { + if w := g.do(c.method, c.path, g.other, nil); w.Code != 403 { + t.Errorf("%s %s for someone who isn't an admin: %d", c.method, c.path, w.Code) + } + } + if w := g.do("GET", "/api/gaming/consoles/nope/core", g.admin, nil); w.Code != 404 { + t.Errorf("an unknown console: %d", w.Code) + } + if w := g.do("GET", "/api/gaming/cores/..%2Fevil/install", g.admin, nil); w.Code != 404 { + t.Errorf("a path is not a core name: %d", w.Code) + } + + // One core installed, as an administrator would have placed it. + dir := g.s.games().cores.Dir + if err := os.MkdirAll(dir, 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(dir, "nestopia_libretro"+cores.LibraryExt()), []byte("x"), 0o755); err != nil { + t.Fatal(err) + } + w := g.do("GET", "/api/gaming/consoles/nes/core", g.admin, nil) + if w.Code != 200 { + t.Fatalf("%d %s", w.Code, w.Body.String()) + } + var v coreChoicesView + if err := json.Unmarshal(w.Body.Bytes(), &v); err != nil { + t.Fatal(err) + } + if v.Console != "nes" || len(v.Choices) < 3 || v.Choices[0].ID != "fceumm" { + t.Fatalf("%+v", v) + } + byID := map[string]coreChoice{} + for _, c := range v.Choices { + byID[c.ID] = c + if c.About == "" || c.Support == nil || c.License == "" { + t.Errorf("%s: about %q, support %v, licence %q", c.ID, c.About, c.Support, c.License) + } + } + if c := byID["nestopia"]; !c.Installed || c.CanInstall { + t.Errorf("an installed core: %+v", c) + } + if c := byID["fceumm"]; c.Installed || c.CanInstall != cores.CanDownload() || !c.Recommended || c.Strength == "" { + t.Errorf("a core to install: %+v", c) + } + if v.Effective != "nestopia" || v.Choice != "" { + t.Errorf("with only Nestopia installed it plays, and nothing was chosen: %q %q", v.Effective, v.Choice) + } + // Chosen as the console's default, it says so. + if w := g.do("PUT", "/api/gaming/consoles/nes/core", g.admin, map[string]any{"core": "nestopia"}); w.Code != 200 { + t.Fatalf("%d %s", w.Code, w.Body.String()) + } + _ = json.Unmarshal(g.do("GET", "/api/gaming/consoles/nes/core", g.admin, nil).Body.Bytes(), &v) + if v.Choice != "nestopia" { + t.Errorf("choice %q", v.Choice) + } + + // Nothing is being installed. + var p struct { + Installing bool + Received, Total int64 + } + if err := json.Unmarshal(g.do("GET", "/api/gaming/cores/fceumm/install", g.admin, nil).Body.Bytes(), &p); err != nil || p.Installing { + t.Errorf("%+v %v", p, err) + } + + // The consoles every signed-in account sees carry the same lines. + var consoles []struct { + ID string `json:"id"` + CoreAbout map[string]coreNote `json:"coreAbout"` + } + _ = json.Unmarshal(g.do("GET", "/api/games/consoles", g.other, nil).Body.Bytes(), &consoles) + found := false + for _, c := range consoles { + if c.ID == "nes" { + found = c.CoreAbout["fceumm"].About == coreNotes["fceumm"].About + } + } + if !found { + t.Error("GET /games/consoles has no coreAbout for the NES's cores") + } +} + +// A core that won't start without a BIOS says so, and says when one is there. +func TestCoreBIOSNeed(t *testing.T) { + system := t.TempDir() + if b := coreBIOS("fceumm", system); b != nil { + t.Errorf("FCEUmm needs no BIOS: %+v", b) + } + b := coreBIOS("mednafen_psx", system) + if b == nil || b.Found || len(b.Files) == 0 { + t.Fatalf("Beetle PSX with no BIOS: %+v", b) + } + if err := os.WriteFile(filepath.Join(system, "scph5502.bin"), make([]byte, 512<<10), 0o644); err != nil { + t.Fatal(err) + } + if b := coreBIOS("mednafen_psx", system); b == nil || !b.Found { + t.Fatalf("Beetle PSX with a European BIOS: %+v", b) + } +} diff --git a/internal/server/core_notes.go b/internal/server/core_notes.go new file mode 100644 index 000000000..3681a4762 --- /dev/null +++ b/internal/server/core_notes.go @@ -0,0 +1,98 @@ +package server + +// What each core on offer is good at, in a line, for choosing between a console's cores: in the +// core picker on a game's page and in Settings, and for the apps (GET /games/consoles gives +// coreAbout; the core choices give each one's). Where it runs and how it draws are corebuilds.txt +// and coreSupport; its licence is the module's console table. Every core in corebuilds.txt has a +// note here (TestEveryCoreHasANote). + +// What a core is chosen for, beside its console's other cores. +const ( + strengthAccuracy = "accuracy" // closest to the console, for more of the processor + strengthSpeed = "speed" // lightest on the server, for slower machines + strengthBalanced = "balanced" // between the two +) + +// coreNote is one core's line. +type coreNote struct { + // Strength is accuracy, speed or balanced, beside its console's other cores; "" for a + // console's only core. + Strength string `json:"strength,omitempty"` + About string `json:"about"` + // BIOS, when the core won't start without one of these files of the owner's own and its traits + // in the module don't already say so. Any one of them will do. + BIOS []string `json:"-"` +} + +var psxBIOS = []string{"scph5501.bin", "scph5500.bin", "scph5502.bin"} + +var coreNotes = map[string]coreNote{ + // NES + "fceumm": {strengthBalanced, "Fast and compatible, with the widest support for unusual cartridges and the Famicom Disk System.", nil}, + "nestopia": {strengthAccuracy, "Accurate, and plays nearly every game, the Famicom Disk System too.", nil}, + "mesen": {strengthAccuracy, "The most accurate, and plays every game. Uses more of the processor.", nil}, + "quicknes": {strengthSpeed, "The lightest, for slow servers. Plays the well-known games, not unusual cartridges.", nil}, + // Super Nintendo + "mednafen_supafaust": {strengthSpeed, "Fast and accurate for nearly every game, spread over several processor cores.", nil}, + "bsnes2014_performance": {strengthBalanced, "bsnes's lighter profile from 2014: accurate, and easy on most servers.", nil}, + "mesen-s": {strengthAccuracy, "Very accurate, and the one that plays Satellaview games (with BS-X.bin).", nil}, + "bsnes": {strengthAccuracy, "Today's bsnes, the reference for accuracy, and the heaviest on the processor.", nil}, + // Game Boy, Game Boy Color + "gambatte": {strengthAccuracy, "Very accurate, and light.", nil}, + "sameboy": {strengthAccuracy, "The most accurate, with Super Game Boy borders and colours.", nil}, + "mgba": {strengthBalanced, "Accurate and fast, with the most features.", nil}, + "gearboy": {strengthSpeed, "Light and fast, with good compatibility.", nil}, + // Game Boy Advance + "vba_next": {strengthSpeed, "Fast, for slower servers, and less accurate.", nil}, + "vbam": {strengthBalanced, "VisualBoyAdvance-M: long-tested, with good compatibility.", nil}, + "gpsp": {strengthSpeed, "The lightest, for low-power servers, and the least accurate. Has a BIOS of its own built in.", nil}, + // Mega Drive + "blastem": {strengthAccuracy, "Very accurate.", nil}, + "clownmdemu": {strengthBalanced, "A newer, accurate core.", nil}, + // Master System, Game Gear + "gearsystem": {strengthAccuracy, "Accurate, for Master System, Game Gear and SG-1000.", nil}, + "smsplus": {strengthSpeed, "Light and fast.", nil}, + // PlayStation + "pcsx_rearmed": {strengthSpeed, "Fast and light, and plays most games without a BIOS file.", nil}, + "mednafen_psx": {strengthAccuracy, "The most accurate, drawn by the processor at the console's own size.", psxBIOS}, + "swanstation": {strengthBalanced, "Fast, and sharper: drawn on a graphics card at higher resolutions.", psxBIOS}, + "mednafen_psx_hw": {strengthAccuracy, "Beetle PSX's accuracy, drawn on a graphics card at higher resolutions.", psxBIOS}, + // PC Engine + "mednafen_pce_fast": {strengthSpeed, "Fast, and plays CD games with your System Card file.", nil}, + "mednafen_pce": {strengthAccuracy, "The full Beetle PCE: more accurate, and plays SuperGrafx games too.", nil}, + "mednafen_supergrafx": {strengthBalanced, "Made for the SuperGrafx, and plays PC Engine games as well.", nil}, + // Atari + "stella2014": {strengthSpeed, "Stella from 2014: light, and plays nearly every game.", nil}, + "stella": {strengthAccuracy, "Today's Stella: the most accurate, with the newest fixes.", nil}, + "prosystem": {"", "Plays Atari 7800 games, with the start-up screen when you add its BIOS.", nil}, + "handy": {strengthSpeed, "Light, and plays most games; better with the Lynx's boot ROM.", nil}, + "mednafen_lynx": {strengthAccuracy, "Mednafen's version of Handy: more accurate.", []string{"lynxboot.img"}}, + // Handhelds + "mednafen_wswan": {"", "Accurate WonderSwan and WonderSwan Color.", nil}, + "mednafen_ngp": {strengthAccuracy, "Accurate Neo Geo Pocket and Color.", nil}, + "race": {strengthSpeed, "Light and fast, with good compatibility.", nil}, + "mednafen_vb": {"", "Accurate Virtual Boy.", nil}, + // Nintendo 64 + "mupen64plus_next": {strengthBalanced, "Plays most games, and sharper at higher resolutions on a graphics card.", nil}, + "parallel_n64": {strengthAccuracy, "Its own graphics plugins, for games Mupen64Plus-Next draws wrongly. Plays libdragon homebrew too.", nil}, + // Nintendo DS + "melonds": {strengthAccuracy, "Accurate, with the DS's own start-up menu when you add its firmware.", nil}, + "desmume": {strengthBalanced, "Long-tested, and plays most games.", nil}, + // Nintendo 3DS + "azahar": {strengthAccuracy, "Carries on from Citra, and plays the most games.", nil}, + "panda3ds": {"", "A newer core, which plays fewer games.", nil}, + // PlayStation 2 + "pcsx2": {strengthAccuracy, "LRPS2, made from PCSX2: plays the most games. Needs a BIOS from your console.", nil}, + "play": {strengthBalanced, "Play!: needs no BIOS, and plays fewer games.", nil}, + // PSP, Dreamcast + "ppsspp": {"", "Plays nearly every PSP game, sharper at higher resolutions on a graphics card.", nil}, + "flycast": {"", "Plays Dreamcast games, sharper at higher resolutions on a graphics card.", nil}, +} + +// coreNoteFor is a core's line, or nothing for a core this server doesn't know, such as a custom one. +func coreNoteFor(id string) *coreNote { + if n, ok := coreNotes[id]; ok { + return &n + } + return nil +} diff --git a/internal/server/corebuilds.txt b/internal/server/corebuilds.txt index 8f26c8fcb..d2960e2c1 100644 --- a/internal/server/corebuilds.txt +++ b/internal/server/corebuilds.txt @@ -5,13 +5,18 @@ fceumm y y y y y y nestopia y y y y y y mesen y y y y y y +quicknes y y y y y y mednafen_supafaust y y y n n n bsnes2014_performance y y y n y y mesen-s y y y n y y +bsnes y y y n y y gambatte y y y y y y sameboy y y n n y y mgba y y y y y y +gearboy y y y y y y vba_next y y y y y y +vbam y y y y y y +gpsp y y y y y y blastem y y y n y y clownmdemu y y y n y y gearsystem y y y y y y @@ -21,12 +26,16 @@ mednafen_psx y y y y y y swanstation y y y n y y mednafen_psx_hw y y y n y y mednafen_pce_fast y y y y y y +mednafen_pce y y y y y y +mednafen_supergrafx y y y y y y stella2014 y y y y y y stella y y y n y y prosystem y y y y y y handy y y y y y y +mednafen_lynx y y y y y y mednafen_wswan y y y y y y mednafen_ngp y y y y y y +race y y y n y y mednafen_vb y y y y y y mupen64plus_next y y y n y y parallel_n64 y y y n y y diff --git a/web/src/api.ts b/web/src/api.ts index 45c317939..3eb7c4faf 100644 --- a/web/src/api.ts +++ b/web/src/api.ts @@ -103,6 +103,8 @@ export type GameConsole = { software?: boolean; notice?: string // Where each core on offer runs, how it draws there, and here: see pages/games/platforms.tsx. coreSupport?: Record + // What each core on offer is good at beside the console's others (docs/GAMING-API.md, Choosing a core). + coreAbout?: Record customCores?: GameCore[]; defaultCore?: string; shared?: string[]; padLike?: string; logoName?: string pad: { face: { id: number; label: string }[]; shoulder?: { id: number; label: string }[]; meta: { id: number; label: string }[]; sticks?: boolean; pointer?: boolean; art?: string } // Its era and years, how its games come, and what it can do (docs/GAMING-API.md, Consoles). diff --git a/web/src/pages/Games.tsx b/web/src/pages/Games.tsx index 216712640..0776a543d 100644 --- a/web/src/pages/Games.tsx +++ b/web/src/pages/Games.tsx @@ -1,4 +1,4 @@ -import { Suspense, useEffect, useMemo, useState } from 'react' +import { lazy, Suspense, useEffect, useMemo, useState } from 'react' import { useNavigate, useParams, useSearchParams } from 'react-router-dom' import { api, getToken, mediaUrl, posterUrl, serverBase, type Item } from '../api' import { LoadError, Spinner } from '../components/common' @@ -17,6 +17,14 @@ import './games.css' // is opened. const GamePlayer = lazyModule('wittyplay', (m) => m.default) // eslint-disable-line @typescript-eslint/no-explicit-any +const CorePicker = lazy(() => import('./games/CorePicker')) + +// chooseCore, for an administrator: the game menu's way to the core picker, drawn by this page over +// the player. It answers restart (start the game again on the new core, without resuming: a state +// from the old core won't load in it), later (the next start uses it) or none (nothing changed). A +// player from before it doesn't ask, and keeps its own way to Settings. +export type CoreChoiceAnswer = 'restart' | 'later' | 'none' +type HostWithCores = PlayHost & { chooseCore?: () => Promise } const Controllers = lazyModule('wittyplay', (m) => m.ControllersPage) // eslint-disable-line @typescript-eslint/no-explicit-any // Controller profiles and the background, through the same routes a TV app uses. @@ -60,16 +68,18 @@ export function GamePage() { const [params] = useSearchParams() const [it, setIt] = useState(null) const [err, setErr] = useState('') + const [choosing, setChoosing] = useState<{ answer: (a: CoreChoiceAnswer) => void } | null>(null) const { user } = useApp() const settingsHost = useSettingsHost(!!user?.isAdmin) useEffect(() => { Promise.all([api.get(`/items/${id}`), getConsoles().then((l) => { for (const c of l) knownConsoles.set(c.id, c.short) }).catch(() => {})]).then(([i]) => setIt(i)).catch((e) => setErr(e.message)) }, [id]) - const host = useMemo(() => { + const host = useMemo(() => { if (!it) return null return { ...settingsHost, itemId: it.id, title: it.title, consoleId: it.console || '', consoleName: consoleName(it.console || ''), resume: params.get('resume') === '1', safeMode: params.get('safe') === '1', startSlot: Number(params.get('slot') || 0) || undefined, cover: it.poster ? `${posterUrl(it)}&w=480` : undefined, openSettings: () => nav('/settings/gaming'), + chooseCore: user?.isAdmin ? () => new Promise((answer) => setChoosing({ answer })) : undefined, prepare: () => api.post(`/games/${it.id}/prepare`), start: (resume, safeMode) => api.post(`/games/${it.id}/play`, { resume, safeMode, client: 'browser' }).then((s) => { setLogSession(s.id); return s }), report: (level, message) => reportClient({ level, kind: 'game', message, module: 'wittyplay' }), @@ -96,10 +106,20 @@ export function GamePage() { action: (sid, type, slot, on, extra) => api.post(`/play/${sid}/action`, { type, slot: slot ?? 0, on: !!on, ...extra }), close: () => nav(getTvMode() ? `/games/game/${it.id}` : couchOn() ? `/big/game/${it.id}` : `/item/${it.id}`, { replace: true }), } - }, [it, settingsHost]) + }, [it, settingsHost, user?.isAdmin]) if (err) return
window.location.reload()} />

{err}

if (!host) return - return }> + return ( + <> + }> + {choosing && it && ( + + { choosing.answer(!picked ? 'none' : picked.restart ? 'restart' : 'later'); setChoosing(null) }} /> + + )} + + ) } const consoleName = (id: string) => knownConsoles.get(id) || id.toUpperCase() diff --git a/web/src/pages/games.css b/web/src/pages/games.css index e87c9ae8e..7f6b32e4d 100644 --- a/web/src/pages/games.css +++ b/web/src/pages/games.css @@ -136,8 +136,5 @@ .custom-audit ul { list-style: none; margin: var(--sp-2) 0 0; padding: 0; max-height: 320px; overflow: auto; display: grid; gap: var(--sp-2); } .custom-audit li { display: grid; gap: 1px; } .custom-detail { display: block; overflow-wrap: anywhere; color: var(--fg-3); font-size: var(--text-xs); } -.custom-gamecore { margin-top: var(--sp-3); font-size: var(--text-sm); max-width: 460px; } -.custom-gamecore summary { cursor: pointer; color: var(--fg-2); min-height: 32px; } -.custom-gamecore-stats { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-1); } .linkish { background: none; border: 0; padding: 0; color: var(--accent-text); text-decoration: underline; cursor: pointer; font: inherit; } diff --git a/web/src/pages/games/CorePicker.tsx b/web/src/pages/games/CorePicker.tsx new file mode 100644 index 000000000..37d1e52cb --- /dev/null +++ b/web/src/pages/games/CorePicker.tsx @@ -0,0 +1,283 @@ +import { useCallback, useEffect, useRef, useState, type KeyboardEvent } from 'react' +import { api } from '../../api' +import { Spinner } from '../../components/common' +import { IconCheck, IconInfo } from '../../icons' +import { toast } from '../../state' +import { Sheet } from '../../ui' +import { drawsWords, platformName, type CoreSupport } from './platforms' +import './corepicker.css' + +// The core picker: which core plays one game, or a console's games unless a game says otherwise. +// Each core says what it's good at, where it runs and how it draws, and whether it needs a BIOS or +// isn't installed yet. Choosing one that isn't installed installs it, with its progress, and then +// uses it. During a game, choosing another offers to restart on it. It's a sheet: ×, Escape, a +// controller's B or a remote's Back, or a tap outside closes it. Administrators only; the server +// answers 403 to anyone else. The API is docs/GAMING-API.md, "Choosing a core". + +export type CoreChoice = { + id: string; name: string; license: string; nonCommercial?: boolean + installed: boolean; source?: string; canInstall?: boolean; recommended?: boolean + strength?: 'accuracy' | 'speed' | 'balanced'; about?: string + support?: CoreSupport; bios?: { files: string[]; found: boolean } + starts?: number; failures?: number; seconds?: number; lastError?: string; best?: boolean +} +export type CoreChoices = { console: string; choice: string; consoleDefault?: string; effective: string; canDownload: boolean; choices: CoreChoice[] } + +export type CorePickerScope = + | { kind: 'game'; itemId: number; title: string; consoleShort: string } + | { kind: 'console'; consoleId: string; consoleShort: string } + +// What the picker settled on: the core now chosen, and, during a game, whether to restart on it. +export type CorePicked = { core: string; restart: boolean } + +type SaveSlot = { slot: number; core?: string } +type Progress = { received: number; total: number } | null + +const STRENGTH: Record = { accuracy: 'Accuracy', speed: 'Speed', balanced: 'Balanced' } + +const and = (l: string[]) => (l.length < 2 ? l.join('') : `${l.slice(0, -1).join(', ')} and ${l[l.length - 1]}`) +const mb = (n: number) => (n >= 1e6 ? `${(n / 1e6).toFixed(1)} MB` : `${Math.max(1, Math.round(n / 1e3))} KB`) +const hours = (sec: number) => (sec < 3600 ? `${Math.max(1, Math.round(sec / 60))} min` : `${(sec / 3600).toFixed(sec < 36000 ? 1 : 0)} h`) + +// How it draws here, in a few words: "Drawn by the processor here." +function hereLine(s?: CoreSupport) { + if (!s) return '' + const h = s.here + if (!h.build) return h.note || 'Not published for this server.' + if (h.draws === 'none') return h.note || 'Can’t draw on this server.' + return `Here: drawn ${drawsWords[h.draws]}${h.draws === 'gpu' && h.api === 'opengl' ? ' (OpenGL)' : ''}.` +} + +// Which server systems it's published for, by name only: "Runs on Windows, Linux and macOS." +function runsLine(s?: CoreSupport) { + if (!s) return '' + const names: string[] = [] + for (const p of s.platforms) { + if (!p.build || p.draws === 'none') continue + const n = platformName({ os: p.os }) + if (!names.includes(n)) names.push(n) + } + return names.length ? `Runs on ${and(names)}.` : '' +} + +// Save states only load in the core that made them; the slots say which made each, by its name. +const sameCore = (made: string | undefined, c: CoreChoice) => { + if (!made) return true + const a = made.toLowerCase(), b = c.name.toLowerCase() + return a === b || a.startsWith(b) || b.startsWith(a) +} + +export default function CorePicker({ scope, onClose, playing, onPicked }: { + scope: CorePickerScope + onClose: (picked?: CorePicked) => void + playing?: boolean // during a game: a change offers to restart on the new core + onPicked?: (core: string) => void +}) { + const [info, setInfo] = useState(null) + const [failed, setFailed] = useState('') + const [confirm, setConfirm] = useState('') + const [busy, setBusy] = useState('') + const [progress, setProgress] = useState(null) + const [restart, setRestart] = useState(null) + const [states, setStates] = useState([]) + const listRef = useRef(null) + const alive = useRef(true) + useEffect(() => () => { alive.current = false }, []) + + const base = scope.kind === 'game' ? `/gaming/games/${scope.itemId}/core` : `/gaming/consoles/${encodeURIComponent(scope.consoleId)}/core` + const load = useCallback(() => api.get(base).then((v) => { if (alive.current) setInfo(v) }).catch((e: any) => { if (alive.current) setFailed(e.message) }), [base]) + useEffect(() => { void load() }, [load]) + useEffect(() => { + if (scope.kind === 'game') api.get(`/games/${scope.itemId}/saves`).then((s) => { if (alive.current) setStates(s) }).catch(() => {}) + }, [scope]) + // The controller and the remote start on what's chosen now. + useEffect(() => { + if (!info) return + listRef.current?.querySelector('[aria-checked="true"]')?.focus({ preventScroll: false }) + }, [!!info]) // eslint-disable-line react-hooks/exhaustive-deps + + const title = scope.kind === 'game' ? `Core for ${scope.title}` : `Core for ${scope.consoleShort} games` + const byId = (id: string) => info?.choices.find((c) => c.id === id) + + // Saves the choice. During a game, a change to what plays offers to restart on it. + const save = async (core: string) => { + const before = info?.effective + await api.put(base, { core }) + onPicked?.(core) + const v = await api.get(base) + if (alive.current) setInfo(v) + const now = v.choices.find((c) => c.id === v.effective) + if (playing && now && v.effective !== before) { + if (alive.current) setRestart(now) + return + } + const c = v.choices.find((x) => x.id === core) + toast(!core ? (scope.kind === 'game' ? `Plays with the same core as other ${scope.consoleShort} games` : 'The first core installed plays these games') : `${c?.name || core} ${scope.kind === 'game' ? 'plays this game' : `plays ${scope.consoleShort} games`} from the next start`) + } + + const choose = async (id: string) => { + if (busy) return + const c = byId(id) + if (id && c && !c.installed) { + if (c.canInstall) setConfirm(id) + return + } + setConfirm('') + setBusy(id || 'auto') + try { await save(id) } catch (e: any) { toast(e.message) } finally { if (alive.current) setBusy('') } + } + + // Install, showing how far the download has got, then use it. The install goes on if the picker + // is closed meanwhile, and the core is still put to use. + const install = async (c: CoreChoice) => { + setBusy(c.id) + setProgress({ received: 0, total: 0 }) + let polling = true + const poll = async () => { + while (polling) { + try { + const p = await api.get<{ installing: boolean; received: number; total: number }>(`/gaming/cores/${c.id}/install`) + if (polling && alive.current && p.installing) setProgress({ received: p.received, total: p.total }) + } catch { /* the install itself says what went wrong */ } + await new Promise((r) => setTimeout(r, 250)) + } + } + void poll() + try { + await api.post(`/gaming/cores/${c.id}/install`) + polling = false + toast(`${c.name} installed`) + if (alive.current) setConfirm('') + await save(c.id) + } catch (e: any) { + polling = false + // A core with no build here says so, naming one that plays the console instead. + toast(e.message) + } finally { + polling = false + if (alive.current) { setBusy(''); setProgress(null) } + } + } + + // Up and Down move between the choices, as in any list of options. + const onKeyDown = (e: KeyboardEvent) => { + if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return + const rows = [...(listRef.current?.querySelectorAll('.cp-row:not(:disabled)') || [])] + const i = rows.indexOf(document.activeElement as HTMLElement) + if (i < 0) return + const next = rows[i + (e.key === 'ArrowDown' ? 1 : -1)] + if (next) { e.preventDefault(); next.focus() } + } + + if (restart) { + const others = [...new Set(states.filter((s) => s.core && !sameCore(s.core, restart)).map((s) => s.core!))] + const resumeFrom = states.find((s) => s.slot === 0) + return ( + onClose({ core: restart.id, restart: false })} className="cp-sheet" + actions={<> + + + }> +
+

{scope.kind === 'game' ? scope.title : 'This game'} will play on {restart.name} from now on. Restart now to switch, or keep playing and it switches the next time the game starts.

+
    +
  • In-game saves stayBattery saves and memory cards belong to the game, whichever core plays it.
  • +
  • Save states stay with their core{others.length + ? `Your save states made with ${and(others)}${resumeFrom && !sameCore(resumeFrom.core, restart) ? ', including where you left off,' : ''} only load in ${others.length === 1 ? 'that core' : 'those cores'}. They’re kept for when you switch back.` + : 'A save state only loads in the core that made it. Those you make now are for this core.'}
  • +
+
+
+ ) + } + + const autoSelected = !!info && !info.choice + // What the first row comes to: the console's default, or else the first core installed. + const firstInstalled = info?.choices.find((c) => c.installed && c.source !== 'custom') + const consoleDefault = (info?.consoleDefault && byId(info.consoleDefault)) || undefined + const autoName = scope.kind === 'game' + ? `Same as other ${scope.consoleShort} games` + : 'Automatic' + const autoSub = scope.kind === 'game' + ? consoleDefault + ? `${consoleDefault.name}, chosen for every ${scope.consoleShort} game in Settings, Consoles & cores.` + : firstInstalled ? `${firstInstalled.name}, the first core installed for ${scope.consoleShort}.` : `The first core installed for ${scope.consoleShort}.` + : `${firstInstalled ? `${firstInstalled.name}: the` : 'The'} first core installed, in this order. A core that can’t start a game, for want of a BIOS, gives way to the next.` + + return ( + onClose()} className="cp-sheet"> +

A core is the program that plays these games on your server. Every device plays them: the server runs the game and streams it.

+ {failed && !info &&

{failed}

} + {!info && !failed && } + {info && ( +
+ + {info.choices.map((c) => { + const selected = info.choice === c.id + const usable = c.installed || !!c.canInstall + const state = c.installed ? 'Installed' : c.canInstall ? 'Not installed' : !info.canDownload ? 'No download here' : 'Not on this server' + const here = hereLine(c.support) + const runs = runsLine(c.support) + const installing = busy === c.id && !c.installed + return ( +
+ + {confirm === c.id && ( +
+ {installing ? ( + <> + +

{progress?.total ? `Downloading ${c.name}: ${mb(progress.received)} of ${mb(progress.total)}` : `Installing ${c.name}…`}

+ + ) : ( + <> +

Install {c.name} and use it? It downloads from buildbot.libretro.com, the libretro project’s build server, and runs boxed in on this server whenever someone plays. License: {c.license}. It’s its authors’ work and stays a separate program.

+
+ + +
+ + )} +
+ )} +
+ ) + })} +
+ )} + {info &&

Switching keeps your in-game saves. A save state only loads in the core that made it.

} +
+ ) +} diff --git a/web/src/pages/games/Details.tsx b/web/src/pages/games/Details.tsx index 3ab8ec97b..d40727331 100644 --- a/web/src/pages/games/Details.tsx +++ b/web/src/pages/games/Details.tsx @@ -11,20 +11,21 @@ import { toast, useApp } from '../../state' import { ask, Dialog, Menu, type MenuEntry } from '../../ui' import { GameCredits, GameMatchBar, GameRatings, GameShots } from '../GameMeta' import { GameFixPanel, GameProblem, GameVersionLinks } from '../GameReview' -import { SettingsScreen, useConsoles, useSettingsHost } from './consoles' +import { getConsoles, SettingsScreen, useConsoles, useSettingsHost } from './consoles' import { crispIfSmall, fmtPlayed, heroCover, saveThumb, useCoverTint, useGameLinks, type GameCheck } from './data' import { Ambient } from './Library' import './shelves.css' import type { SaveSlot } from '@wittywilla/wittyplay' import './games-ui.css' import { CorePlatforms, runsOnWords } from './platforms' +import type { CorePickerScope } from './CorePicker' // A game's page: what it is, a big button to play it, where you left off, and everything // else about it below. Whatever's stopping a game from starting says so here, with the // way to fix it, rather than waiting for someone to press Play. -// Only administrators ever see this, so nobody else downloads the settings code for it. -const GameCorePicker = lazy(() => import('../settings/GamingCustom').then((m) => ({ default: m.GameCorePicker }))) +// Only administrators ever choose a core, so nobody else downloads the picker. +const CorePicker = lazy(() => import('./CorePicker')) type GamePersonal = { favourite: boolean; note: string; plays: number; lastPlayed: number; cheats: { name?: string; enabled?: boolean }[]; hasBattery?: boolean } @@ -56,6 +57,7 @@ export default function GameDetails({ it, reload }: { it: Item; reload?: () => v const [saves, setSaves] = useState([]) const [meta, setMeta] = useState(null) const [check, setCheck] = useState(null) + const [picker, setPicker] = useState(null) const [mine, setMine] = useState(null) const [resumeMode, setResumeMode] = useState('ask') const [showSettings, setShowSettings] = useState(false) @@ -174,7 +176,7 @@ export default function GameDetails({ it, reload }: { it: Item; reload?: () => v ? Resume : ready && Play} {ready && auto && Start over} - {!ready && check?.reason === 'core' && !check.noBuild && user?.isAdmin && Install a core} + {!ready && check?.reason === 'core' && !check.noBuild && user?.isAdmin && c && } {!ready && check?.reason === 'bios' && user?.isAdmin && Set up {c?.short}} {mine && ( } + + )} + {check?.reason === 'core' && !check.noBuild &&
  • No core installed{user?.isAdmin && c + ? <>A core is the free program that plays these games. + : Ask whoever runs this server.}
  • } {check?.needsGpu && check.reason !== 'gpu' &&
  • Uses the server’s graphics cardThis console is drawn with one, so it needs a server that has one.
  • } {check?.software &&
  • Drawn by the server’s processorThis server has no graphics card games can use, so its processor draws this console’s games. They can run slower than on a server with one.
  • } {check?.reason === 'gpu' &&
  • Needs a graphics card this server can’t give it{check.gpuMissing ? `Why: ${check.gpuMissing}.` : 'This server has none it can use.'}
  • } @@ -284,7 +295,6 @@ export default function GameDetails({ it, reload }: { it: Item; reload?: () => v {/* Reserved and not built: playing with someone on another server. Never an action. */}
  • MultiplayerPlay with someone on another server. Coming later.
  • - {user?.isAdmin && }

    Controls

    @@ -334,6 +344,7 @@ export default function GameDetails({ it, reload }: { it: Item; reload?: () => v {meta && } + {picker && { setPicker(null); void loadCheck(); void getConsoles(true) }} />} {edit && setEdit(false)} onSaved={() => { setEdit(false); reload?.() }} />} {art && setArt(false)} diff --git a/web/src/pages/games/corepicker.css b/web/src/pages/games/corepicker.css new file mode 100644 index 000000000..02e0c9c16 --- /dev/null +++ b/web/src/pages/games/corepicker.css @@ -0,0 +1,39 @@ +/* The core picker (CorePicker.tsx): a sheet from the side on wide screens and from the bottom on a + phone, one row per core, each a radio button big enough for a thumb, a remote or a controller. */ +.modal.ui-sheet.cp-sheet { width: min(32rem, 100vw); } +@media (max-width: 600px) { .modal.ui-sheet.cp-sheet { max-height: 92dvh; border-radius: var(--r-lg) var(--r-lg) 0 0; } } +.cp-intro { margin: 0 0 var(--sp-3); color: var(--fg-2); font-size: var(--text-sm); } +.cp-list { display: grid; gap: var(--sp-2); } +.cp-item { display: grid; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--bg-2); min-width: 0; } +.cp-item.on { border-color: var(--accent-line); background: var(--accent-soft); } +.cp-list > .cp-row { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--bg-2); } +.cp-list > .cp-row[aria-checked="true"] { border-color: var(--accent-line); background: var(--accent-soft); } +.cp-row { display: flex; align-items: flex-start; gap: var(--sp-3); width: 100%; min-height: 56px; padding: var(--sp-3); border: 0; border-radius: var(--r-lg); background: none; color: var(--fg); font: inherit; text-align: start; cursor: pointer; } +.cp-row:disabled { cursor: default; } +.cp-item.off .cp-row { color: var(--fg-2); } +.cp-row:not(:disabled):hover { background: var(--bg-3); } +.cp-item.on .cp-row:not(:disabled):hover, .cp-list > .cp-row[aria-checked="true"]:not(:disabled):hover { background: none; } +/* The radio's circle, filled when chosen. */ +.cp-mark { flex: none; width: 20px; height: 20px; margin-top: 2px; border: 2px solid var(--fg-3); border-radius: var(--r-full); } +.cp-row[aria-checked="true"] .cp-mark { border-color: var(--accent); background: radial-gradient(circle, var(--accent) 0 45%, transparent 50%); } +.cp-main { display: grid; gap: var(--sp-1); min-width: 0; flex: 1; } +.cp-name { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-2); } +.cp-chip { display: inline-flex; align-items: center; min-height: 20px; padding: 0 var(--sp-2); border-radius: var(--r-full); background: var(--bg-3); color: var(--fg-2); font-size: var(--text-xs); font-weight: 600; } +.cp-chip.now { background: var(--ok-soft); color: var(--fg); } +.cp-chip.accuracy, .cp-chip.speed, .cp-chip.balanced { color: var(--fg); } +.cp-line { font-size: var(--text-sm); color: var(--fg-2); overflow-wrap: anywhere; } +.cp-facts { color: var(--fg-3); } +.cp-bios { display: flex; align-items: flex-start; gap: var(--sp-1); font-size: var(--text-xs); color: var(--fg-2); overflow-wrap: anywhere; } +.cp-bios svg { flex: none; margin-top: 1px; color: var(--warn); } +.cp-bios.ok svg { color: var(--ok); } +.cp-stats, .cp-small { font-size: var(--text-xs); color: var(--fg-3); overflow-wrap: anywhere; } +.cp-install { display: grid; gap: var(--sp-2); padding: 0 var(--sp-3) var(--sp-3) calc(var(--sp-3) * 2 + 20px); font-size: var(--text-sm); } +.cp-install p { margin: 0; } +.cp-install progress { width: 100%; height: 8px; accent-color: var(--accent); } +.cp-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-2); } +.cp-foot { margin: var(--sp-3) 0 0; font-size: var(--text-xs); } +.cp-restart p { margin: 0 0 var(--sp-3); } +@media (max-width: 600px) { .cp-install { padding-left: var(--sp-3); } } +/* From across the room: bigger targets, and room for the lifted focus ring. */ +html.tv-mode .cp-row, html.ten-foot .cp-row { min-height: 72px; } +html.tv-mode .cp-list, html.ten-foot .cp-list { gap: var(--sp-3); padding: var(--sp-1); } diff --git a/web/src/pages/games/games-ui.css b/web/src/pages/games/games-ui.css index d6e8a7682..93284a48d 100644 --- a/web/src/pages/games/games-ui.css +++ b/web/src/pages/games/games-ui.css @@ -255,6 +255,12 @@ html.gm-couch, html.gm-couch body { background: var(--bg); } .gm-setup-cores { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-2); } .gm-setup-cores li { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); min-width: 0; } .gm-setup-note { margin: var(--sp-3) 0 var(--sp-2); } +/* The core a console plays with, and the way to change it (CorePicker.tsx). */ +.gm-setup-core { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-top: var(--sp-3); min-width: 0; } +.gm-setup-core > span { display: grid; gap: 2px; min-width: 0; } +.gm-setup-core small { font-size: var(--text-xs); overflow-wrap: anywhere; } +.gm-setup-core .btn { flex: none; } +.gm-core-line .gm-core-change { justify-self: start; margin-top: var(--sp-2); } .gm-pill { display: inline-flex; align-items: center; gap: var(--sp-1); min-height: 24px; padding: 0 var(--sp-2); border-radius: var(--r-full); font-size: var(--text-xs); font-weight: 600; background: var(--bg-3); color: var(--fg); } .gm-pill.ok svg { color: var(--ok); } .gm-pill.warn { background: var(--warn-soft); } diff --git a/web/src/pages/settings/Gaming.tsx b/web/src/pages/settings/Gaming.tsx index f66b9d6bd..2770685b5 100644 --- a/web/src/pages/settings/Gaming.tsx +++ b/web/src/pages/settings/Gaming.tsx @@ -1,4 +1,4 @@ -import { useEffect, useMemo, useState } from 'react' +import { lazy, Suspense, useEffect, useMemo, useState } from 'react' import { Link } from 'react-router-dom' import { api, type GameConsole, type GameCore } from '../../api' import { LoadError, Spinner } from '../../components/common' @@ -6,12 +6,15 @@ import { IconCheck, IconGamepad, IconInfo } from '../../icons' import { toast } from '../../state' import { Dialog } from '../../ui' import { getConsoles } from '../games/consoles' -import CustomCoresSection, { ConsoleCoreSelect, licenseText } from './GamingCustom' +import CustomCoresSection, { licenseText } from './GamingCustom' import RegionOrder from './RegionOrder' import { PageHead, Section } from './ui' import LegalNote from '../../components/LegalNote' import '../games/games-ui.css' import { CorePlatforms, type CoreAlternative } from '../games/platforms' +import type { CorePickerScope } from '../games/CorePicker' + +const CorePicker = lazy(() => import('../games/CorePicker')) // Settings, Consoles & cores. What most people need is one screen: each console they have // games for, whether it's ready to play, and the one thing to do if it isn't. Everything @@ -57,6 +60,7 @@ export default function GamingSettings() { const [st, setSt] = useState(null) const [busy, setBusy] = useState('') const [confirm, setConfirm] = useState<{ id: string; name: string; license: string }[] | null>(null) + const [picker, setPicker] = useState(null) const [settings, setSettings] = useState | null>(null) const [failed, setFailed] = useState(false) const load = () => api.get('/gaming').then(setSt).catch(() => setFailed(true)) @@ -164,7 +168,17 @@ export default function GamingSettings() { {s === 'gpu' &&

    Its games are drawn with a graphics card, and this server doesn’t have one it can use{c.gpuMissing ? `: ${c.gpuMissing}` : ''}. Its games are listed, and can’t be started here.

    } {s === 'ready' && c.needsGpu && !c.software &&

    Uses this server’s graphics card.

    } {s === 'ready' && c.software &&

    This server has no graphics card games can use, so its processor draws these games. They can run slower than on a server with one, and keep several processor cores busy.

    } - + {s !== 'none' && (c.cores.length > 0 || (c.customCores?.length ?? 0) > 0) && (() => { + // What plays these games now: the default chosen here, or the first core installed. + const now = (c.defaultCore && c.installed.find((x) => x.id === c.defaultCore)) || c.installed[0] + return ( +
    + {c.defaultCore ? 'Plays with' : 'Plays with, automatically'}{now ? now.name : 'No core yet'} + {now && c.coreAbout?.[now.id] && {c.coreAbout[now.id].about}} + +
    + ) + })()} {(c.cores.length > 1 || biosList.length > 0 || (c.customCores?.length ?? 0) > 0 || (s === 'ready' && c.cores.length > 0)) && (
    Cores and BIOS files @@ -343,6 +357,7 @@ export default function GamingSettings() { )} + {picker && { setPicker(null); void refresh() }} />} {confirm && ( setConfirm(null)} actions={<>}> diff --git a/web/src/pages/settings/GamingCustom.tsx b/web/src/pages/settings/GamingCustom.tsx index 9cff0e01a..f001c3eef 100644 --- a/web/src/pages/settings/GamingCustom.tsx +++ b/web/src/pages/settings/GamingCustom.tsx @@ -6,7 +6,6 @@ import { toast } from '../../state' import { getConsoles } from '../games/consoles' import { Row, Section, Switch } from './ui' import { ask } from '../../ui/Overlay' -import { hereShort, type PlatformSupport } from '../games/platforms' // Settings, Consoles & cores: an administrator's own cores and consoles. A core is a program // that runs on the server, so the page says so before anything else, asks for the @@ -727,55 +726,3 @@ export default function CustomCoresSection({ onChanged }: { onChanged: () => voi ) } - -// A console's core, for its card in Settings, Consoles & cores. -export function ConsoleCoreSelect({ console: c, onChanged }: { console: GameConsole; onChanged: () => void }) { - const list = c.installed - if (!list || list.length < 2) return null - const value = c.defaultCore || '' - return ( - - ) -} - -// A game's own core, on its page, for administrators only. -type GameCoreOption = { id: string; name: string; source: string; license: string; nonCommercial?: boolean; starts: number; failures: number; seconds: number; lastError?: string; best?: boolean; here?: PlatformSupport } -export function GameCorePicker({ itemId }: { itemId: number }) { - const [info, setInfo] = useState<{ choice: string; effective: string; options: GameCoreOption[] } | null>(null) - const load = () => api.get<{ choice: string; effective: string; options: GameCoreOption[] }>(`/gaming/games/${itemId}/core`).then(setInfo).catch(() => {}) - useEffect(() => { load() }, [itemId]) - if (!info || info.options.length < 2) return null - const set = async (core: string) => { - try { await api.put(`/gaming/games/${itemId}/core`, { core }); toast('Saved'); await load() } catch (e: any) { toast(e.message) } - } - const shown = info.options.find((o) => o.id === (info.choice || info.effective)) - return ( -
    - Core: {shown?.name || 'none'}{info.choice ? ' (just for this game)' : ''} - -
      - {info.options.filter((o) => o.starts > 0).map((o) => ( -
    • {o.name}: {o.starts} {o.starts === 1 ? 'start' : 'starts'}, {fmtHours(o.seconds)}{o.failures ? `, ${o.failures} failed` : ''}{o.lastError ? Last problem: {o.lastError} : null}
    • - ))} -
    -
    - ) -}