Complete the Modern main menu and persistent mod library (by Codex)
This commit is contained in:
1 parent
ab4a962a39
commit
6bcd95d668
21 files changed
+2043
-248
No files matched your search
@@ -52,9 +52,9 @@ jobs:
|
||||
- name: Configure opt-in UI without external assets
|
||||
run: cmake -S . -B build-ui -G Ninja -DCMAKE_BUILD_TYPE=Release -DOPENBMH_BUILD_MODERN_UI=ON -DOPENBMH_BUILD_EDITOR=OFF -DBMH_DATA=
|
||||
- name: Compile native frontend and synthetic checks
|
||||
run: cmake --build build-ui --target openbmh_play modern_ui_core_tests modern_ticket_document_tests modern_control_layout_tests modern_reports_tests modern_planning_tests modern_almanac_ui_tests modern_finance_ui_tests modern_environment_ui_tests modern_advertising_ui_tests modern_toto_ui_tests modern_lineup_ui_tests modern_transfer_ui_tests modern_career_reports_tests modern_rankings_tests modern_stadium_ui_tests modern_statistics_ui_tests modern_news_ui_tests modern_settings_ui_tests modern_desktop_ui_tests modern_files_ui_tests --parallel 2
|
||||
run: cmake --build build-ui --target openbmh_play modern_ui_core_tests modern_ticket_document_tests modern_control_layout_tests modern_reports_tests modern_planning_tests modern_almanac_ui_tests modern_finance_ui_tests modern_environment_ui_tests modern_advertising_ui_tests modern_toto_ui_tests modern_lineup_ui_tests modern_transfer_ui_tests modern_career_reports_tests modern_rankings_tests modern_stadium_ui_tests modern_statistics_ui_tests modern_news_ui_tests modern_settings_ui_tests modern_desktop_ui_tests modern_files_ui_tests modern_mods_ui_tests --parallel 2
|
||||
- name: Check controls, fonts, density and draft cancellation
|
||||
run: ctest --test-dir build-ui -R "^modern_(ui_|ticket_|control_|reports_|planning_|almanac_ui_|finance_ui_|environment_ui_|advertising_ui_|toto_ui_|lineup_ui_|transfer_ui_|career_reports_|rankings_|stadium_ui_|statistics_ui_|news_ui_|settings_ui_|desktop_ui_|files_ui_)" --output-on-failure --output-junit modern-ui-results.xml
|
||||
run: ctest --test-dir build-ui -R "^modern_(ui_|ticket_|control_|reports_|planning_|almanac_ui_|finance_ui_|environment_ui_|advertising_ui_|toto_ui_|lineup_ui_|transfer_ui_|career_reports_|rankings_|stadium_ui_|statistics_ui_|news_ui_|settings_ui_|desktop_ui_|files_ui_|mods_ui_)" --output-on-failure --output-junit modern-ui-results.xml
|
||||
- name: Upload test report
|
||||
if: always()
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
.front-home {position:absolute;left:0;top:0;width:3840dp;height:2160dp;}
|
||||
.main-options {display:flex;flex-direction:column;gap:18dp;}
|
||||
.main-options button {display:flex;align-items:center;justify-content:flex-start;gap:36dp;margin:0;height:128dp;padding:18dp 38dp;border:1dp transparent;border-radius:12dp;color:#d3dfe7;}
|
||||
.main-options button>span {display:block;flex-shrink:0;}
|
||||
.main-options button>small {display:block;flex-shrink:0;margin:0;font-size:25dp;letter-spacing:1dp;color:#a4b8c5;}
|
||||
.main-options button:last-child {margin-top:18dp;}
|
||||
.main-options button .front-hover-arrow {margin-left:auto;font-size:52dp;color:#b2ded0;opacity:0;}
|
||||
.main-options button:hover .front-hover-arrow,.main-options button:focus-visible .front-hover-arrow {opacity:1;}
|
||||
.main-options button:disabled {color:#7a8f9e;opacity:0.5;}
|
||||
.main-options button:disabled .front-hover-arrow {opacity:0;}
|
||||
.front-active {display:flex;align-items:center;gap:26dp;}
|
||||
.front-active-dot,.front-mod-active-dot {display:block;width:12dp;height:12dp;flex-shrink:0;border-radius:6dp;background-color:#b0dac9;}
|
||||
.front-active>div {display:flex;flex-direction:column;gap:10dp;}
|
||||
.front-active small {display:block;font-size:22dp;color:#849dad;}
|
||||
.front-active strong {display:block;font-size:29dp;font-weight:normal;color:#bacdd7;}
|
||||
.front-footer .front-version {font-size:22dp;letter-spacing:2dp;color:#8da5b3;}
|
||||
.front-mod-content {position:absolute;left:52dp;right:52dp;top:148dp;bottom:98dp;}
|
||||
.front-mod-tabs {display:flex;gap:20dp;height:86dp;}
|
||||
.front-mod-tabs button {min-width:340dp;height:86dp;font-size:30dp;}
|
||||
.front-mod-tabs button.active {border-color:var(--accent);background-color:var(--selected);}
|
||||
.front-mod-tabpanel {position:absolute;left:0;right:0;top:126dp;bottom:170dp;}
|
||||
.front-mod-layout {position:absolute;left:0;right:0;top:0;bottom:0;}
|
||||
.front-mod-browser {position:absolute;left:0;top:0;bottom:0;width:1158.296dp;border:2dp var(--border);border-radius:18dp;background-color:var(--panel);overflow:hidden;}
|
||||
.front-mod-browser>header {display:flex;align-items:center;padding:28dp 30dp;border-bottom:2dp var(--border);font-size:27dp;color:var(--muted);}
|
||||
.front-mod-browser>header>span:first-child {display:block;flex:1;}
|
||||
.front-mod-browser>header>span:last-child {display:block;width:170dp;text-align:center;}
|
||||
.front-mod-list {position:absolute;left:0;right:0;top:90dp;bottom:0;padding:14dp;overflow-y:auto;overflow-x:hidden;}
|
||||
.front-mod-entry {display:flex;align-items:center;gap:22dp;width:100%;min-height:150dp;margin-bottom:12dp;padding:26dp 18dp;border:2dp transparent;border-radius:12dp;background-color:transparent;text-align:left;}
|
||||
.front-mod-entry:hover {background-color:var(--hover);}
|
||||
.front-mod-entry.selected {border-color:var(--border);background-color:var(--selected);}
|
||||
.front-mod-copy {display:flex;flex-direction:column;gap:14dp;min-width:0;flex:1;}
|
||||
.front-mod-copy>strong {display:block;overflow:hidden;white-space:nowrap;font-size:33dp;font-weight:normal;}
|
||||
.front-mod-copy>small {display:flex;align-items:center;gap:14dp;color:var(--muted);font-size:25dp;}
|
||||
.front-mod-copy>small>span {display:block;flex-shrink:0;}
|
||||
.front-mod-type {display:block;width:170dp;text-align:center;font-size:26dp;color:var(--muted);flex-shrink:0;}
|
||||
.front-mod-empty-list {padding:24dp;font-size:29dp;color:var(--muted);line-height:1.6;}
|
||||
.front-mod-details {position:absolute;left:1196.296dp;right:0;top:0;bottom:0;padding:0 28dp 20dp;overflow-y:auto;overflow-x:hidden;}
|
||||
.front-mod-cover {position:relative;height:360dp;border:2dp var(--border);border-radius:18dp;overflow:hidden;}
|
||||
.front-mod-cover>.image-frame {position:absolute;left:0;top:0;}
|
||||
.front-mod-cover>span {position:absolute;left:40dp;bottom:40dp;font-size:69dp;font-weight:bold;letter-spacing:-3dp;color:#eef4f6;}
|
||||
.front-mod-cover>span>span {color:#b1d9cd;}
|
||||
.front-mod-details>header {display:flex;align-items:center;justify-content:space-between;gap:24dp;margin:32dp 0;}
|
||||
.front-mod-details>header>div {min-width:0;flex:1;}
|
||||
.front-mod-details header p {margin:0 0 12dp;font-size:26dp;line-height:1.4;color:var(--muted);}
|
||||
.front-mod-details h2 {font-size:43dp;font-weight:normal;margin:0;}
|
||||
.front-mod-status {display:block;flex-shrink:0;padding:12dp 18dp;border:2dp var(--border);border-radius:10dp;font-size:25dp;color:var(--muted);}
|
||||
.front-mod-status.is-active {background-color:var(--selected);color:var(--accent);}
|
||||
.front-mod-metadata {margin:32dp 0;padding:30dp 0;border-top:2dp var(--border);border-bottom:2dp var(--border);}
|
||||
.front-mod-metadata>div {display:flex;gap:18dp;margin-bottom:22dp;min-height:40dp;font-size:29dp;line-height:1.4;}
|
||||
.front-mod-metadata>div:last-child {margin-bottom:0;}
|
||||
.front-mod-metadata span {display:block;width:220dp;flex-shrink:0;color:var(--muted);}
|
||||
.front-mod-metadata strong {display:block;flex:1;min-width:0;font-weight:normal;}
|
||||
.front-mod-activation-note,.front-mod-error {font-size:27dp;line-height:1.55;color:var(--muted);margin:24dp 0;}
|
||||
.front-mod-error {color:var(--danger);}
|
||||
.front-mod-activate {width:100%;min-height:90dp;font-size:32dp;margin-top:8dp;}
|
||||
.front-mod-actions {position:absolute;left:0;right:0;bottom:0;height:140dp;}
|
||||
.front-mod-actions>p {margin:0;min-height:32dp;font-size:25dp;color:var(--muted);}
|
||||
.front-mod-actions>div {position:absolute;left:0;right:0;bottom:0;display:flex;gap:22dp;}
|
||||
.front-mod-actions button {min-width:300dp;height:86dp;font-size:30dp;}
|
||||
.front-mod-empty,.front-mod-downloads {position:absolute;left:1196.296dp;right:0;top:0;bottom:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:30dp;padding:80dp;text-align:center;color:var(--muted);}
|
||||
.front-mod-downloads {left:0;}
|
||||
.front-mod-empty h2,.front-mod-downloads h2 {font-size:47dp;font-weight:normal;margin:0;}
|
||||
.front-mod-empty p,.front-mod-downloads p {display:block;font-size:32dp;line-height:1.6;margin:0;}
|
||||
.front-mod-downloads>.image-frame {flex-shrink:0;}
|
||||
.front-mod-downloads button {margin-top:24dp;min-width:480dp;min-height:90dp;font-size:30dp;}
|
||||
.front-dialog-layer {position:absolute;left:0;right:0;top:108dp;bottom:0;z-index:30;background-color:#08101999;display:flex;align-items:center;justify-content:center;padding:70dp;}
|
||||
.front-dialog {width:1750dp;max-height:100%;overflow-y:auto;overflow-x:hidden;padding:44dp 52dp;border:2dp var(--border);border-radius:22dp;background-color:var(--strong);}
|
||||
.front-dialog h2 {margin:0 0 34dp;font-size:42dp;font-weight:normal;text-align:center;}
|
||||
.front-dialog p {margin:24dp 0;font-size:31dp;line-height:1.55;}
|
||||
.front-dialog>footer {display:flex;gap:24dp;justify-content:flex-end;margin-top:36dp;}
|
||||
.front-dialog>footer button {min-width:360dp;min-height:84dp;font-size:30dp;}
|
||||
.front-import-choices {margin-top:32dp;}
|
||||
.front-import-choices button {display:flex;flex-direction:column;align-items:flex-start;justify-content:center;gap:14dp;width:100%;padding:28dp 32dp;margin-bottom:20dp;}
|
||||
.front-import-choices strong {display:block;font-size:32dp;font-weight:normal;flex-shrink:0;}
|
||||
.front-import-choices span {display:block;font-size:26dp;color:var(--muted);flex-shrink:0;}
|
||||
.front-name-label {display:flex;flex-direction:column;gap:18dp;font-size:28dp;color:var(--muted);}
|
||||
.front-name-label>span {display:block;flex-shrink:0;}
|
||||
#front-mod-name {width:100%;padding:20dp 24dp;border:2dp var(--border);border-radius:12dp;background-color:var(--input);font-size:34dp;}
|
||||
.front-dialog .front-import-summary {padding:24dp;border:2dp var(--border);border-radius:12dp;background-color:var(--panel);font-size:29dp;}
|
||||
.front-dialog .front-import-note {font-size:27dp;color:var(--muted);}
|
||||
.front-dialog .front-name-error {min-height:44dp;margin:18dp 0 0;color:var(--danger);font-size:27dp;}
|
||||
|
||||
.brand p {letter-spacing:11dp;}
|
||||
.brand h1 {line-height:1;}
|
||||
/* Front-end library paint is intentionally Midnight in every desktop theme. */
|
||||
.front-mod-window {--text:#dce8ef;--muted:#9fb9c9;--accent:#b9dfcf;--strong:#283542fc;--panel:#12243140;--input:#152431;--hover:#bdd6dd12;--selected:#8ebfaf1f;--border:#c5d9e726;--danger:#e7b1a7;--menu-top:#303c49eb;--menu-bottom:#1a2531f2;color:#dce8ef;}
|
||||
.front-mod-window>.titlebar {background-color:#ffffff06;}
|
||||
.front-mod-tabs button.active {border-color:#b1d9cd70;background-color:#8ebfaf26;color:#c3e5d9;}
|
||||
.front-mod-entry.selected {border-color:#aacbc84d;background-color:#8ebfaf1f;}
|
||||
.front-mod-status.is-active {color:#b9dfcf;background-color:#8ebfaf1f;border-color:#b1d9cd4d;}
|
||||
.front-dialog {background-color:#283542fc;color:#dce8ef;border-color:#e1ecf429;}
|
||||
.front-import-choices button {height:142dp;min-height:142dp;flex-shrink:0;}
|
||||
.front-import-choices button:last-child {margin-bottom:0;}
|
||||
.front-mod-downloads button {flex-shrink:0;}
|
||||
@@ -0,0 +1,2 @@
|
||||
<!-- SPDX-License-Identifier: GPL-3.0-only -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 80" fill="none" stroke="#dceae7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 53a16 16 0 0 1-1-32 23 23 0 0 1 44 2 15 15 0 0 1-2 30M40 35v35m-12-12 12 12 12-12"/></svg>
|
||||
|
After Width: | Height: | Size: 304 B |
@@ -1,6 +1,6 @@
|
||||
<rml>
|
||||
<head><title>OpenBMH</title><link type="text/rcss" href="theme.rcss"/><link type="text/rcss" href="ticket.rcss"/><link type="text/rcss" href="sports.rcss"/><link type="text/rcss" href="calendar.rcss"/><link type="text/rcss" href="reports.rcss"/><link type="text/rcss" href="report_details.rcss"/><link type="text/rcss" href="report_pickers.rcss"/><link type="text/rcss" href="indoor.rcss"/><link type="text/rcss" href="planning.rcss"/><link type="text/rcss" href="almanac.rcss"/><link type="text/rcss" href="finance.rcss"/>
|
||||
<link type="text/rcss" href="bank.rcss"/><link type="text/rcss" href="contracts.rcss"/><link type="text/rcss" href="amount.rcss"/><link type="text/rcss" href="environment.rcss"/><link type="text/rcss" href="advertising.rcss"/><link type="text/rcss" href="toto.rcss"/><link type="text/rcss" href="lineup.rcss"/><link type="text/rcss" href="transfer.rcss"/><link type="text/rcss" href="career_reports.rcss"/><link type="text/rcss" href="rankings.rcss"/><link type="text/rcss" href="stadium.rcss"/><link type="text/rcss" href="statistics.rcss"/><link type="text/rcss" href="news.rcss"/><link type="text/rcss" href="settings.rcss"/><link type="text/rcss" href="widgets.rcss"/><link type="text/rcss" href="files.rcss"/></head>
|
||||
<link type="text/rcss" href="bank.rcss"/><link type="text/rcss" href="contracts.rcss"/><link type="text/rcss" href="amount.rcss"/><link type="text/rcss" href="environment.rcss"/><link type="text/rcss" href="advertising.rcss"/><link type="text/rcss" href="toto.rcss"/><link type="text/rcss" href="lineup.rcss"/><link type="text/rcss" href="transfer.rcss"/><link type="text/rcss" href="career_reports.rcss"/><link type="text/rcss" href="rankings.rcss"/><link type="text/rcss" href="stadium.rcss"/><link type="text/rcss" href="statistics.rcss"/><link type="text/rcss" href="news.rcss"/><link type="text/rcss" href="settings.rcss"/><link type="text/rcss" href="widgets.rcss"/><link type="text/rcss" href="files.rcss"/><link type="text/rcss" href="front.rcss"/></head>
|
||||
<body class="midnight">
|
||||
<div id="background"></div>
|
||||
<div id="canvas"></div>
|
||||
|
||||
@@ -14,7 +14,10 @@ wird ausdrücklich mit `OPENBMH_BUILD_MODERN_UI=ON` gebaut.
|
||||
- Eigene GUI-Ressourcen für Hintergründe, Desktop-Icons, Managerporträts,
|
||||
Karten und Trainingslagerbilder. Der Vorbereitungsbefehl verändert weder
|
||||
das Mockup noch die Weltdatei.
|
||||
- Hauptmenü und Mod-Auswahl; Grundeinstellungen mit vier großen Auswahlfeldern;
|
||||
- [Hauptmenü und Mod-Verwaltung](main-menu/README.md): zwei Tabs, Paketdetails,
|
||||
explizite dauerhaft gespeicherte Aktivierung und bestätigte Dateioperationen.
|
||||
Import von Originalordner, OBW/ZIP und Exportordner mit Prüfung/Namensentwurf,
|
||||
asynchroner Übernahme und getrennten Nutzerdaten. Grundeinstellungen mit vier großen Auswahlfeldern;
|
||||
Manager-/Vereinswahl mit Foto- und Illustrationsporträts. Ausländische
|
||||
Vereine bleiben sichtbar und sind für Manager gesperrt.
|
||||
- Drei Teilnehmerseiten, automatische Demo-Auslosung mit Pause/Überspringen
|
||||
@@ -138,7 +141,7 @@ vom HTML-Mockup übertragen. Für fehlende Ports erscheinen keine vereinfachten
|
||||
Ersatzlayouts. Der Katalog zählt jetzt 34 native und drei noch nicht separat
|
||||
zugeordnete Routen; diese Zahl bestätigt keine vollständige gestalterische
|
||||
Abnahme aller früheren Teilimplementierungen.
|
||||
Der Mod-Importkomfort ist noch nicht vollständig. Bildschirmkonfiguration und Audioausgabe benötigen noch die
|
||||
Bildschirmkonfiguration und Audioausgabe benötigen noch die
|
||||
Plattform-/Engine-Anbindung der nun gespeicherten UI-Voreinstellungen. Übersetzungen, echte Engine-Anbindung und Plattform-Abnahme
|
||||
unter Windows/macOS folgen später. Dies ist kein freigegebenes Test-Release.
|
||||
Die [QA-Befundliste](qa-findings.md) hält die noch offenen Abweichungen nach.
|
||||
|
||||
@@ -13,6 +13,7 @@ Implementierung in der Spiel-Engine.
|
||||
| Menü-QA | [Wiederholbarer Gesamtkatalog und Meilenstein-Abnahme](menu-qa.md) |
|
||||
| QA-Befunde | [Offene Abweichungen zur HTML-Referenz](qa-findings.md) |
|
||||
| Ressourcen | [GUI-Assets, Weltbilder und spätere Paketbereinigung](assets.md) |
|
||||
| Hauptmenü & Mods | [Bibliothek, Import und explizite Aktivierung](main-menu/README.md) |
|
||||
| Desktop | [Statusleiste, Gestaltung und Fenster](desktop/README.md) |
|
||||
| Widgets | [17 Typen, 48 Größen, Raster, Fixierung und Arbeitsanordnung](desktop/widgets/README.md) |
|
||||
| Dateiverwaltung | [Spielstände und Desktopansichten mit Vorschauen](desktop/save-load/README.md) |
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
<!-- SPDX-License-Identifier: GPL-3.0-only -->
|
||||
# Hauptmenü und lokale Mod-Bibliothek
|
||||
|
||||
Dieser Backendvertrag gehört zur nativen Modern-UI-Umsetzung auf Basis
|
||||
`ab4a962`. Schreibgeschützte Gestaltungsreferenz sind `desktop/mod-library.js`
|
||||
und `desktop/main-menu.js` im privaten HTML-Goldstand, Revision
|
||||
`97c19979f10f190a87bbb93a06df397a8d3dae89`. Proprietäre Inhalte werden nicht in
|
||||
dieses Repository übernommen. Das Hauptmenü wählt eine Mod für das nächste
|
||||
Spiel aus; die Aktivierung erzeugt keine Karriere und verändert keine Engine.
|
||||
|
||||
## Ablage und Schnittstelle
|
||||
|
||||
`UiModLibrary(portable_root)` verwendet `portable_root/mods/<name>/content.obw`
|
||||
und optional `mod.json`. Der Root-Parameter ist ausdrücklich die portable
|
||||
Basis, nicht das Verzeichnis `mods` selbst. `--ui-mods` kann diese Basis für
|
||||
isolierte Tests überschreiben. Neu installierte Modern-Mods besitzen ein Profil mit
|
||||
Schema `openbmh-mod@1.0`. Classic-Mods bleiben für den vorhandenen 0.2-Launcher
|
||||
streng `content.obw`-only; auch bestehende solche Verzeichnisse bleiben lesbar. `UiModEntry.path` bezeichnet immer den
|
||||
Mod-Ordner, nicht die Paketdatei.
|
||||
|
||||
Die öffentliche API steht in `src/modern/ui/mod_library.hpp`:
|
||||
|
||||
- `snapshot()` liefert Einträge, eine optionale aktive Verzeichnis-ID,
|
||||
Auswahl-Token und Bibliotheksfehler. Beschädigte Einträge bleiben als
|
||||
Fehlerzeilen erhalten. Eine beschädigte Profilbeschreibung verhindert keine
|
||||
sichere Entfernung des eigenen Datensatzes. Fremde oder nicht normalisierbare
|
||||
Namen blockieren nicht pauschal neue Importe.
|
||||
- `inspect(source,start_year)` liefert einen `ModImportPlan` mit geprüftem
|
||||
Namensvorschlag und Metadaten. Es wird noch keine Mod installiert, keine
|
||||
Bibliotheksauswahl geändert und kein echtes Nutzerverzeichnis angelegt.
|
||||
- `commit(plan,name,progress)` veröffentlicht erst nach erneuter Quellprüfung
|
||||
ein vollständig vorbereitetes Verzeichnis. Öffentliche Plan-Metadaten dienen
|
||||
der Anzeige; maßgeblich bleibt der private unveränderliche geprüfte Plan.
|
||||
- `activate`, `deactivate`, `rename` und `remove` verlangen sowohl die konkrete
|
||||
Bibliotheksmitgliedschaft als auch aktuelle Datei- und Auswahl-Token.
|
||||
|
||||
Inspektion und Commit enthalten keine SDL-/RmlUI-Aufrufe. Die Oberfläche darf
|
||||
sie in einem Hintergrundauftrag ausführen und währenddessen weitere
|
||||
Mutationen sperren. Der optionale Fortschrittscallback liefert nur Text und
|
||||
muss durch den UI-Besitzer sicher an dessen Hauptthread weitergereicht werden.
|
||||
Ein explizites externes `--mod` ist ein vorübergehender Startoverride und wird
|
||||
nicht als Bibliotheksmitglied oder persistierte Aktivierung ausgegeben.
|
||||
|
||||
## Metadaten und unterstützte Quellen
|
||||
|
||||
Die Detaildaten sind `type`, `source`, `version`, `file_count`, `bytes` und
|
||||
`description`. Art und Herkunft folgen den tatsächlich validierten Inhalten.
|
||||
Ein importiertes `mod.json` darf Classic und Modern nicht gegeneinander
|
||||
umdeklarieren. Die Dateianzahl und Bytes zählen die geprüften, entpackten
|
||||
Paketinhalte; vor einer Originalkonvertierung beschreibt der Plan die
|
||||
Originalquellensammlung. Interne Bibliotheksprofile gehören nicht zu dieser
|
||||
Inhaltszahl.
|
||||
|
||||
Unterstützt werden OBW-/ZIP-Weltpakete mit einer Manifestdatei an der
|
||||
Archivwurzel, entpackte Weltverzeichnisse und Mod-Verzeichnisse mit
|
||||
`content.obw`. Der vorhandene `editor::ArchiveStore` prüft sichere Pfade,
|
||||
Grenzen und komprimierte Einträge. Alle Payload-Einträge werden gelesen und
|
||||
gehasht, nicht lediglich die Manifestdatei. Modern-Inhalte müssen durch den
|
||||
vorhandenen `Catalog` lesbar sein und bekannte UI-Weltanforderungen erfüllen.
|
||||
Unbekannte Profile oder eine Welt ohne von der UI-Demo unterstützten Verein
|
||||
werden ausdrücklich zurückgewiesen. Das ist keine Zusage einer vollständigen
|
||||
Modern-Engine-Ausführung.
|
||||
|
||||
Classic wird ausschließlich nach erfolgreichem `content::open` klassifiziert:
|
||||
Das vorhandene Siegel, die exakten Inhaltshashes, der Classic-Adapter und die
|
||||
unterstützte Ligastruktur bleiben verbindlich. Herkunft ist bei geprüften
|
||||
deutschen Inhalten `BMH`, bei Football Limited `FTLD`; letzteres ist das
|
||||
historische UI-Kürzel, während die echte Originaldatei `FLTD.EXE` heißt.
|
||||
|
||||
Originalordner und explizit gewählte `BMH.EXE`/`FLTD.EXE` werden mit
|
||||
`launch::check_game_directory` geprüft. Nicht unterstützte Disketteneditionen,
|
||||
unvollständige und mehrdeutige Installationen ergeben konkrete Fehler.
|
||||
Die eigentliche Konvertierung verwendet unverändert
|
||||
`launch::ModLibrary::add`/`AddMod` in einer isolierten temporären Bibliothek,
|
||||
mit `migrate=false`. Nutzerspielstände, Einstellungen und Desktopdateien werden
|
||||
nicht migriert. Nach vollständiger Prüfung wird nur das resultierende
|
||||
`content.obw` in die echte Mod-Bibliothek übernommen.
|
||||
|
||||
Eine Quelle darf höchstens 512 MiB und 12.000 Dateien umfassen; die bestehenden
|
||||
strengeren Classic- und ArchiveStore-Grenzen gelten zusätzlich. Quell- und
|
||||
Mitgliedschaftstoken werden blockweise gebildet, damit ein großes Paket nicht
|
||||
als zusätzliche vollständige Kopie im RAM gehalten werden muss. Temporäre
|
||||
ArchiveStore-Snapshots und Konvertierungsordner werden beim Verwerfen des
|
||||
Plans beziehungsweise nach dem Vorgang entfernt. Eine ungefähr 1,6-GiB große
|
||||
Season-Sammlung liegt außerhalb dieses Bibliotheksimports und wird nicht
|
||||
stillschweigend als unterstütztes Ligaset übernommen.
|
||||
|
||||
## Auswahl und Transaktionen
|
||||
|
||||
Ohne gespeicherte Auswahl ist keine Mod aktiviert. Import aktiviert niemals
|
||||
automatisch den ersten oder zuletzt importierten Eintrag. Eine explizite
|
||||
Auswahl steht atomar in `.ui-active-mod.json`; ihr Wert ist entweder genau
|
||||
eine existierende gültige Verzeichnis-ID oder `null`. Fehlt eine referenzierte
|
||||
Mod oder ist sie beschädigt, meldet `snapshot()` den Fehler und zeigt keine
|
||||
falsche aktive Mod. Ein Neustart wählt keinen Ersatz aus.
|
||||
|
||||
Neue Namen besitzen höchstens 64 Unicode-Zeichen und 240 UTF-8-Bytes. Die
|
||||
Vergleichsregeln übernehmen die portable deutsche Casefold-Hilfe der
|
||||
Dateiverwaltung einschließlich Ö/ö, ß und zerlegter lateinischer Akzente.
|
||||
Zusätzlich gelten portable Dateinamensregeln: keine Schrägstriche, Doppelpunkte
|
||||
oder anderen Windows-Sonderzeichen, keine versteckten Namen, kein abschließender
|
||||
Punkt und keine reservierten Gerätenamen. Bestehende gültige 0.2-Namen bis
|
||||
100 ASCII-Zeichen bleiben lesbar und können auf einen neuen kürzeren Namen
|
||||
umbenannt werden. Die dokumentierte Unicode-Normalisierungsgrenze des
|
||||
Dateianbieters bleibt bestehen.
|
||||
|
||||
Installieren veröffentlicht einen fertig geprüften Staging-Ordner mit einer
|
||||
einzigen abschließenden Umbenennung. Für Rename/Delete werden der Ordnerwechsel
|
||||
und die aktive Namensreferenz durch ein kleines Journal mit Auswahl-Nonce
|
||||
verbunden. Ein Fehler vor dem Auswahl-Commit stellt die bisherige Anordnung
|
||||
wieder her. Nach dem Commit wird ausschließlich aufgeräumt. Auch reine
|
||||
Groß-/Kleinschreibungsänderungen verwenden einen temporären Zwischennamen,
|
||||
damit das Verhalten auf Windows nicht vom Umbenennen auf denselben Pfad
|
||||
abhängt. Ein liegen gebliebenes Journal wird vor dem nächsten Bibliothekszugriff
|
||||
geprüft und soweit eindeutig wiederhergestellt. Unerwartete externe Änderungen
|
||||
führen zu einer ausdrücklichen Prüfmeldung; unbekannte Daten werden dabei
|
||||
nicht gelöscht.
|
||||
|
||||
Der eigene temporäre Schreib-Lock verhindert konkurrierende Anbietertransaktionen.
|
||||
Ein nach einem Prozessabsturz verbliebener Lock wird nicht ungeprüft entfernt.
|
||||
Symlinks innerhalb der verwalteten Mod-Struktur und verknüpfte Quellen werden
|
||||
zurückgewiesen. Die vertrauenswürdige portable Basis wird kanonisiert, damit
|
||||
gewöhnliche Betriebssystem-Basisaliase funktionieren. `userdata` hat einen
|
||||
unabhängigen Lebenszyklus und bleibt bei Mod-Rename und Mod-Delete erhalten.
|
||||
|
||||
## Prüfung
|
||||
|
||||
`tests/modern_mods_ui_tests.cpp` verwendet ausschließlich temporäre synthetische
|
||||
Welten und den bereits öffentlichen künstlichen Classic-Testgenerator. Es
|
||||
prüft Modern-/versiegelte Classic-Metadaten, 0/1-Auswahl über Neustarts,
|
||||
Namenskonflikte, Mitgliedschaft, alte 0.2-Ordner, fehlerhafte Profile, geänderte
|
||||
Quellen, Staging-Abbruch, IO-/Lock-Fehler, Symlinks und erhaltene Nutzerdaten.
|
||||
Originalkonvertierungen mit tatsächlich proprietären Installationen gehören
|
||||
ausschließlich in die private QA. Die Testquelle allein belegt weder einen
|
||||
ausgeführten Build noch natives Plattformverhalten.
|
||||
|
||||
## Native Oberfläche und Bedienung
|
||||
|
||||
Der native RmlUI-Client übernimmt das Hauptmenü mit sechs großen Textaktionen,
|
||||
Hover-/Fokuspfeil und zurückhaltender Versionsanzeige. Ohne aktive Mod bleibt
|
||||
Neues Spiel gesperrt. Das Netzwerk ist ein sichtbarer Platzhalter; Downloads
|
||||
führt in den zweiten Mod-Tab mit angekündigtem, gesperrtem Datenbankzugang.
|
||||
|
||||
Die Bibliothek zeigt die tatsächlich installierten Classic-/Modern-Pakete und
|
||||
ihre geprüften Metadaten. Auswahl aktiviert noch nichts. Aktivierung bleibt
|
||||
explizit und wird über Neustarts erhalten. Umbenennen und Löschen verwenden
|
||||
lokale Bestätigungen; beim Löschen der aktiven Mod gibt es keine automatische
|
||||
Ersatzwahl. Nutzerdateien bleiben getrennt erhalten.
|
||||
|
||||
Der Import bietet Originalordner, Paketdatei und Export-/Modordner. Nach
|
||||
Dateiauswahl folgt die asynchrone Prüfung, danach ein editierbarer Namensentwurf.
|
||||
Erst Importieren veröffentlicht das Paket. Auswahlabbruch und verworfene
|
||||
Namensentwürfe ändern die Bibliothek nicht. Während laufender Prüfung oder
|
||||
Übernahme sperrt der Client weitere Mutationen, Escape und Schließen; ein
|
||||
in-flight Abbruch wird nicht angeboten. Der vorhandene Classic-Konverter wird
|
||||
wiederverwendet und verändert keine Originaldateien. Inspektion, Konvertierung
|
||||
und Veröffentlichung laufen ohne SDL-/RmlUI-Zugriffe im Worker.
|
||||
|
||||
`--ui-mods <portable Basis>` isoliert eine Bibliothek mit ihrem Unterordner
|
||||
`mods/`; `--ui-mod-import <Quelle>` ersetzt ausschließlich die explizite
|
||||
OS-Dateiauswahl für QA. Das JSONL-Skript wartet mit `front-wait` auf denselben
|
||||
normalen Abschlussweg wie die interaktive Anwendung. Es injiziert keine
|
||||
Bibliothekszustände.
|
||||
|
||||
Ein explizites `--mod` ist eine temporäre externe Welt und wird nicht als
|
||||
installierte oder dauerhaft aktivierte Mod dargestellt. Neues Spiel einer
|
||||
Classic-Mod startet weiter den vorhandenen Classic-Client; die zugehörige
|
||||
Spielstandauswahl bleibt ebenfalls dort. Modern verwendet weiterhin den
|
||||
getrennten UI-Datenanbieter. Die echte Engine wird nicht geändert und Anstoß
|
||||
bleibt ohne Aktion. Die eigentliche Bildschirm-/Audioanbindung und das größere
|
||||
Stadionperipherie-Redesign gehören nicht zu diesem Paket.
|
||||
|
||||
Private Vorher-/Nachherbilder, UI-Zustände, synthetische Importfixtures und
|
||||
Eingabeskripte liegen in
|
||||
`bmh_4k_ui/docs/qa/front-mods-batch-2026-10-26/`. Gold enthält eine fiktive
|
||||
mitgelieferte Beispielmod; die native frische Liste bleibt wegen der getrennten
|
||||
Nutzerdaten leer. Gold sammelt Originalbytes nur lokal für den POC, während der
|
||||
native Client den bestehenden tatsächlichen Converter verwendet. Das ist eine
|
||||
ausdrückliche Datenstrecken-Abgrenzung, keine Behauptung identischer Engine-
|
||||
funktionalität.
|
||||
|
||||
## Prüfung
|
||||
|
||||
Die lokale Meilenstein-Suite umfasst 35 bestandene Tests. Synthetische
|
||||
Referenzpakete lassen sich reproduzierbar über
|
||||
`modern_mods_ui_tests --write-fixtures <leeres Verzeichnis>` erzeugen; dabei
|
||||
wird keine Engine gestartet. Der unabhängige UI-Lauf besteht auf seiner
|
||||
zugeordneten Runtime 132 Prüfungen in neun Prozessen (darunter zwei Neustarts).
|
||||
Die neue Kompatibilitäts-/Coverkohorte wird getrennt dokumentiert. Native
|
||||
Bild- und Bedienungstests laufen unter Linux/OpenGL; die Plattform-CI baut
|
||||
und prüft synthetisch, ersetzt aber keine Windows-/macOS-Spielabnahme.
|
||||
@@ -235,3 +235,27 @@ bleiben UI-Demodaten. Die vertieften Dateitests enthalten tatsächliche
|
||||
GUI-Eingaben und externe Änderungen eigener QA-Dateien zwischen Auswahl und
|
||||
Bestätigung; es werden keine Produktzustände in den laufenden Prozess injiziert.
|
||||
Separate Runtimekohorten bewahren ihre ursprünglichen Fingerprints.
|
||||
|
||||
|
||||
Das Einstiegspaket ergänzt Hauptmenü und Mod-Bibliothek mit zwei Tabs,
|
||||
Metadaten, drei Importentscheidungen, Namensprüfung, expliziter Aktivierung und
|
||||
Neustartpersistenz. Der private Goldlauf besteht 82/82 Prüfungen; die begrenzte
|
||||
native Modern-Bedienung samt zwei Neustarts besteht 78/78. Beim Vergleich der
|
||||
Importdaten zählen entpackte Dateihashes; ein neu gepackter ZIP-Container darf
|
||||
sich byteweise unterscheiden. Der ältere gegenteilige Harnessbefund bleibt
|
||||
als korrigierte Prüferwartung erhalten.
|
||||
|
||||
Die sechs nativen Bildfälle dokumentieren drei Themes bei 720p und 1080p.
|
||||
Frontfenster bleiben wie Gold bewusst dunkel, während Desktop-/Untermenüthemes
|
||||
ihre eigenen Paletten behalten. Quellen und alte UI-Demostände werden nicht
|
||||
verändert. Proprietäre Referenzen und Importbelege liegen nur privat unter
|
||||
`bmh_4k_ui/docs/qa/front-mods-batch-2026-10-26/`.
|
||||
|
||||
Die lokale Suite besteht nach dem Einstiegspaket **35/35 Tests**. Der neue
|
||||
Bibliothekstest verwendet vollständig synthetische Modern- und versiegelte
|
||||
Classic-DE/EN-Pakete und prüft Aktivierung, Namenskonflikte, Auswahl-CAS,
|
||||
Quelländerungen, Rollback und unveränderte Nutzerdaten. Classic-Importe werden
|
||||
zusätzlich vom vorhandenen 0.2-Launcher erkannt. Die Schriftprobe kontrolliert
|
||||
auch den Hauptmenütext und Modnamen bei vier Dichten in drei Themes.
|
||||
Ein schmaler Streifen rechts vom Cover wurde im finalen Link durch korrekte
|
||||
Coverbreite geschlossen; frühere Kohorten behalten ihre tatsächlichen Bilder.
|
||||
@@ -112,3 +112,13 @@ inert. Kontextmenüs verwenden ihre Borderbox zur Randbegrenzung und zeigen
|
||||
Fixierungs-/Rasterzustände. Exporte dürfen keine verwalteten Slots ersetzen.
|
||||
Die native Ansichts-/Arbeitsablage bleibt bewusst weltbezogen, während Gold
|
||||
browserglobal speichert; diese Abgrenzung ist in der Dateiverwaltung dokumentiert.
|
||||
|
||||
|
||||
Im Einstiegspaket korrigiert: die nur teilweise native Modseite, fehlende
|
||||
Downloads-/Importauswahl, die automatisch gesetzte erste Mod und verlorene
|
||||
Neustartauswahl. Import veröffentlicht erst nach Bestätigung und erneuter
|
||||
Quellprüfung. Classic bleibt content-only und wird vom vorhandenen 0.2-Launcher
|
||||
weiter erkannt. Frontfarben folgen in allen Desktopthemes dem dunklen Gold;
|
||||
fast opaker Importdialog und nicht schrumpfender Downloadsbutton beheben die
|
||||
geprüften Farb-/Textabweichungen. Das Hauptmenü zeigt den Fokus-/Hoverpfeil und
|
||||
die korrekten Text-/Fenstermaße.
|
||||
@@ -140,6 +140,10 @@ int main(int argc, char** argv) {
|
||||
modern_config.file_import = launch::path_from_utf8(args[++i]);
|
||||
} else if (is("--ui-file-export") && value) {
|
||||
modern_config.file_export = launch::path_from_utf8(args[++i]);
|
||||
} else if (is("--ui-mods") && value) {
|
||||
modern_config.mods = launch::path_from_utf8(args[++i]);
|
||||
} else if (is("--ui-mod-import") && value) {
|
||||
modern_config.mod_import = launch::path_from_utf8(args[++i]);
|
||||
} else if (is("--ui-size") && value) {
|
||||
const auto size = args[++i];
|
||||
const auto separator = size.find('x');
|
||||
|
||||
@@ -2,8 +2,20 @@
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp model.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp)
|
||||
target_include_directories(bmh_modern_ui_core PUBLIC ../..)
|
||||
target_link_libraries(bmh_modern_ui_core PUBLIC bmh_asset_io)
|
||||
add_library(bmh_modern_ui_mods STATIC mod_library.cpp)
|
||||
target_link_libraries(bmh_modern_ui_mods PUBLIC bmh_modern_ui_core bmh_launcher)
|
||||
add_executable(modern_mods_ui_tests ../../../tests/modern_mods_ui_tests.cpp)
|
||||
target_link_libraries(modern_mods_ui_tests PRIVATE bmh_modern_ui_mods)
|
||||
if(MSVC)
|
||||
target_compile_options(bmh_modern_ui_mods PRIVATE /W4 /utf-8)
|
||||
target_compile_options(modern_mods_ui_tests PRIVATE /W4 /utf-8)
|
||||
else()
|
||||
target_compile_options(bmh_modern_ui_mods PRIVATE -Wall -Wextra -Wpedantic)
|
||||
endif()
|
||||
add_test(NAME modern_mods_ui_tests COMMAND modern_mods_ui_tests)
|
||||
find_package(Threads REQUIRED)
|
||||
add_library(bmh_modern_ui STATIC view.cpp ticket_popover.cpp)
|
||||
target_link_libraries(bmh_modern_ui PUBLIC bmh_modern_ui_core PRIVATE bmh_rmlui bmh_launcher nfd::nfd ${BMH_SDL_TARGET})
|
||||
target_link_libraries(bmh_modern_ui PUBLIC bmh_modern_ui_core PRIVATE Threads::Threads bmh_modern_ui_mods bmh_rmlui bmh_launcher nfd::nfd ${BMH_SDL_TARGET})
|
||||
if(MSVC)
|
||||
target_compile_options(bmh_modern_ui_core PRIVATE /W4 /utf-8)
|
||||
target_compile_options(bmh_modern_ui PRIVATE /W4 /utf-8 /bigobj)
|
||||
@@ -14,7 +26,7 @@ endif()
|
||||
set(modern_assets "${CMAKE_BINARY_DIR}/assets/modern")
|
||||
FetchContent_GetProperties(rmlui)
|
||||
file(MAKE_DIRECTORY "${modern_assets}")
|
||||
foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss reports.rcss report_details.rcss report_pickers.rcss indoor.rcss planning.rcss almanac.rcss finance.rcss bank.rcss contracts.rcss amount.rcss environment.rcss advertising.rcss toto.rcss lineup.rcss transfer.rcss career_reports.rcss rankings.rcss stadium.rcss statistics.rcss news.rcss settings.rcss widgets.rcss files.rcss)
|
||||
foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss reports.rcss report_details.rcss report_pickers.rcss indoor.rcss planning.rcss almanac.rcss finance.rcss bank.rcss contracts.rcss amount.rcss environment.rcss advertising.rcss toto.rcss lineup.rcss transfer.rcss career_reports.rcss rankings.rcss stadium.rcss statistics.rcss news.rcss settings.rcss widgets.rcss files.rcss front.rcss)
|
||||
configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY)
|
||||
endforeach()
|
||||
|
||||
|
||||
+12
-141
@@ -145,6 +145,7 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
n = n->GetParentNode())
|
||||
if (n->GetId() == "native-ticket-layer")
|
||||
return;
|
||||
if(front_event(event))return;
|
||||
if (amount_event(event)) return;
|
||||
if (popup_.empty() && settings_event(event)) return;
|
||||
if (popup_.empty() && (files_event(event) || widget_event(event))) return;
|
||||
@@ -457,6 +458,7 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
const auto id =
|
||||
target ? target->GetAttribute<Rml::String>("data-id", "") : std::string();
|
||||
if(front_action(action,target))return;
|
||||
if (settings_action(action,target)) return;
|
||||
if (files_action(action,target) || widget_action(action,target)) return;
|
||||
if (lineup_action(action, target) || transfer_action(action, target)) return;
|
||||
@@ -618,6 +620,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
return;
|
||||
}
|
||||
if (action == "load") {
|
||||
if(auto *active=mod(active_mod_);active&&active->type=="Modern"&&(!world_||world_->source()!=fs::absolute(active->file).lexically_normal()))load_world(active->file);
|
||||
if (!source_) {
|
||||
if (auto *m = mod(active_mod_); m && m->type == "Modern")
|
||||
load_world(m->file);
|
||||
@@ -639,7 +642,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
contents->content_id,
|
||||
{},
|
||||
m->file.parent_path()};
|
||||
launch::ModLibrary library(root_);
|
||||
launch::ModLibrary library(front_library_root());
|
||||
const auto user = library.user_directory(entry);
|
||||
SDL_HideWindow(video_.window);
|
||||
const int code =
|
||||
@@ -674,142 +677,6 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "mod-select") {
|
||||
selected_mod_ = id;
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "mod-activate") {
|
||||
if (auto *m = mod(selected_mod_)) {
|
||||
if (!m->error.empty()) {
|
||||
message(m->error);
|
||||
return;
|
||||
}
|
||||
active_mod_ = m->name;
|
||||
}
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "mod-remove") {
|
||||
if (auto *m = mod(selected_mod_)) {
|
||||
const auto name = m->name;
|
||||
confirmation(
|
||||
"Mod „" + name + "“ löschen? Persönliche Daten bleiben erhalten.",
|
||||
[this, name] {
|
||||
auto *m = mod(name);
|
||||
if (!m)
|
||||
return;
|
||||
launch::ModLibrary library(root_);
|
||||
library.remove({m->name, m->type, {}, {}, m->file.parent_path()});
|
||||
if (active_mod_ == name)
|
||||
active_mod_.clear();
|
||||
selected_mod_.clear();
|
||||
collect_mods();
|
||||
refresh();
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (action == "mod-rename") {
|
||||
auto *m = mod(selected_mod_);
|
||||
if (!m)
|
||||
return;
|
||||
const auto previous = m->name;
|
||||
text_dialog("Mod umbenennen", previous,
|
||||
[this, previous](const std::string &name) {
|
||||
launch::ModLibrary::validate_name(name);
|
||||
auto *m = mod(previous);
|
||||
if (!m)
|
||||
throw editor::Error("Mod ist nicht mehr vorhanden.");
|
||||
launch::ModLibrary library(root_);
|
||||
library.rename(
|
||||
{m->name, m->type, {}, {}, m->file.parent_path()}, name);
|
||||
if (active_mod_ == previous)
|
||||
active_mod_ = name;
|
||||
selected_mod_ = name;
|
||||
collect_mods();
|
||||
refresh();
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (action == "import-modern") {
|
||||
NFD::Guard guard;
|
||||
NFD::UniquePath chosen;
|
||||
const nfdfilteritem_t filter[] = {{"OpenBMH-Welt", "obw"}};
|
||||
const auto result = NFD::OpenDialog(chosen, filter, 1);
|
||||
if (result == NFD_CANCEL)
|
||||
return;
|
||||
if (result != NFD_OKAY) {
|
||||
message("Die Dateiauswahl konnte nicht geöffnet werden.");
|
||||
return;
|
||||
}
|
||||
const auto file = editor::path(chosen.get());
|
||||
auto candidate = Catalog::open(file);
|
||||
auto initial = candidate->title();
|
||||
for (char &c : initial)
|
||||
if (std::string("/\\:*?\"<>|").find(c) != std::string::npos)
|
||||
c = '-';
|
||||
if (initial.empty())
|
||||
initial = "Modern";
|
||||
text_dialog("Bezeichnung der neuen Mod", initial,
|
||||
[this, file](const std::string &name) {
|
||||
launch::ModLibrary::validate_name(name);
|
||||
const auto destination = root_ / "mods" / editor::path(name);
|
||||
if (fs::exists(destination))
|
||||
throw editor::Error(
|
||||
"Eine Mod mit diesem Namen ist bereits vorhanden.");
|
||||
fs::create_directories(destination.parent_path());
|
||||
const auto staging =
|
||||
destination.parent_path() /
|
||||
(".ui-import-" + std::to_string(SDL_GetTicks64()));
|
||||
if (!fs::create_directory(staging))
|
||||
throw editor::Error("Import wird bereits vorbereitet.");
|
||||
try {
|
||||
fs::copy_file(file, staging / "content.obw");
|
||||
(void)Catalog::open(staging / "content.obw");
|
||||
fs::rename(staging, destination);
|
||||
} catch (...) {
|
||||
fs::remove_all(staging);
|
||||
throw;
|
||||
}
|
||||
collect_mods();
|
||||
selected_mod_ = name;
|
||||
refresh();
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (action == "import-classic") {
|
||||
NFD::Guard guard;
|
||||
NFD::UniquePath chosen;
|
||||
const auto result = NFD::PickFolder(chosen);
|
||||
if (result == NFD_CANCEL)
|
||||
return;
|
||||
if (result != NFD_OKAY) {
|
||||
message("Die Ordnerauswahl konnte nicht geöffnet werden.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
launch::AddMod request;
|
||||
request.source = editor::path(chosen.get());
|
||||
const auto game = launch::check_game_directory(request.source);
|
||||
request.name = game.family == launch::GameFamily::english ? "FTDL-classic"
|
||||
: "BMH-classic";
|
||||
request.migrate = false;
|
||||
text_dialog("Bezeichnung der neuen Mod", request.name,
|
||||
[this, request](const std::string &name) mutable {
|
||||
launch::ModLibrary::validate_name(name);
|
||||
request.name = name;
|
||||
launch::ModLibrary library(root_);
|
||||
library.add(request, migrate_);
|
||||
collect_mods();
|
||||
selected_mod_ = name;
|
||||
refresh();
|
||||
});
|
||||
} catch (const std::exception &e) {
|
||||
message(e.what());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (action == "setup-step") {
|
||||
const auto step = target->GetAttribute<int>("data-step", 0);
|
||||
const int limit = id == "duration" ? 5
|
||||
@@ -1082,7 +949,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
}
|
||||
}
|
||||
void App::change(Rml::Element *target) {
|
||||
if(files_change(target) || widget_change(target) || settings_change(target))return;
|
||||
if(front_change(target)||files_change(target) || widget_change(target) || settings_change(target))return;
|
||||
const auto kind = target->GetAttribute<Rml::String>("data-change", "");
|
||||
auto *control = dynamic_cast<Rml::ElementFormControl *>(target);
|
||||
if (!control)
|
||||
@@ -1146,7 +1013,7 @@ void App::change(Rml::Element *target) {
|
||||
}
|
||||
}
|
||||
void App::input(Rml::Element *target) {
|
||||
if(files_change(target) || widget_change(target) || settings_change(target))return;
|
||||
if(front_change(target)||files_change(target) || widget_change(target) || settings_change(target))return;
|
||||
const auto kind = target->GetAttribute<Rml::String>("data-input", "");
|
||||
auto *control = dynamic_cast<Rml::ElementFormControl *>(target);
|
||||
if (!control)
|
||||
@@ -1211,7 +1078,11 @@ void App::script() {
|
||||
try {
|
||||
const auto command = Json::parse(line);
|
||||
const auto type = command.value("type", std::string());
|
||||
if (type == "click" || type == "right") {
|
||||
if(type=="front-wait"){
|
||||
const auto end=SDL_GetTicks64()+command.value("timeout_ms",uint64_t(300000));
|
||||
while(front_busy_&&SDL_GetTicks64()<end){front_poll();if(needs_render_||dirty_)frame();SDL_Delay(10);}
|
||||
if(front_busy_)throw editor::Error("Modvorgang hat das QA-Zeitlimit überschritten.");
|
||||
} else if (type == "click" || type == "right") {
|
||||
const auto point = locate(command);
|
||||
const int button = type == "right" ? 1 : 0;
|
||||
context_->ProcessMouseMove(point.x, point.y, 0);
|
||||
@@ -1274,7 +1145,7 @@ void App::script() {
|
||||
{"transfer_view", transfer_view_}, {"transfer_dialog", transfer_dialog_}, {"transfer_draft", transfer_draft_},
|
||||
{"career_view", career_view_}, {"rankings_view", rankings_view_},
|
||||
{"stadium_view", stadium_view_},
|
||||
{"files_view",{{"mode",files_mode_},{"selected",files_selected_},{"name",files_name_},{"feedback",files_feedback_}}}, {"widget_view",{{"query",widget_query_},{"notice",widget_notice_}}}, {"ui_preferences",ui_preferences_}, {"settings_draft",settings_draft_}, {"settings_category",settings_category_}, {"settings_query",settings_query_}, {"settings_notice",settings_notice_},
|
||||
{"front_view",front_snapshot_view()}, {"files_view",{{"mode",files_mode_},{"selected",files_selected_},{"name",files_name_},{"feedback",files_feedback_}}}, {"widget_view",{{"query",widget_query_},{"notice",widget_notice_}}}, {"ui_preferences",ui_preferences_}, {"settings_draft",settings_draft_}, {"settings_category",settings_category_}, {"settings_query",settings_query_}, {"settings_notice",settings_notice_},
|
||||
{"statistics_view", statistics_view_}, {"statistics_trophy", statistics_trophy_},
|
||||
{"statistics_scrolls", statistics_scrolls_},
|
||||
{"news_view", news_view_}, {"news_dialog", news_dialog_},
|
||||
|
||||
@@ -0,0 +1,460 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
void App::front_invalidate_world() {
|
||||
ticket_.reset();
|
||||
source_.reset();
|
||||
world_.reset();
|
||||
renderer_.world(nullptr);
|
||||
reset_files();
|
||||
reset_settings();
|
||||
reset_news();
|
||||
desktop_ = Json::object();
|
||||
saved_desktop_ = Json::object();
|
||||
working_desktop_initialized_ = false;
|
||||
working_desktop_base_ = Json();
|
||||
files_default_key_.clear();
|
||||
files_default_picture_ = Picture();
|
||||
files_default_pending_ = false;
|
||||
undo_.clear();
|
||||
undo_themes_.clear();
|
||||
pending_selects_.clear();
|
||||
amount_.reset();
|
||||
}
|
||||
void App::front_start(std::function<FrontResult()> work) {
|
||||
if (front_busy_)
|
||||
return;
|
||||
front_busy_ = true;
|
||||
front_dialog_.clear();
|
||||
front_feedback_ = "Dateien werden verarbeitet …";
|
||||
front_job_ = std::async(std::launch::async, std::move(work));
|
||||
refresh();
|
||||
}
|
||||
void App::front_poll() {
|
||||
if (!front_busy_ || !front_job_.valid())
|
||||
return;
|
||||
if (front_job_.wait_for(std::chrono::milliseconds(0)) !=
|
||||
std::future_status::ready) {
|
||||
if (front_progress_) {
|
||||
std::lock_guard lock(front_progress_->mutex);
|
||||
if (!front_progress_->text.empty() &&
|
||||
front_progress_->text != front_feedback_) {
|
||||
front_feedback_ = front_progress_->text;
|
||||
if (auto *text = element("mod-feedback"))
|
||||
text->SetInnerRML(esc(front_feedback_));
|
||||
dirty_ = true;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
const auto previous = active_mod_;
|
||||
front_busy_ = false;
|
||||
try {
|
||||
auto result = front_job_.get();
|
||||
if (result.plan) {
|
||||
front_plan_ = std::move(result.plan);
|
||||
front_name_ = front_plan_->metadata.name;
|
||||
front_dialog_ = "name";
|
||||
front_feedback_.clear();
|
||||
front_selection_token_ = front_snapshot_.selection_token;
|
||||
front_validate_name();
|
||||
focus_after_render_ = "front-mod-name";
|
||||
front_select_name_ = true;
|
||||
} else {
|
||||
if (result.activate)
|
||||
front_external_override_ = false;
|
||||
selected_mod_ = result.selected;
|
||||
collect_mods();
|
||||
front_plan_.reset();
|
||||
front_target_.reset();
|
||||
front_feedback_ = result.feedback;
|
||||
if ((!front_external_override_ && previous != active_mod_) ||
|
||||
(world_ && !fs::exists(world_->source()))) {
|
||||
front_external_override_ = false;
|
||||
front_invalidate_world();
|
||||
}
|
||||
front_select(selected_mod_);
|
||||
}
|
||||
} catch (const std::exception &error) {
|
||||
front_error_ = error.what();
|
||||
front_dialog_ = "error";
|
||||
front_plan_.reset();
|
||||
front_target_.reset();
|
||||
try {
|
||||
collect_mods();
|
||||
if (!front_external_override_ && previous != active_mod_)
|
||||
front_invalidate_world();
|
||||
} catch (const std::exception &) { /* The original error remains visible. */
|
||||
}
|
||||
}
|
||||
front_progress_.reset();
|
||||
refresh();
|
||||
}
|
||||
void App::front_validate_name() {
|
||||
front_name_error_.clear();
|
||||
try {
|
||||
const auto clean = UiModLibrary::clean_name(front_name_),
|
||||
key = UiModLibrary::name_key(clean);
|
||||
for (const auto &entry : front_snapshot_.entries) {
|
||||
if (front_dialog_ == "rename" && front_target_ &&
|
||||
entry.id == front_target_->id)
|
||||
continue;
|
||||
std::string existing;
|
||||
try {
|
||||
existing = UiModLibrary::name_key(entry.name);
|
||||
} catch (const std::exception &) {
|
||||
continue;
|
||||
}
|
||||
if (existing == key)
|
||||
throw editor::Error("Diese Mod-Bezeichnung wird bereits verwendet.");
|
||||
}
|
||||
} catch (const std::exception &error) {
|
||||
front_name_error_ = error.what();
|
||||
}
|
||||
if (auto *error = element("front-name-error"))
|
||||
error->SetInnerRML(esc(front_name_error_));
|
||||
if (auto *button = element("front-name-confirm")) {
|
||||
if (front_name_error_.empty() && !front_busy_)
|
||||
button->RemoveAttribute("disabled");
|
||||
else
|
||||
button->SetAttribute("disabled", true);
|
||||
}
|
||||
dirty_ = true;
|
||||
}
|
||||
void App::front_select(const std::string &id) {
|
||||
selected_mod_ = id;
|
||||
front_reveal_selection_ = true;
|
||||
for (size_t i = 0; i < front_snapshot_.entries.size(); ++i)
|
||||
if (front_snapshot_.entries[i].id == id)
|
||||
focus_after_render_ = "mod-entry-" + std::to_string(i);
|
||||
refresh();
|
||||
}
|
||||
void App::front_after_render() {
|
||||
if (scene_ != "mods")
|
||||
return;
|
||||
if (front_select_name_) {
|
||||
if (auto *input = dynamic_cast<Rml::ElementFormControlInput *>(
|
||||
element("front-mod-name")))
|
||||
input->Select();
|
||||
front_select_name_ = false;
|
||||
}
|
||||
if (auto *list = element("mod-list")) {
|
||||
if (front_restore_scroll_) {
|
||||
list->SetScrollTop(front_list_scroll_);
|
||||
front_restore_scroll_ = false;
|
||||
}
|
||||
if (front_reveal_selection_) {
|
||||
for (size_t i = 0; i < front_snapshot_.entries.size(); ++i)
|
||||
if (front_snapshot_.entries[i].id == selected_mod_)
|
||||
if (auto *row = element("mod-entry-" + std::to_string(i)))
|
||||
row->ScrollIntoView(
|
||||
Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));
|
||||
front_reveal_selection_ = false;
|
||||
}
|
||||
}
|
||||
if (!front_dialog_.empty()) {
|
||||
Rml::ElementList behind;
|
||||
doc_->QuerySelectorAll(
|
||||
behind, ".front-mod-content button,.front-mod-window>.titlebar button");
|
||||
for (auto *control : behind) {
|
||||
control->SetAttribute("disabled", true);
|
||||
control->SetProperty("pointer-events", "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
void App::front_pick(const std::string &kind) {
|
||||
if (front_busy_)
|
||||
return;
|
||||
fs::path selected = config_.mod_import;
|
||||
if (selected.empty()) {
|
||||
NFD::Guard guard;
|
||||
NFD::UniquePath chosen;
|
||||
const nfdfilteritem_t filters[] = {{"OpenBMH-Weltpaket", "obw,zip"}};
|
||||
const auto result = kind == "package" ? NFD::OpenDialog(chosen, filters, 1)
|
||||
: NFD::PickFolder(chosen);
|
||||
if (result == NFD_CANCEL)
|
||||
return;
|
||||
if (result != NFD_OKAY) {
|
||||
front_error_ = "Die Dateiauswahl konnte nicht geöffnet werden.";
|
||||
front_dialog_ = "error";
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
selected = editor::path(chosen.get());
|
||||
}
|
||||
const auto root = front_library_root();
|
||||
front_start([root, selected] {
|
||||
UiModLibrary library(root);
|
||||
FrontResult result;
|
||||
result.plan = library.inspect(selected);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
bool App::front_change(Rml::Element *target) {
|
||||
if (!target || target->GetId() != "front-mod-name" || front_busy_)
|
||||
return false;
|
||||
front_name_ = field("front-mod-name");
|
||||
front_validate_name();
|
||||
return true;
|
||||
}
|
||||
bool App::front_action(const std::string &action, Rml::Element *target) {
|
||||
const bool front = scene_ == "main" || scene_ == "mods";
|
||||
if (!front)
|
||||
return false;
|
||||
if (front_busy_) {
|
||||
if (action != "")
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
const auto id =
|
||||
target ? target->GetAttribute<Rml::String>("data-id", "") : std::string();
|
||||
if (action == "load") {
|
||||
if (auto *active = mod(active_mod_);
|
||||
active && active->type == "Classic" && active->error.empty()) {
|
||||
dispatch("new", target);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (action == "mods") {
|
||||
collect_mods();
|
||||
front_tab_ = "installed";
|
||||
front_dialog_.clear();
|
||||
front_plan_.reset();
|
||||
front_feedback_.clear();
|
||||
front_list_scroll_ = 0;
|
||||
if (!front_selected())
|
||||
selected_mod_ = front_snapshot_.entries.empty()
|
||||
? ""
|
||||
: front_snapshot_.entries.front().id;
|
||||
scene_ = "mods";
|
||||
focus_after_render_ = "mod-installed";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "front-home" || (action == "close" && scene_ == "mods")) {
|
||||
scene_ = "main";
|
||||
front_dialog_.clear();
|
||||
front_plan_.reset();
|
||||
front_target_.reset();
|
||||
focus_after_render_ = "front-mods";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "front-tab") {
|
||||
if (auto *list = element("mod-list"))
|
||||
front_list_scroll_ = list->GetScrollTop();
|
||||
if (id == "installed" || id == "downloads") {
|
||||
front_tab_ = id;
|
||||
front_restore_scroll_ = true;
|
||||
focus_after_render_ =
|
||||
id == "installed" ? "mod-installed" : "mod-downloads";
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "mod-select") {
|
||||
front_select(id);
|
||||
return true;
|
||||
}
|
||||
if (action == "front-import") {
|
||||
front_dialog_ = "choice";
|
||||
front_return_focus_ = "front-import-button";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "front-pick") {
|
||||
front_pick(id);
|
||||
return true;
|
||||
}
|
||||
if (action == "front-dismiss") {
|
||||
front_dialog_.clear();
|
||||
front_plan_.reset();
|
||||
front_target_.reset();
|
||||
front_name_error_.clear();
|
||||
focus_after_render_ =
|
||||
front_return_focus_.empty() ? "mod-installed" : front_return_focus_;
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "front-name-confirm") {
|
||||
front_name_ = field("front-mod-name");
|
||||
front_validate_name();
|
||||
if (!front_name_error_.empty())
|
||||
return true;
|
||||
const auto name = UiModLibrary::clean_name(front_name_);
|
||||
const auto root = front_library_root();
|
||||
if (front_dialog_ == "name" && front_plan_) {
|
||||
const auto plan = *front_plan_;
|
||||
front_progress_ = std::make_shared<FrontProgress>();
|
||||
const auto progress = front_progress_;
|
||||
front_start([root, plan, name, progress] {
|
||||
UiModLibrary library(root);
|
||||
const auto row =
|
||||
library.commit(plan, name, [progress](const std::string &text) {
|
||||
std::lock_guard lock(progress->mutex);
|
||||
progress->text = text;
|
||||
});
|
||||
return FrontResult{{},
|
||||
row.id,
|
||||
"Mod importiert. Du kannst sie jetzt aktivieren.",
|
||||
false};
|
||||
});
|
||||
} else if (front_dialog_ == "rename" && front_target_) {
|
||||
const auto row = *front_target_;
|
||||
const auto token = front_selection_token_;
|
||||
front_start([root, row, name, token] {
|
||||
UiModLibrary library(root);
|
||||
const auto renamed = library.rename(row, name, token);
|
||||
return FrontResult{{}, renamed.id, "Mod umbenannt.", false};
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "mod-rename") {
|
||||
if (auto *entry = front_selected()) {
|
||||
front_target_ = *entry;
|
||||
front_selection_token_ = front_snapshot_.selection_token;
|
||||
front_name_ = entry->name;
|
||||
front_dialog_ = "rename";
|
||||
front_return_focus_ = "mod-rename-button";
|
||||
front_validate_name();
|
||||
focus_after_render_ = "front-mod-name";
|
||||
front_select_name_ = true;
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "mod-remove") {
|
||||
if (auto *entry = front_selected()) {
|
||||
front_target_ = *entry;
|
||||
front_selection_token_ = front_snapshot_.selection_token;
|
||||
front_dialog_ = "delete";
|
||||
front_return_focus_ = "mod-remove-button";
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "front-delete-confirm" && front_target_) {
|
||||
const auto entry = *front_target_;
|
||||
const auto token = front_selection_token_;
|
||||
const auto root = front_library_root();
|
||||
front_start([root, entry, token] {
|
||||
UiModLibrary library(root);
|
||||
library.remove(entry, token);
|
||||
return FrontResult{
|
||||
{}, "", "Mod entfernt. Persönliche Daten wurden erhalten.", false};
|
||||
});
|
||||
return true;
|
||||
}
|
||||
if (action == "mod-activate") {
|
||||
if (auto *entry = front_selected(); entry && entry->valid()) {
|
||||
const auto row = *entry;
|
||||
const auto token = front_snapshot_.selection_token;
|
||||
const auto root = front_library_root();
|
||||
front_start([root, row, token] {
|
||||
UiModLibrary library(root);
|
||||
library.activate(row, token);
|
||||
return FrontResult{{}, row.id, "Mod aktiviert.", true};
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "front-noop" || action == "network")
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
bool App::front_event(Rml::Event &event) {
|
||||
if (scene_ != "main" && scene_ != "mods")
|
||||
return false;
|
||||
if (!popup_.empty() || !menu_.empty())
|
||||
return false;
|
||||
const auto type = event.GetType();
|
||||
auto *target = event.GetTargetElement();
|
||||
if ((type == "input" || type == "change") && front_change(target))
|
||||
return true;
|
||||
if (type != "keydown")
|
||||
return false;
|
||||
const auto key =
|
||||
Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0));
|
||||
if (front_busy_) {
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (key == Rml::Input::KI_ESCAPE) {
|
||||
if (!front_dialog_.empty())
|
||||
front_action("front-dismiss", nullptr);
|
||||
else if (scene_ == "mods")
|
||||
front_action("front-home", nullptr);
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (!front_dialog_.empty() && target->GetId() == "front-mod-name" &&
|
||||
(key == Rml::Input::KI_RETURN || key == Rml::Input::KI_NUMPADENTER)) {
|
||||
front_action("front-name-confirm", nullptr);
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (key == Rml::Input::KI_TAB) {
|
||||
Rml::ElementList controls;
|
||||
auto *region = scene_ == "main" ? doc_->QuerySelector(".main-options")
|
||||
: !front_dialog_.empty()
|
||||
? doc_->QuerySelector(".front-dialog")
|
||||
: doc_->QuerySelector(".front-mod-window");
|
||||
if (region)
|
||||
region->QuerySelectorAll(controls, "button,input,select");
|
||||
std::erase_if(controls, [](auto *node) {
|
||||
return node->HasAttribute("disabled") || !node->IsVisible(true);
|
||||
});
|
||||
if (!controls.empty()) {
|
||||
const auto it = std::find(controls.begin(), controls.end(),
|
||||
context_->GetFocusElement());
|
||||
const int pos = it == controls.end() ? -1 : int(it - controls.begin()),
|
||||
n = int(controls.size());
|
||||
const bool reverse = event.GetParameter<int>("shift_key", 0) != 0;
|
||||
controls[size_t(pos < 0 ? (reverse ? n - 1 : 0)
|
||||
: (pos + (reverse ? -1 : 1) + n) % n)]
|
||||
->Focus(true);
|
||||
}
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (front_dialog_.empty() &&
|
||||
(key == Rml::Input::KI_UP || key == Rml::Input::KI_DOWN ||
|
||||
key == Rml::Input::KI_HOME || key == Rml::Input::KI_END)) {
|
||||
if (scene_ == "main") {
|
||||
Rml::ElementList options;
|
||||
doc_->QuerySelectorAll(options, ".main-options button");
|
||||
std::erase_if(options,
|
||||
[](auto *n) { return n->HasAttribute("disabled"); });
|
||||
if (!options.empty()) {
|
||||
const auto it = std::find(options.begin(), options.end(),
|
||||
context_->GetFocusElement());
|
||||
const int n = int(options.size()),
|
||||
pos = it == options.end() ? 0 : int(it - options.begin());
|
||||
const int index =
|
||||
key == Rml::Input::KI_HOME ? 0
|
||||
: key == Rml::Input::KI_END
|
||||
? n - 1
|
||||
: (pos + (key == Rml::Input::KI_UP ? -1 : 1) + n) % n;
|
||||
options[size_t(index)]->Focus(true);
|
||||
}
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (target->IsClassSet("front-mod-entry")) {
|
||||
size_t index = 0;
|
||||
for (size_t i = 0; i < front_snapshot_.entries.size(); ++i)
|
||||
if (front_snapshot_.entries[i].id == selected_mod_)
|
||||
index = i;
|
||||
if (!front_snapshot_.entries.empty()) {
|
||||
index = key == Rml::Input::KI_HOME ? 0
|
||||
: key == Rml::Input::KI_END ? front_snapshot_.entries.size() - 1
|
||||
: key == Rml::Input::KI_UP
|
||||
? (index ? index - 1 : 0)
|
||||
: std::min(index + 1, front_snapshot_.entries.size() - 1);
|
||||
front_select(front_snapshot_.entries[index].id);
|
||||
}
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
fs::path App::front_library_root() const {
|
||||
return config_.mods.empty() ? root_ : config_.mods;
|
||||
}
|
||||
const UiModEntry *App::front_selected() const {
|
||||
for (const auto &entry : front_snapshot_.entries)
|
||||
if (entry.id == selected_mod_)
|
||||
return &entry;
|
||||
return nullptr;
|
||||
}
|
||||
std::string App::front_source_name(const UiModEntry &entry) const {
|
||||
return entry.source == "BMH" ? "Bundesliga Manager Hattrick"
|
||||
: entry.source == "FTLD" || entry.source == "FLTD" ? "Football Limited"
|
||||
: "OpenBMH";
|
||||
}
|
||||
std::string App::front_size(uint64_t bytes) const {
|
||||
const auto tenths = (bytes * 10 + 524288) / 1048576;
|
||||
return number(int64_t(tenths / 10)) +
|
||||
(tenths % 10 ? "," + std::to_string(tenths % 10) : "") + " MiB";
|
||||
}
|
||||
std::string App::main_menu() {
|
||||
const auto *active = mod(active_mod_);
|
||||
const bool available = active && active->error.empty();
|
||||
std::string out =
|
||||
"<div class=\"fill front-shade\"></div><div class=\"front-home\"><header "
|
||||
"class=\"brand\"><p>FUSSBALLMANAGER</p><h1>Open<span>BMH</span></h1></"
|
||||
"header><nav class=\"main-options\" aria-label=\"Hauptmenü\">";
|
||||
const std::array<std::pair<const char *, const char *>, 6> actions{
|
||||
{{"new", "Neues Spiel"},
|
||||
{"load", "Spiel laden"},
|
||||
{"network", "Netzwerk"},
|
||||
{"mods", "Mod"},
|
||||
{"settings", "Einstellungen"},
|
||||
{"exit", "Beenden"}}};
|
||||
for (const auto &[key, title] : actions) {
|
||||
const bool network = std::string(key) == "network",
|
||||
disabled = scene_ != "main" || network ||
|
||||
(std::string(key) == "new" && !available &&
|
||||
!(front_external_override_ && world_));
|
||||
out += btn(key,
|
||||
"<span>" + std::string(title) + "</span>" +
|
||||
(network ? "<small>Demnächst</small>" : "") +
|
||||
"<span class=\"front-hover-arrow\">›</span>",
|
||||
"front-menu-action",
|
||||
"id=\"front-" + std::string(key) + "\" " +
|
||||
(disabled ? "disabled" : ""));
|
||||
}
|
||||
const auto label = front_external_override_ && world_ ? world_->title()
|
||||
: available ? active->name
|
||||
: "Keine Mod aktiviert";
|
||||
out +=
|
||||
"</nav><footer class=\"front-footer\"><div class=\"front-active\"><span "
|
||||
"class=\"front-active-dot\"></span><div><small>Aktive Mod</small><strong "
|
||||
"id=\"front-active-name\">" +
|
||||
esc(label) + "</strong></div></div><small class=\"front-version\">v" +
|
||||
std::string(kOpenBmhVersion) + " · UI-Demo</small></footer></div>";
|
||||
return out;
|
||||
}
|
||||
std::string App::front_mod_details() {
|
||||
const auto *entry = front_selected();
|
||||
if (!entry)
|
||||
return "<div class=\"front-mod-empty\"><h2>Noch keine Mods "
|
||||
"installiert</h2><p>Importiere einen Originalordner oder ein "
|
||||
"OpenBMH-Paket.</p></div>";
|
||||
const bool active = entry->active && !front_external_override_;
|
||||
const auto provenance = entry->description.empty() ? front_source_name(*entry)
|
||||
: entry->description;
|
||||
std::string out =
|
||||
"<div class=\"front-mod-details\"><div class=\"front-mod-cover\">" +
|
||||
img("background", 1360, 360, false, true, 1600) +
|
||||
"<span>Open<span>BMH</span></span></div><header><div><p>" +
|
||||
esc(provenance) + "</p><h2>" + esc(entry->name) +
|
||||
"</h2></div><span class=\"front-mod-status " +
|
||||
(active ? "is-active" : "") + "\">" +
|
||||
(active ? "Aktiv"
|
||||
: entry->valid() ? "Installiert"
|
||||
: "Fehlerhaft") +
|
||||
"</span></header><div class=\"front-mod-metadata\">";
|
||||
const std::vector<std::pair<std::string, std::string>> fields = {
|
||||
{"Art", entry->type},
|
||||
{"Herkunft", front_source_name(*entry)},
|
||||
{"Version", entry->version},
|
||||
{"Inhalt", std::to_string(entry->file_count) +
|
||||
(entry->file_count == 1 ? " Datei" : " Dateien") + " · " +
|
||||
front_size(entry->bytes)}};
|
||||
for (const auto &[label, value] : fields)
|
||||
out += "<div><span>" + esc(label) + "</span><strong>" + esc(value) +
|
||||
"</strong></div>";
|
||||
out += "</div>";
|
||||
if (!entry->valid())
|
||||
out += "<p class=\"front-mod-error\">" + esc(entry->error) + "</p>";
|
||||
const auto *current = mod(active_mod_);
|
||||
out +=
|
||||
"<p class=\"front-mod-activation-note\">" +
|
||||
esc(active ? "Diese Mod ist für das nächste Spiel ausgewählt."
|
||||
: current ? "Aktivieren ersetzt die Auswahl „" + current->name + "“."
|
||||
: "Aktiviere diese Mod für das nächste Spiel.") +
|
||||
"</p>";
|
||||
return out +
|
||||
btn("mod-activate", active ? "Aktiv" : "Aktivieren",
|
||||
"front-mod-activate",
|
||||
"id=\"mod-activate\" " +
|
||||
std::string(active || !entry->valid() || front_busy_
|
||||
? "disabled"
|
||||
: "")) +
|
||||
"</div>";
|
||||
}
|
||||
std::string App::front_modal() {
|
||||
if (front_dialog_.empty())
|
||||
return {};
|
||||
std::string heading, body, buttons;
|
||||
if (front_dialog_ == "choice") {
|
||||
heading = "Mod importieren";
|
||||
body = "<p>Wähle einen Originalordner oder einen Export im "
|
||||
"OpenBMH-Format.</p><div class=\"front-import-choices\">";
|
||||
const std::array<std::array<const char *, 3>, 3> choices{
|
||||
{{{"original", "BMH / Football Limited",
|
||||
"Originalordner mit BMH.EXE oder FLTD.EXE"}},
|
||||
{{"package", "OpenBMH-Paket",
|
||||
"Weltpaket im neuen Format · .obw oder .zip"}},
|
||||
{{"folder", "OpenBMH-Exportordner",
|
||||
"Entpackte Welt oder Mod-Ordner mit content.obw"}}}};
|
||||
for (const auto &c : choices)
|
||||
body += btn(
|
||||
"front-pick",
|
||||
"<strong>" + std::string(c[1]) + "</strong><span>" + c[2] + "</span>",
|
||||
"front-import-choice", "data-id=\"" + std::string(c[0]) + "\"");
|
||||
body += "</div>";
|
||||
buttons = btn("front-dismiss", "Abbrechen");
|
||||
} else if (front_dialog_ == "name" || front_dialog_ == "rename") {
|
||||
const bool importing = front_dialog_ == "name";
|
||||
heading = importing ? "Mod übernehmen" : "Mod umbenennen";
|
||||
body = "<label class=\"front-name-label\"><span>Bezeichnung</span><input "
|
||||
"type=\"text\" id=\"front-mod-name\" value=\"" +
|
||||
esc(front_name_) + "\" maxlength=\"64\"/></label>";
|
||||
if (importing && front_plan_) {
|
||||
const auto &m = front_plan_->metadata;
|
||||
body +=
|
||||
"<p class=\"front-import-summary\">" + esc(m.description) + " · " +
|
||||
esc(m.type) + "<br/>" + std::to_string(m.file_count) +
|
||||
(m.file_count == 1 ? " Datei" : " Dateien") + " · " +
|
||||
front_size(m.bytes) + "</p><p class=\"front-import-note\">" +
|
||||
std::string(m.type == "Classic"
|
||||
? "Der vorhandene OpenBMH-Importer konvertiert die "
|
||||
"Originaldaten in ein eigenständiges Classic-Paket."
|
||||
: "Das geprüfte Weltpaket wird in deine "
|
||||
"Mod-Bibliothek übernommen.") +
|
||||
" Anschließend kannst du die Mod aktivieren.</p>";
|
||||
}
|
||||
body += "<p id=\"front-name-error\" class=\"front-name-error\">" +
|
||||
esc(front_name_error_) + "</p>";
|
||||
buttons = btn("front-dismiss", "Abbrechen") +
|
||||
btn("front-name-confirm",
|
||||
importing ? "Importieren" : "Umbenennen", "primary",
|
||||
"id=\"front-name-confirm\" " +
|
||||
std::string(front_name_error_.empty() ? "" : "disabled"));
|
||||
} else if (front_dialog_ == "delete") {
|
||||
heading = "Mod löschen?";
|
||||
body = "<p>„" + esc(front_target_ ? front_target_->name : "") +
|
||||
"“ wirklich aus der lokalen Bibliothek entfernen?</p>";
|
||||
if (front_target_ && front_target_->active)
|
||||
body += "<p class=\"front-import-note\">Danach ist keine Mod aktiviert. "
|
||||
"Wähle eine andere Mod für das nächste neue Spiel.</p>";
|
||||
body += "<p class=\"front-import-note\">Persönliche Spielstände und "
|
||||
"Desktopansichten bleiben erhalten.</p>";
|
||||
buttons = btn("front-dismiss", "Abbrechen") +
|
||||
btn("front-delete-confirm", "Löschen", "primary");
|
||||
} else {
|
||||
heading = "Vorgang nicht möglich";
|
||||
body = "<p>" + esc(front_error_) + "</p>";
|
||||
buttons = btn("front-dismiss", "Verstanden");
|
||||
}
|
||||
return "<div class=\"front-dialog-layer\"><section class=\"front-dialog\" "
|
||||
"role=\"dialog\" aria-modal=\"true\"><h2>" +
|
||||
esc(heading) + "</h2>" + body + "<footer>" + buttons +
|
||||
"</footer></section></div>";
|
||||
}
|
||||
std::string App::mods_page() {
|
||||
std::string rows;
|
||||
for (size_t i = 0; i < front_snapshot_.entries.size(); ++i) {
|
||||
const auto &entry = front_snapshot_.entries[i];
|
||||
const bool active = entry.active && !front_external_override_;
|
||||
rows += btn(
|
||||
"mod-select",
|
||||
"<span class=\"front-mod-copy\"><strong>" + esc(entry.name) +
|
||||
"</strong><small>" +
|
||||
(active
|
||||
? "<span "
|
||||
"class=\"front-mod-active-dot\"></span><span>Aktiv</span>"
|
||||
: "<span>" + esc(entry.valid() ? entry.source : "Fehlerhaft") +
|
||||
"</span>") +
|
||||
"</small></span><span class=\"front-mod-type\">" + esc(entry.type) +
|
||||
"</span>",
|
||||
"front-mod-entry " +
|
||||
std::string(entry.id == selected_mod_ ? "selected" : ""),
|
||||
"id=\"mod-entry-" + std::to_string(i) +
|
||||
"\" role=\"option\" aria-selected=\"" +
|
||||
(entry.id == selected_mod_ ? "true" : "false") + "\" data-id=\"" +
|
||||
esc(entry.id) + "\" " + (front_busy_ ? "disabled" : ""));
|
||||
}
|
||||
if (rows.empty())
|
||||
rows = "<p class=\"front-mod-empty-list\">Noch keine Mods vorhanden.</p>";
|
||||
const auto tabs =
|
||||
btn("front-tab",
|
||||
"Installiert · " + std::to_string(front_snapshot_.entries.size()),
|
||||
front_tab_ == "installed" ? "active" : "",
|
||||
"id=\"mod-installed\" role=\"tab\" aria-selected=\"" +
|
||||
std::string(front_tab_ == "installed" ? "true" : "false") +
|
||||
"\" data-id=\"installed\" " + (front_busy_ ? "disabled" : "")) +
|
||||
btn("front-tab", "Downloads", front_tab_ == "downloads" ? "active" : "",
|
||||
"id=\"mod-downloads\" role=\"tab\" aria-selected=\"" +
|
||||
std::string(front_tab_ == "downloads" ? "true" : "false") +
|
||||
"\" data-id=\"downloads\" " + (front_busy_ ? "disabled" : ""));
|
||||
const auto pane =
|
||||
front_tab_ == "installed"
|
||||
? "<div class=\"front-mod-layout\"><section "
|
||||
"class=\"front-mod-browser\"><header><span>Mod</span><span>Art</"
|
||||
"span></header><div class=\"front-mod-list\" id=\"mod-list\" "
|
||||
"role=\"listbox\" aria-label=\"Mod auswählen\">" +
|
||||
rows + "</div></section>" + front_mod_details() + "</div>"
|
||||
: "<section class=\"front-mod-downloads\">" +
|
||||
img("icon.download", 180, 180) +
|
||||
"<h2>Neue Welten entdecken</h2><p>Hier findest du später Mods "
|
||||
"aus der zentralen OpenBMH-Datenbank.</p>" +
|
||||
btn("front-noop", "Downloads demnächst", {}, "disabled") +
|
||||
"</section>";
|
||||
const bool selected = front_selected() != nullptr,
|
||||
enabled = !front_busy_ && selected && front_tab_ == "installed";
|
||||
const auto feedback = front_busy_ ? front_feedback_
|
||||
: !front_feedback_.empty() ? front_feedback_
|
||||
: !front_snapshot_.error.empty()
|
||||
? front_snapshot_.error
|
||||
: "Es kann genau eine Mod aktiv sein.";
|
||||
const auto body =
|
||||
"<div class=\"front-mod-content\"><nav class=\"front-mod-tabs\" "
|
||||
"role=\"tablist\">" +
|
||||
tabs + "</nav><div class=\"front-mod-tabpanel\" role=\"tabpanel\">" +
|
||||
pane +
|
||||
"</div><footer class=\"front-mod-actions\"><p id=\"mod-feedback\">" +
|
||||
esc(feedback) + "</p><div>" +
|
||||
btn("front-import", "Importieren", {},
|
||||
"id=\"front-import-button\" " +
|
||||
std::string(front_busy_ ? "disabled" : "")) +
|
||||
btn("mod-rename", "Umbenennen", {},
|
||||
"id=\"mod-rename-button\" " +
|
||||
std::string(enabled ? "" : "disabled")) +
|
||||
btn("mod-remove", "Löschen", {},
|
||||
"id=\"mod-remove-button\" " +
|
||||
std::string(enabled ? "" : "disabled")) +
|
||||
"</div></footer></div>";
|
||||
return main_menu() +
|
||||
"<div class=\"fill front-mod-layer\" style=\"z-index:100;\"><section "
|
||||
"class=\"window front-mod-window\"><header class=\"titlebar\">" +
|
||||
btn("front-home", "<span>×</span>", "close",
|
||||
"id=\"window-close\" aria-label=\"Mod-Verwaltung schließen\" " +
|
||||
std::string(front_busy_ ? "disabled" : "")) +
|
||||
"<h1>Mod</h1></header>" + body + front_modal() + "</section></div>";
|
||||
}
|
||||
|
||||
Json App::front_snapshot_view() const {
|
||||
Json rows = Json::array();
|
||||
for (const auto &row : front_snapshot_.entries)
|
||||
rows.push_back({{"id", row.id},
|
||||
{"name", row.name},
|
||||
{"type", row.type},
|
||||
{"source", row.source},
|
||||
{"version", row.version},
|
||||
{"error", row.error},
|
||||
{"active", row.active},
|
||||
{"bytes", row.bytes},
|
||||
{"file_count", row.file_count},
|
||||
{"token", row.token}});
|
||||
return {{"tab", front_tab_},
|
||||
{"dialog", front_dialog_},
|
||||
{"busy", front_busy_},
|
||||
{"selected", selected_mod_},
|
||||
{"active", active_mod_},
|
||||
{"external_override", front_external_override_},
|
||||
{"feedback", front_feedback_},
|
||||
{"name_error", front_name_error_},
|
||||
{"library_error", front_snapshot_.error},
|
||||
{"entries", rows},
|
||||
{"plan", front_plan_ ? Json{{"name", front_plan_->metadata.name},
|
||||
{"type", front_plan_->metadata.type},
|
||||
{"source", front_plan_->metadata.source},
|
||||
{"bytes", front_plan_->metadata.bytes}}
|
||||
: Json()}};
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
struct FrontProgress {
|
||||
std::mutex mutex;
|
||||
std::string text;
|
||||
};
|
||||
struct FrontResult {
|
||||
std::optional<ModImportPlan> plan;
|
||||
std::string selected, feedback;
|
||||
bool activate = false;
|
||||
};
|
||||
ModSnapshot front_snapshot_;
|
||||
std::string front_tab_ = "installed", front_dialog_, front_name_,
|
||||
front_name_error_, front_feedback_, front_error_,
|
||||
front_return_focus_;
|
||||
std::optional<ModImportPlan> front_plan_;
|
||||
std::optional<UiModEntry> front_target_;
|
||||
std::string front_selection_token_;
|
||||
std::future<FrontResult> front_job_;
|
||||
std::shared_ptr<FrontProgress> front_progress_;
|
||||
bool front_busy_ = false, front_external_override_ = false;
|
||||
float front_list_scroll_ = 0;
|
||||
bool front_restore_scroll_ = false, front_reveal_selection_ = false;
|
||||
fs::path front_library_root() const;
|
||||
const UiModEntry *front_selected() const;
|
||||
std::string front_source_name(const UiModEntry &) const;
|
||||
std::string front_size(uint64_t) const;
|
||||
std::string front_modal();
|
||||
std::string front_mod_details();
|
||||
void front_start(std::function<FrontResult()>);
|
||||
void front_poll();
|
||||
void front_pick(const std::string &);
|
||||
void front_validate_name();
|
||||
void front_select(const std::string &);
|
||||
void front_after_render();
|
||||
void front_invalidate_world();
|
||||
bool front_action(const std::string &, Rml::Element *);
|
||||
bool front_event(Rml::Event &);
|
||||
bool front_change(Rml::Element *);
|
||||
|
||||
Json front_snapshot_view() const;
|
||||
|
||||
bool front_select_name_ = false;
|
||||
@@ -0,0 +1,405 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/mod_library.hpp"
|
||||
#include "modern/ui/demo_files.hpp"
|
||||
#include "content/package.hpp"
|
||||
#include "launch/mods.hpp"
|
||||
#include "launch/game_data.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
constexpr uint64_t limit = 512ull * 1024 * 1024;
|
||||
constexpr const char *selection_file = ".ui-active-mod.json";
|
||||
constexpr const char *journal_file = ".ui-mod-transaction.json";
|
||||
void directory(const fs::path &path, bool create = false) {
|
||||
fs::path cursor;
|
||||
for (const auto &part : fs::absolute(path).lexically_normal()) {
|
||||
cursor /= part;
|
||||
const auto status = fs::symlink_status(cursor);
|
||||
if (fs::is_symlink(status) || (fs::exists(status) && !fs::is_directory(status)))
|
||||
throw editor::Error("Unsicheres Mod-Verzeichnis.");
|
||||
}
|
||||
if (create) fs::create_directories(path);
|
||||
}
|
||||
std::string regular(const fs::path &path, uint64_t maximum = limit) {
|
||||
if (fs::is_symlink(fs::symlink_status(path)) || !fs::is_regular_file(path))
|
||||
throw editor::Error("Die Mod-Datei fehlt oder ist verknüpft.");
|
||||
return editor::read_file(path, maximum);
|
||||
}
|
||||
std::string file_digest(const fs::path &path) {
|
||||
if (fs::is_symlink(fs::symlink_status(path)) || !fs::is_regular_file(path) || fs::file_size(path) > limit)
|
||||
throw editor::Error("Unsichere oder zu große Mod-Datei.");
|
||||
std::ifstream stream(path, std::ios::binary);
|
||||
if (!stream) throw editor::Error("Mod-Datei nicht lesbar.");
|
||||
std::string buffer(1024 * 1024, '\0'), blocks; uint64_t count = 0;
|
||||
while (stream) {
|
||||
stream.read(buffer.data(), std::streamsize(buffer.size()));
|
||||
const auto received = stream.gcount();
|
||||
if (received > 0) { count += uint64_t(received); if (count > limit) throw editor::Error("Mod-Datei zu groß."); blocks += content::sha256(std::string_view(buffer.data(), size_t(received))); }
|
||||
}
|
||||
if (!stream.eof() || count != fs::file_size(path)) throw editor::Error("Mod-Datei wurde beim Lesen geändert.");
|
||||
return content::sha256(std::to_string(count) + ":" + blocks);
|
||||
}
|
||||
struct Temp {
|
||||
fs::path path;
|
||||
Temp() : path(fs::temp_directory_path() / editor::new_id("openbmh-mod-plan-")) {
|
||||
if (!fs::create_directory(path)) throw editor::Error("Temporärer Mod-Ordner nicht verfügbar.");
|
||||
}
|
||||
~Temp() { std::error_code error; fs::remove_all(path, error); }
|
||||
};
|
||||
struct Lock {
|
||||
fs::path path;
|
||||
explicit Lock(const fs::path &root) : path(root / ".ui-mod-lock") {
|
||||
directory(root, true);
|
||||
if (!fs::create_directory(path)) throw editor::Error("Die Mod-Bibliothek ist gerade belegt.");
|
||||
}
|
||||
~Lock() { std::error_code error; fs::remove(path, error); }
|
||||
};
|
||||
void member_name(const std::string &name) {
|
||||
try { UiModLibrary::clean_name(name); }
|
||||
catch (const std::exception &) {
|
||||
// Existing 0.2 ASCII names may exceed the new UI's64-character limit.
|
||||
launch::ModLibrary::validate_name(name);
|
||||
}
|
||||
}
|
||||
std::string member_key(const std::string &name) {
|
||||
try { return DemoFiles::name_key(name); }
|
||||
catch (const std::exception &) { member_name(name); return editor::folded(name); }
|
||||
}
|
||||
std::string fingerprint(const fs::path &source) {
|
||||
if (fs::is_symlink(fs::symlink_status(source))) throw editor::Error("Verknüpfte Mod-Quellen werden nicht übernommen.");
|
||||
if (fs::is_regular_file(source)) return content::sha256("file:" + file_digest(source));
|
||||
if (!fs::is_directory(source)) throw editor::Error("Die Mod-Quelle fehlt.");
|
||||
std::map<std::string, std::string> files; uint64_t bytes = 0;
|
||||
std::set<std::string> paths;
|
||||
for (const auto &entry : fs::recursive_directory_iterator(source)) {
|
||||
if (entry.is_symlink()) throw editor::Error("Verknüpfte Mod-Inhalte werden nicht übernommen.");
|
||||
if (!entry.is_regular_file()) {
|
||||
if (!entry.is_directory()) throw editor::Error("Nicht unterstützter Dateityp in der Mod.");
|
||||
continue;
|
||||
}
|
||||
const auto name = editor::utf8(entry.path().lexically_relative(source));
|
||||
if (!editor::safe_name(name) || !paths.insert(editor::folded(name)).second || files.size() >= 12000 ||
|
||||
entry.file_size() > limit || (bytes += entry.file_size()) > limit)
|
||||
throw editor::Error("Unsichere, doppelte oder zu große Mod-Inhalte.");
|
||||
files[name] = file_digest(entry.path());
|
||||
}
|
||||
return content::sha256(Json(files).dump());
|
||||
}
|
||||
std::string description(const Json &manifest) {
|
||||
auto text = localized(manifest.value("description", Json()));
|
||||
if (text.empty()) text = localized(manifest.value("title", Json()));
|
||||
if (text.size() > 4000) throw editor::Error("Die Mod-Beschreibung ist zu lang.");
|
||||
return text;
|
||||
}
|
||||
bool feature(const Json &manifest, const std::string &name) {
|
||||
const auto required = manifest.value("requires", Json::array());
|
||||
return required.is_array() && std::find(required.begin(), required.end(), Json(name)) != required.end();
|
||||
}
|
||||
struct Package {
|
||||
std::shared_ptr<editor::ArchiveStore> archive;
|
||||
UiModEntry metadata;
|
||||
};
|
||||
Package package(const fs::path &path) {
|
||||
Package value; value.archive = editor::ArchiveStore::open(path);
|
||||
const auto manifest = Json::parse(value.archive->read("manifest.json"));
|
||||
if (manifest.value("format", "") != "openbmh-world" || manifest.value("kind", "") != "world")
|
||||
throw editor::Error("Die Quelle ist kein OpenBMH-Weltpaket.");
|
||||
auto &row = value.metadata;
|
||||
row.name = manifest.value("mod", std::string());
|
||||
if (row.name.empty()) row.name = localized(manifest.value("title", Json()));
|
||||
try { row.name = UiModLibrary::clean_name(row.name); } catch (...) { row.name = "OpenBMH-Mod"; }
|
||||
row.description = description(manifest);
|
||||
row.version = manifest.value("version", manifest.value("format_version", std::string()));
|
||||
if (row.version.size() > 120) throw editor::Error("Ungültige Mod-Version.");
|
||||
row.format = fs::is_directory(path) ? "obw-directory" : "obw";
|
||||
Json hashes = Json::object();
|
||||
for (const auto &name : value.archive->names()) {
|
||||
if (++row.file_count > 12000 || (row.bytes += value.archive->size(name)) > limit)
|
||||
throw editor::Error("Das Weltpaket ist zu groß.");
|
||||
// Reading every entry checks compressed payload integrity, not just JSON.
|
||||
hashes[name] = content::sha256(value.archive->read(name));
|
||||
}
|
||||
const bool classic = feature(manifest, "runtime:classic-v1");
|
||||
if (classic) {
|
||||
if (feature(manifest, "runtime:modern-v1")) throw editor::Error("Mehrdeutiges Classic-/Modern-Profil.");
|
||||
Temp temp; const auto packed = temp.path / "content.obw";
|
||||
value.archive->save(packed, {}, {});
|
||||
const auto checked = content::open(packed);
|
||||
row.type = "Classic"; row.source = checked->english ? "FTLD" : "BMH";
|
||||
row.content_id = checked->content_id;
|
||||
} else {
|
||||
const auto required = manifest.value("requires", Json::array());
|
||||
if (!required.is_array()) throw editor::Error("Ungültige Weltanforderungen.");
|
||||
for (const auto &requirement : required)
|
||||
if (requirement != "editor:world-v1" && requirement != "runtime:modern-v1")
|
||||
throw editor::Error("Diese Weltanforderung wird von der nativen Oberfläche nicht unterstützt.");
|
||||
if (!Catalog::modern_manifest(manifest)) throw editor::Error("Dieses Weltprofil wird nicht unterstützt.");
|
||||
const auto checked = Catalog::open(path);
|
||||
const auto clubs = checked->clubs();
|
||||
if (std::none_of(clubs.begin(), clubs.end(), [&](const auto *club) {
|
||||
return checked->manageable(club->value("id", ""));
|
||||
})) throw editor::Error("Diese Welt besitzt keinen von der UI-Demo unterstützten Verein.");
|
||||
row.type = "Modern"; row.source = "OpenBMH"; row.content_id = content::sha256(hashes.dump());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
struct Selection {
|
||||
std::optional<std::string> active;
|
||||
std::string token, transaction, error;
|
||||
};
|
||||
Selection selection(const fs::path &root) {
|
||||
Selection out; const auto file = root / selection_file;
|
||||
if (!fs::exists(fs::symlink_status(file))) { out.token = content::sha256("absent"); return out; }
|
||||
try {
|
||||
const auto bytes = regular(file, 1024 * 1024); out.token = content::sha256("file:" + bytes);
|
||||
const auto state = Json::parse(bytes);
|
||||
if (state.at("schema").get<std::string>() != "openbmh-ui-active-mod@1" ||
|
||||
(!state.at("active").is_null() && !state.at("active").is_string())) throw editor::Error("Ungültige aktive Mod-Auswahl.");
|
||||
if (!state.at("active").is_null()) {
|
||||
const auto name = state.at("active").get<std::string>(); member_name(name); out.active = name;
|
||||
}
|
||||
out.transaction = state.value("transaction", "");
|
||||
} catch (const std::exception &e) { out.active.reset(); out.error = e.what(); }
|
||||
return out;
|
||||
}
|
||||
void publish_selection(const fs::path &root, const std::optional<std::string> &active, const std::string &transaction) {
|
||||
editor::write_atomic(root / selection_file, Json{{"schema", "openbmh-ui-active-mod@1"},
|
||||
{"active", active ? Json(*active) : Json()}, {"transaction", transaction}}.dump(2));
|
||||
}
|
||||
void selection_matches(const fs::path &root, const std::string &token) {
|
||||
if (token.empty() || selection(root).token != token) throw editor::Error("Die aktive Mod-Auswahl wurde inzwischen geändert.");
|
||||
}
|
||||
void recover(const fs::path &root) {
|
||||
const auto file = root / journal_file;
|
||||
if (!fs::exists(fs::symlink_status(file))) return;
|
||||
const auto journal = Json::parse(regular(file, 1024 * 1024));
|
||||
if (journal.at("schema").get<std::string>() != "openbmh-ui-mod-transaction@1") throw editor::Error("Ungültiges Mod-Transaktionsjournal.");
|
||||
const auto from = journal.at("from").get<std::string>(); member_name(from);
|
||||
const auto to = journal.at("to").get<std::string>();
|
||||
const auto nonce = journal.at("nonce").get<std::string>();
|
||||
const auto operation = journal.at("operation").get<std::string>();
|
||||
if (nonce.empty() || nonce.find_first_not_of("0123456789abcdef") != nonce.npos || nonce.size() != 64)
|
||||
throw editor::Error("Ungültige Mod-Transaktionskennung.");
|
||||
if (operation == "rename") UiModLibrary::clean_name(to);
|
||||
else if (operation != "remove" || to != ".ui-trash-" + nonce) throw editor::Error("Ungültiges Mod-Transaktionsziel.");
|
||||
const auto old_path = root / "mods" / editor::path(from), new_path = root / "mods" / editor::path(to);
|
||||
const auto intermediate = root / "mods" / (".ui-rename-" + nonce);
|
||||
const auto rollback = root / "mods" / (".ui-rollback-" + nonce);
|
||||
directory(root / "mods");
|
||||
if (fs::is_symlink(fs::symlink_status(old_path)) || fs::is_symlink(fs::symlink_status(new_path)) || fs::is_symlink(fs::symlink_status(intermediate)))
|
||||
throw editor::Error("Unsichere Mod-Wiederherstellung.");
|
||||
const bool committed = selection(root).transaction == nonce;
|
||||
const auto candidate = fs::exists(new_path) ? new_path : fs::exists(intermediate) ? intermediate : rollback;
|
||||
if (!committed && fs::exists(candidate)) {
|
||||
std::error_code equivalent_error;
|
||||
const bool same = fs::equivalent(old_path, candidate, equivalent_error);
|
||||
if ((fs::exists(old_path) && (equivalent_error || !same)) || fingerprint(candidate) != journal.at("token").get<std::string>())
|
||||
throw editor::Error("Mod-Wiederherstellung benötigt eine manuelle Prüfung; Daten bleiben erhalten.");
|
||||
if (candidate != rollback) {
|
||||
if (fs::exists(rollback)) throw editor::Error("Mod-Rollback benötigt eine manuelle Prüfung.");
|
||||
fs::rename(candidate, rollback);
|
||||
}
|
||||
fs::rename(rollback, old_path);
|
||||
}
|
||||
if (committed && operation == "remove") { std::error_code error; fs::remove_all(new_path, error); }
|
||||
std::error_code error; fs::remove(file, error);
|
||||
if (error) throw editor::Error("Das Mod-Transaktionsjournal konnte nicht aufgeräumt werden.");
|
||||
}
|
||||
void available(const fs::path &root, const std::string &name, const std::string &except = {}) {
|
||||
directory(root / "mods");
|
||||
if (!fs::exists(root / "mods")) return;
|
||||
for (const auto &entry : fs::directory_iterator(root / "mods")) {
|
||||
const auto current = editor::utf8(entry.path().filename());
|
||||
if (current == except || current.starts_with('.')) continue;
|
||||
bool conflict = false;
|
||||
try { conflict = member_key(current) == UiModLibrary::name_key(name); } catch (const std::exception &) {}
|
||||
if (conflict) throw editor::Error("Diese Mod-Bezeichnung wird bereits verwendet.");
|
||||
}
|
||||
}
|
||||
UiModEntry entry(const fs::path &root, const std::string &name) {
|
||||
UiModEntry row; row.id = row.name = name; row.path = root / "mods" / editor::path(name);
|
||||
try {
|
||||
row.token = content::sha256("member:" + name + ":" + fingerprint(row.path));
|
||||
member_name(name);
|
||||
if (!fs::is_directory(row.path)) throw editor::Error("Kein Mod-Verzeichnis.");
|
||||
for (const auto &file : fs::directory_iterator(row.path))
|
||||
if (file.path().filename() != "content.obw" && file.path().filename() != "mod.json")
|
||||
throw editor::Error("Unerwartete Datei im Mod-Verzeichnis.");
|
||||
const auto checked = package(row.path / "content.obw");
|
||||
const auto token = row.token;
|
||||
row = checked.metadata; row.id = row.name = name; row.path = root / "mods" / editor::path(name); row.token = token;
|
||||
if (fs::exists(row.path / "mod.json")) {
|
||||
const auto profile = Json::parse(regular(row.path / "mod.json", 1024 * 1024));
|
||||
if (profile.value("schema", "") != "openbmh-mod@1.0") throw editor::Error("Ungültiges Mod-Profil.");
|
||||
// Authored profile hints never override the verified package type.
|
||||
if (profile.contains("content_id") && profile.at("content_id").get<std::string>() != row.content_id)
|
||||
throw editor::Error("Mod-Profil und geprüfter Inhalt stimmen nicht überein.");
|
||||
}
|
||||
} catch (const std::exception &e) { row.error = e.what(); }
|
||||
return row;
|
||||
}
|
||||
UiModEntry owned(const fs::path &root, const UiModEntry &expected, bool require_valid) {
|
||||
if (expected.id != expected.name || expected.path != root / "mods" / editor::path(expected.id))
|
||||
throw editor::Error("Die Mod gehört nicht zu dieser Bibliothek.");
|
||||
member_name(expected.id);
|
||||
if (fs::is_symlink(fs::symlink_status(expected.path)) || !fs::is_directory(expected.path))
|
||||
throw editor::Error("Unsicheres oder fehlendes Mod-Verzeichnis.");
|
||||
const auto actual = entry(root, expected.id);
|
||||
if (expected.token.empty() || actual.token != expected.token) throw editor::Error("Diese Mod wurde inzwischen geändert. Bitte erneut auswählen.");
|
||||
if (require_valid && !actual.valid()) throw editor::Error(actual.error);
|
||||
return actual;
|
||||
}
|
||||
void transact(const fs::path &root, const UiModEntry &old, const std::string &to,
|
||||
const std::string &operation, const std::optional<std::string> &active, const std::string &nonce) {
|
||||
const Json journal = {{"schema", "openbmh-ui-mod-transaction@1"}, {"from", old.name},
|
||||
{"to", to}, {"operation", operation}, {"nonce", nonce}, {"token", fingerprint(old.path)}};
|
||||
editor::write_atomic(root / journal_file, journal.dump(2), false);
|
||||
try {
|
||||
if (operation == "rename") {
|
||||
const auto intermediate = root / "mods" / (".ui-rename-" + nonce);
|
||||
fs::rename(old.path, intermediate);
|
||||
fs::rename(intermediate, root / "mods" / editor::path(to));
|
||||
} else fs::rename(old.path, root / "mods" / editor::path(to));
|
||||
publish_selection(root, active, nonce);
|
||||
} catch (...) {
|
||||
recover(root);
|
||||
throw;
|
||||
}
|
||||
// The selection nonce is the commit point. Cleanup never undoes that commit.
|
||||
recover(root);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
struct ModImportPlan::Payload {
|
||||
UiModEntry metadata;
|
||||
fs::path source, original_exe;
|
||||
std::string token;
|
||||
int start_year = 2026;
|
||||
std::shared_ptr<editor::ArchiveStore> archive;
|
||||
};
|
||||
UiModLibrary::UiModLibrary(fs::path root) : root_(fs::weakly_canonical(fs::absolute(std::move(root)))) {}
|
||||
std::string UiModLibrary::clean_name(const std::string &raw) {
|
||||
const auto name = DemoFiles::clean_name(raw);
|
||||
if (name.size() > 240 || name.front() == '.' || name.back() == '.' || name.find_first_of("/\\:*?\"<>|") != name.npos)
|
||||
throw editor::Error("Bitte einen portablen Mod-Namen ohne Sonderzeichen oder abschließenden Punkt verwenden.");
|
||||
const auto stem = DemoFiles::name_key(name.substr(0, name.find('.')));
|
||||
const std::set<std::string> reserved = {"con", "prn", "aux", "nul", "com1", "com2", "com3", "com4", "com5", "com6", "com7", "com8", "com9", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9"};
|
||||
if (reserved.contains(stem)) throw editor::Error("Dieser Mod-Name ist vom Betriebssystem reserviert.");
|
||||
return name;
|
||||
}
|
||||
std::string UiModLibrary::name_key(const std::string &name) { return DemoFiles::name_key(clean_name(name)); }
|
||||
ModSnapshot UiModLibrary::snapshot() const {
|
||||
ModSnapshot result;
|
||||
try {
|
||||
directory(root_); directory(root_ / "mods");
|
||||
if (fs::exists(root_ / journal_file)) { Lock lock(root_); recover(root_); }
|
||||
if (fs::exists(root_ / ".ui-mod-lock")) throw editor::Error("Die Mod-Bibliothek ist gerade belegt.");
|
||||
const auto selected = selection(root_); result.selection_token = selected.token; result.error = selected.error;
|
||||
if (fs::exists(root_ / "mods"))
|
||||
for (const auto &file : fs::directory_iterator(root_ / "mods")) {
|
||||
const auto name = editor::utf8(file.path().filename());
|
||||
if (!name.starts_with('.')) result.entries.push_back(entry(root_, name));
|
||||
}
|
||||
std::sort(result.entries.begin(), result.entries.end(), [](const auto &a, const auto &b) { return a.name < b.name; });
|
||||
if (selected.active) {
|
||||
auto found = std::find_if(result.entries.begin(), result.entries.end(), [&](const auto &row) { return row.id == *selected.active && row.valid(); });
|
||||
if (found != result.entries.end()) { found->active = true; result.active = found->id; }
|
||||
else if (result.error.empty()) result.error = "Die gespeicherte aktive Mod fehlt oder ist ungültig; keine Mod ist aktiviert.";
|
||||
}
|
||||
} catch (const std::exception &e) { result.error = e.what(); }
|
||||
return result;
|
||||
}
|
||||
ModImportPlan UiModLibrary::inspect(const fs::path &input, int start_year) const {
|
||||
if (start_year < 1900 || start_year > 9998) throw editor::Error("Ungültiges Startjahr.");
|
||||
const auto source = fs::absolute(input).lexically_normal();
|
||||
if (fs::is_symlink(fs::symlink_status(source))) throw editor::Error("Verknüpfte Mod-Quellen werden nicht übernommen.");
|
||||
auto state = std::make_shared<ModImportPlan::Payload>(); state->source = source; state->start_year = start_year;
|
||||
state->token = fingerprint(source);
|
||||
fs::path content = source;
|
||||
if (fs::is_directory(source) && fs::exists(source / "content.obw")) content /= "content.obw";
|
||||
const bool world = fs::is_regular_file(content) && editor::folded(editor::utf8(content.extension())) != ".exe";
|
||||
if (world || (fs::is_directory(content) && fs::exists(content / "manifest.json"))) {
|
||||
auto checked = package(content); state->archive = std::move(checked.archive); state->metadata = checked.metadata;
|
||||
} else {
|
||||
const auto checked = launch::check_game_directory(source);
|
||||
if (checked.family == launch::GameFamily::unknown || checked.family == launch::GameFamily::disk1994 ||
|
||||
!checked.unsupported.empty() || !checked.problems.empty()) {
|
||||
std::string error = "Originalinstallation nicht unterstützt oder unvollständig.";
|
||||
if (!checked.unsupported.empty()) error += " " + checked.unsupported;
|
||||
for (const auto &problem : checked.problems) error += "\n" + problem;
|
||||
throw editor::Error(error);
|
||||
}
|
||||
if (fs::is_directory(source) && launch::find_file(checked.directory, "BMH.EXE") && launch::find_file(checked.directory, "FLTD.EXE"))
|
||||
throw editor::Error("Mehrdeutige Originalinstallation; bitte die gewünschte EXE auswählen.");
|
||||
state->source = checked.directory; state->original_exe = checked.exe; state->token = fingerprint(state->source);
|
||||
auto &row = state->metadata; row.type = "Classic";
|
||||
row.source = checked.family == launch::GameFamily::english ? "FTLD" : "BMH";
|
||||
row.name = row.source == "FTLD" ? "FLTD-classic" : "BMH-classic";
|
||||
row.version = "Originalimport"; row.description = checked.title; row.format = "legacy-source";
|
||||
for (const auto &file : fs::recursive_directory_iterator(state->source)) if (file.is_regular_file()) { ++row.file_count; row.bytes += file.file_size(); }
|
||||
}
|
||||
if (fingerprint(state->source) != state->token) throw editor::Error("Die Quelle wurde während der Prüfung geändert.");
|
||||
ModImportPlan plan; plan.metadata = state->metadata; plan.source = source; plan.source_token = state->token; plan.start_year = start_year; plan.payload_ = std::move(state); return plan;
|
||||
}
|
||||
UiModEntry UiModLibrary::commit(const ModImportPlan &plan, const std::string &raw_name, const ModProgress &progress) {
|
||||
const auto name = clean_name(raw_name);
|
||||
if (!plan.payload_) throw editor::Error("Der Importplan fehlt.");
|
||||
const auto &state = *plan.payload_;
|
||||
if (fingerprint(state.source) != state.token) throw editor::Error("Die Importquelle wurde inzwischen geändert. Bitte erneut auswählen.");
|
||||
directory(root_); available(root_, name);
|
||||
Temp temporary; const auto prepared = temporary.path / "content.obw";
|
||||
if (progress) progress("Inhalte werden geprüft und vorbereitet …");
|
||||
if (state.archive) state.archive->save(prepared, {}, {});
|
||||
else {
|
||||
launch::AddMod request; request.source = state.original_exe; request.name = "prepared"; request.start_year = state.start_year; request.migrate = false;
|
||||
const auto converted = launch::ModLibrary(temporary.path).add(request, {}, progress);
|
||||
fs::copy_file(converted.mod.directory / "content.obw", prepared);
|
||||
}
|
||||
const auto checked = package(prepared);
|
||||
Lock lock(root_); recover(root_); available(root_, name); directory(root_ / "mods", true);
|
||||
const auto staging = root_ / "mods" / editor::path(editor::new_id(".ui-import-"));
|
||||
if (!fs::create_directory(staging)) throw editor::Error("Mod-Zwischenablage konnte nicht angelegt werden.");
|
||||
struct Cleanup { fs::path path; ~Cleanup() { std::error_code error; fs::remove_all(path, error); } } cleanup{staging};
|
||||
fs::copy_file(prepared, staging / "content.obw");
|
||||
// The existing Classic launcher owns a content-only directory contract.
|
||||
// Its verified package already contains all metadata needed by this UI.
|
||||
if (checked.metadata.type == "Modern")
|
||||
editor::write_atomic(staging / "mod.json", Json{{"schema", "openbmh-mod@1.0"}, {"name", name},
|
||||
{"type", checked.metadata.type}, {"content_id", checked.metadata.content_id}, {"source", checked.metadata.source}}.dump(2));
|
||||
if (progress) progress("Mod wird in die Bibliothek übernommen …");
|
||||
if (fingerprint(state.source) != state.token) throw editor::Error("Die Importquelle wurde während der Vorbereitung geändert.");
|
||||
available(root_, name);
|
||||
fs::rename(staging, root_ / "mods" / editor::path(name));
|
||||
return entry(root_, name);
|
||||
}
|
||||
void UiModLibrary::activate(const UiModEntry &expected, const std::string &token) {
|
||||
Lock lock(root_); recover(root_); directory(root_ / "mods");
|
||||
const auto current = owned(root_, expected, true); selection_matches(root_, token);
|
||||
publish_selection(root_, current.id, content::sha256(editor::new_id("activate-")));
|
||||
}
|
||||
void UiModLibrary::deactivate(const std::string &token) {
|
||||
Lock lock(root_); recover(root_); selection_matches(root_, token);
|
||||
publish_selection(root_, {}, content::sha256(editor::new_id("deactivate-")));
|
||||
}
|
||||
UiModEntry UiModLibrary::rename(const UiModEntry &expected, const std::string &raw_name, const std::string &token) {
|
||||
const auto name = clean_name(raw_name);
|
||||
Lock lock(root_); recover(root_); directory(root_ / "mods");
|
||||
const auto current = owned(root_, expected, false); selection_matches(root_, token);
|
||||
if (name == current.name) return current;
|
||||
available(root_, name, current.name);
|
||||
auto active = selection(root_).active; if (active == current.id) active = name;
|
||||
transact(root_, current, name, "rename", active, content::sha256(editor::new_id("rename-")));
|
||||
return entry(root_, name);
|
||||
}
|
||||
void UiModLibrary::remove(const UiModEntry &expected, const std::string &token) {
|
||||
Lock lock(root_); recover(root_); directory(root_ / "mods");
|
||||
const auto current = owned(root_, expected, false); selection_matches(root_, token);
|
||||
auto active = selection(root_).active; if (active == current.id) active.reset();
|
||||
const auto nonce = content::sha256(editor::new_id("remove-"));
|
||||
transact(root_, current, ".ui-trash-" + nonce, "remove", active, nonce);
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,55 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "modern/ui/catalog.hpp"
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
struct UiModEntry {
|
||||
// IDs are current library directory names. Rename returns the new identity.
|
||||
// path is always the installed MOD DIRECTORY; its package is path/content.obw.
|
||||
std::string id, name, type, source, version, description, format, content_id;
|
||||
std::string token, error;
|
||||
fs::path path;
|
||||
uint64_t file_count = 0, bytes = 0;
|
||||
bool active = false;
|
||||
bool valid() const { return error.empty(); }
|
||||
};
|
||||
struct ModSnapshot {
|
||||
std::vector<UiModEntry> entries;
|
||||
std::optional<std::string> active;
|
||||
std::string selection_token, error;
|
||||
};
|
||||
struct ModImportPlan {
|
||||
// Suggested name and validated source details. This is not yet a member:
|
||||
// metadata.id/path stay empty until commit. Public metadata is display-only.
|
||||
UiModEntry metadata;
|
||||
fs::path source;
|
||||
std::string source_token;
|
||||
int start_year = 2026;
|
||||
private:
|
||||
struct Payload;
|
||||
std::shared_ptr<const Payload> payload_;
|
||||
friend class UiModLibrary;
|
||||
};
|
||||
using ModProgress = std::function<void(const std::string &)>;
|
||||
class UiModLibrary {
|
||||
public:
|
||||
// portable_root contains mods/ and .ui-active-mod.json, never source content.
|
||||
explicit UiModLibrary(fs::path portable_root);
|
||||
static std::string clean_name(const std::string &);
|
||||
static std::string name_key(const std::string &);
|
||||
ModSnapshot snapshot() const;
|
||||
ModImportPlan inspect(const fs::path &, int start_year = 2026) const;
|
||||
UiModEntry commit(const ModImportPlan &, const std::string &name,
|
||||
const ModProgress &progress = {});
|
||||
void activate(const UiModEntry &, const std::string &selection_token);
|
||||
void deactivate(const std::string &selection_token);
|
||||
UiModEntry rename(const UiModEntry &, const std::string &name,
|
||||
const std::string &selection_token);
|
||||
void remove(const UiModEntry &, const std::string &selection_token);
|
||||
const fs::path &root() const { return root_; }
|
||||
private:
|
||||
fs::path root_;
|
||||
};
|
||||
} // namespace bmh::modern_ui
|
||||
+20
-97
@@ -26,6 +26,9 @@
|
||||
#include "modern/ui/demo_files.hpp"
|
||||
#include "modern/ui/gui_assets.hpp"
|
||||
#include "modern/ui/model.hpp"
|
||||
#include "modern/ui/mod_library.hpp"
|
||||
#include <future>
|
||||
#include <mutex>
|
||||
#include "modern/ui/ticket_popover.hpp"
|
||||
#include "modern/ui/view.hpp"
|
||||
#include "version.hpp"
|
||||
@@ -426,6 +429,7 @@ class App final : public Rml::EventListener {
|
||||
#include "modern/ui/settings_state.inc"
|
||||
#include "modern/ui/widgets_state.inc"
|
||||
#include "modern/ui/files_state.inc"
|
||||
#include "modern/ui/front_state.inc"
|
||||
std::map<std::string, std::string> selections_;
|
||||
Rml::Element *element(const std::string &id) const {
|
||||
return doc_->GetElementById(id);
|
||||
@@ -568,31 +572,10 @@ class App final : public Rml::EventListener {
|
||||
dirty_ = true;
|
||||
}
|
||||
void collect_mods() {
|
||||
mods_.clear();
|
||||
const auto folder = root_ / "mods";
|
||||
if (!fs::exists(folder))
|
||||
return;
|
||||
for (const auto &entry : fs::directory_iterator(folder)) {
|
||||
if (!entry.is_directory() || entry.is_symlink() ||
|
||||
editor::utf8(entry.path().filename()).starts_with('.'))
|
||||
continue;
|
||||
Mod m{editor::utf8(entry.path().filename()),
|
||||
"",
|
||||
{},
|
||||
entry.path() / "content.obw",
|
||||
{}};
|
||||
try {
|
||||
auto store = editor::ArchiveStore::open(m.file);
|
||||
m.manifest = Json::parse(store->read("manifest.json"));
|
||||
m.type = Catalog::modern_manifest(m.manifest) ? "Modern" : "Classic";
|
||||
} catch (const std::exception &e) {
|
||||
m.error = e.what();
|
||||
m.type = "Unbekannt";
|
||||
}
|
||||
mods_.push_back(std::move(m));
|
||||
}
|
||||
std::sort(mods_.begin(), mods_.end(),
|
||||
[](const auto &a, const auto &b) { return a.name < b.name; });
|
||||
front_snapshot_=UiModLibrary(front_library_root()).snapshot();mods_.clear();
|
||||
for(const auto &entry:front_snapshot_.entries)mods_.push_back({entry.name,entry.type,entry.error,entry.path/"content.obw",Json::object()});
|
||||
active_mod_=front_external_override_?"":front_snapshot_.active.value_or("");
|
||||
if(!front_selected())selected_mod_=front_snapshot_.entries.empty()?"":front_snapshot_.entries.front().id;
|
||||
}
|
||||
Mod *mod(const std::string &name) {
|
||||
for (auto &m : mods_)
|
||||
@@ -649,74 +632,8 @@ class App final : public Rml::EventListener {
|
||||
: world_->leagues("nation:de").front()->value("id", "");
|
||||
selected_club_ = manager(snap()).value("club", "");
|
||||
}
|
||||
std::string main_menu() {
|
||||
const auto *m = mod(active_mod_);
|
||||
std::string out =
|
||||
"<div class=\"fill front-shade\"></div><div "
|
||||
"class=\"brand\"><p>FUSSBALLMANAGER</p><h1>Open<span>BMH</span></h1></"
|
||||
"div><div class=\"main-options\">";
|
||||
const std::array<std::pair<std::string, std::string>, 6> actions = {
|
||||
{{"new", "Neues Spiel"},
|
||||
{"load", "Spiel laden"},
|
||||
{"network", "Netzwerk"},
|
||||
{"mods", "Mod"},
|
||||
{"settings", "Einstellungen"},
|
||||
{"exit", "Beenden"}}};
|
||||
for (const auto &[key, name] : actions)
|
||||
out += btn(
|
||||
key,
|
||||
(key == "network" ? "<span>" + esc(name) + "</span>" : esc(name)) +
|
||||
(key == "network" ? "<small>Demnächst</small>" : ""),
|
||||
{},
|
||||
key == "network" || (key == "new" && !m && !world_) ? "disabled"
|
||||
: "");
|
||||
out +=
|
||||
"</div><div class=\"front-footer\"><div><small>Aktive Mod</small><p>" +
|
||||
esc(m ? m->name
|
||||
: world_ ? world_->title()
|
||||
: "Keine Mod aktiviert") +
|
||||
"</p></div><small>v" + std::string(kOpenBmhVersion) +
|
||||
(m && m->type == "Classic" ? "" : " · Modern UI Demo") +
|
||||
"</small></div>";
|
||||
return out;
|
||||
}
|
||||
std::string mods_page() {
|
||||
if (selected_mod_.empty() && !mods_.empty())
|
||||
selected_mod_ = mods_.front().name;
|
||||
std::string left = "<h3 style=\"padding:28dp;\">Installierte Mods</h3><div "
|
||||
"class=\"list\" style=\"height:1310dp;\">";
|
||||
for (const auto &m : mods_)
|
||||
left += btn(
|
||||
"mod-select",
|
||||
"<span class=\"grow\">" + esc(m.name) + "</span><span>" +
|
||||
esc(m.type) + "</span>",
|
||||
std::string("row choice ") +
|
||||
(m.name == selected_mod_ ? "selected" : ""),
|
||||
"data-id=\"" + esc(m.name) +
|
||||
"\" style=\"width:100%;margin-bottom:12dp;min-height:120dp;\"");
|
||||
left += "</div>";
|
||||
std::string right;
|
||||
if (auto *m = mod(selected_mod_))
|
||||
right =
|
||||
"<div class=\"column\" style=\"padding:38dp;\">" +
|
||||
img("background", 1300, 400, false, true, 1600) + "<h2>" +
|
||||
esc(m->name) + "</h2><p class=\"muted\">" + esc(m->type) +
|
||||
(m->type == "Modern" ? " · Oberfläche bis zum Anstoß" : "") +
|
||||
"</p><p>" + esc(m->error) + "</p>" +
|
||||
btn("mod-activate", m->name == active_mod_ ? "Aktiv" : "Aktivieren",
|
||||
"primary", m->name == active_mod_ ? "disabled" : "") +
|
||||
"</div>";
|
||||
return window(
|
||||
"Mod",
|
||||
"<div class=\"row\" style=\"height:1560dp;align-items:stretch;\"><div "
|
||||
"class=\"panel\" style=\"width:1120dp;\">" +
|
||||
left + "</div><div class=\"panel grow\">" + right +
|
||||
"</div></div><div class=\"bottom-controls\">" +
|
||||
btn("import-modern", "OBW-Paket hinzufügen") +
|
||||
btn("import-classic", "BMH / Football Limited") +
|
||||
btn("mod-rename", "Umbenennen") + btn("mod-remove", "Löschen") +
|
||||
"</div>");
|
||||
}
|
||||
std::string main_menu();
|
||||
std::string mods_page();
|
||||
std::string render_desktop();
|
||||
void init_desktop();
|
||||
std::string widget(const std::string &, const Json &);
|
||||
@@ -1056,6 +973,7 @@ class App final : public Rml::EventListener {
|
||||
return true;
|
||||
}
|
||||
void frame() {
|
||||
front_poll();
|
||||
flush_selects();
|
||||
if (ticket_)
|
||||
ticket_->update();
|
||||
@@ -1098,6 +1016,7 @@ class App final : public Rml::EventListener {
|
||||
if (menu_ == "statistics") statistics_restore_scroll();
|
||||
if (menu_ == "settings") settings_after_render();
|
||||
files_after_render();
|
||||
front_after_render();
|
||||
if(menu_=="widgets" && widget_restore_scroll_){if(auto *gallery=element("widget-gallery"))gallery->SetScrollTop(widget_gallery_scroll_);widget_restore_scroll_=false;}
|
||||
if (!report_option_to_scroll_.empty()) {
|
||||
if (auto *node = element(report_option_to_scroll_))
|
||||
@@ -1261,14 +1180,14 @@ public:
|
||||
if (!config_.theme.empty()) theme_ = config_.theme;
|
||||
if (theme_ != "midnight" && theme_ != "silver" && theme_ != "matchday")
|
||||
throw editor::Error("Unbekanntes Modern-Theme.");
|
||||
front_external_override_=!config_.world.empty();
|
||||
collect_mods();
|
||||
if (!mods_.empty())
|
||||
active_mod_ = mods_.front().name;
|
||||
if(config_.world.empty() && config_.scene=="mods")scene_="mods";
|
||||
if (!config_.world.empty()) {
|
||||
active_mod_.clear();
|
||||
load_world(config_.world);
|
||||
scene_ = config_.scene;
|
||||
if (scene_ != "main" && scene_ != "newgame" && scene_ != "manager" &&
|
||||
if (scene_ != "main" && scene_ != "mods" && scene_ != "newgame" && scene_ != "manager" &&
|
||||
scene_ != "opening" && scene_ != "desktop") {
|
||||
menu_ = scene_;
|
||||
scene_ = "desktop";
|
||||
@@ -1325,6 +1244,7 @@ public:
|
||||
return 0;
|
||||
}
|
||||
while (!closed_) {
|
||||
front_poll();
|
||||
if (scene_ == "opening" && opening_page_ == 3 && draw_revealed_ < 64 &&
|
||||
draw_playing_ && SDL_GetTicks64() >= draw_at_ &&
|
||||
(SDL_GetWindowFlags(video_.window) & SDL_WINDOW_INPUT_FOCUS)) {
|
||||
@@ -1342,7 +1262,8 @@ public:
|
||||
bool got = SDL_WaitEventTimeout(&event, timeout) != 0;
|
||||
while (got) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
if (source_ && scene_ != "main") {
|
||||
if(front_busy_){front_feedback_="Bitte den laufenden Import abwarten.";dirty_=true;}
|
||||
else if (source_ && scene_ != "main" && scene_ != "mods") {
|
||||
quit_closes_app_=true;
|
||||
dispatch("context-quit", nullptr);
|
||||
} else
|
||||
@@ -1384,6 +1305,8 @@ public:
|
||||
#include "modern/ui/widgets_controls.inc"
|
||||
#include "modern/ui/files_screens.inc"
|
||||
#include "modern/ui/files_controls.inc"
|
||||
#include "modern/ui/front_screens.inc"
|
||||
#include "modern/ui/front_controls.inc"
|
||||
#include "modern/ui/screens.inc"
|
||||
#include "modern/ui/sports_screens.inc"
|
||||
#include "modern/ui/calendar_screen.inc"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
struct Config {
|
||||
std::filesystem::path world, gui_assets, screenshot, commands, state, preferences, userdata, file_import, file_export;
|
||||
std::filesystem::path world, gui_assets, screenshot, commands, state, preferences, userdata, file_import, file_export, mods, mod_import;
|
||||
std::string scene = "main", theme;
|
||||
int width = 1280, height = 720;
|
||||
};
|
||||
|
||||
@@ -113,7 +113,7 @@ int main(int argc, char **argv) try {
|
||||
std::ostringstream css;
|
||||
for (const auto *name : {"theme.rcss", "ticket.rcss", "sports.rcss",
|
||||
"calendar.rcss", "reports.rcss", "report_details.rcss",
|
||||
"report_pickers.rcss", "indoor.rcss", "planning.rcss", "almanac.rcss", "finance.rcss", "bank.rcss", "contracts.rcss", "amount.rcss", "environment.rcss", "advertising.rcss", "toto.rcss", "lineup.rcss", "transfer.rcss", "career_reports.rcss", "rankings.rcss", "stadium.rcss", "statistics.rcss", "news.rcss", "settings.rcss", "widgets.rcss", "files.rcss"}) {
|
||||
"report_pickers.rcss", "indoor.rcss", "planning.rcss", "almanac.rcss", "finance.rcss", "bank.rcss", "contracts.rcss", "amount.rcss", "environment.rcss", "advertising.rcss", "toto.rcss", "lineup.rcss", "transfer.rcss", "career_reports.rcss", "rankings.rcss", "stadium.rcss", "statistics.rcss", "news.rcss", "settings.rcss", "widgets.rcss", "files.rcss", "front.rcss"}) {
|
||||
std::ifstream input(root / name);
|
||||
require(bool(input), "Production stylesheet missing");
|
||||
css << input.rdbuf() << '\n';
|
||||
@@ -196,6 +196,10 @@ int main(int argc, char **argv) try {
|
||||
"<div class='desk-fixture'><div><span id='fixture-label'>Synthetic Club</span></div></div></div>";
|
||||
content += "<div id='gallery-scroll-test' class='modern-widget-gallery' style='left:2700dp;top:1500dp;width:900dp;height:200dp;max-height:200dp;'>"
|
||||
"<div style='position:relative;height:1000dp;'><article class='widget-gallery-item' style='top:600dp;'></article></div></div>";
|
||||
content += "<div class='main-options' style='left:40dp;top:2020dp;'>" +
|
||||
button_markup("load", "<span id='front-test-label'>Spiel laden</span><span class='front-hover-arrow'>›</span>", "front-menu-action", "id='front-test-button'") + "</div>"
|
||||
"<div class='front-mod-entry' style='position:absolute;left:2100dp;top:1800dp;width:1100dp;'>"
|
||||
"<span class='front-mod-copy'><strong id='mod-test-name'>Synthetic world</strong><small><span>OpenBMH</span></small></span><span class='front-mod-type'>Modern</span></div>";
|
||||
auto *doc = context->LoadDocumentFromMemory(
|
||||
"<rml><head><style>" + css.str() + "</style></head><body class='" +
|
||||
theme + "'>" + content + "</body></rml>");
|
||||
@@ -212,7 +216,7 @@ int main(int argc, char **argv) try {
|
||||
}
|
||||
require(doc->GetElementById("gallery-scroll-test")->GetScrollHeight() > doc->GetElementById("gallery-scroll-test")->GetClientHeight()*2,"Gallery content does not contribute to scroll extent");
|
||||
require(!center_selects(*doc), "Control centering does not settle");
|
||||
for (const auto *id : {"stats-scale-label", "stats-legend-label", "stats-player-label", "stats-world-label", "stats-from-label", "stats-winner-label", "news-brand-test", "settings-row-label", "settings-row-help", "month-label", "warning-label", "fixture-label"}) {
|
||||
for (const auto *id : {"stats-scale-label", "stats-legend-label", "stats-player-label", "stats-world-label", "stats-from-label", "stats-winner-label", "news-brand-test", "settings-row-label", "settings-row-help", "month-label", "warning-label", "fixture-label", "front-test-label", "mod-test-name"}) {
|
||||
auto *label = doc->GetElementById(id);
|
||||
require(label && label->GetBox().GetSize(Rml::BoxArea::Content).x > 0 && visible_text_lines(*label) > 0,
|
||||
"A production statistics/news label has collapsed or lost its font face");
|
||||
@@ -223,6 +227,7 @@ int main(int argc, char **argv) try {
|
||||
centered_text(*button, *button);
|
||||
}
|
||||
centered_text(*doc->GetElementById("month-label"), *doc->GetElementById("month-box"));
|
||||
centered_text(*doc->GetElementById("front-test-label"),*doc->GetElementById("front-test-button"),false);
|
||||
auto *list = doc->GetElementById("list");
|
||||
centered_text(*list, *list, false);
|
||||
auto *rich = doc->GetElementById("rich");
|
||||
|
||||
@@ -0,0 +1,404 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/mod_library.hpp"
|
||||
#include "editor/images.hpp"
|
||||
#include "import/obw.hpp"
|
||||
#include "import/classic.hpp"
|
||||
#include "content/package.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "launch/archive.hpp"
|
||||
#include "launch/mods.hpp"
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
using namespace bmh;
|
||||
using namespace bmh::modern_ui;
|
||||
namespace fixture {
|
||||
using J = bmh::cli::Json;
|
||||
// Generated records and effective tables reused from the public OBW test.
|
||||
|
||||
void check(bool condition, const std::string& message) {
|
||||
if (!condition) throw std::runtime_error(message);
|
||||
}
|
||||
template<class F> void rejects(F&& action, const std::string& message) {
|
||||
bool rejected = false;
|
||||
try { action(); } catch (const std::exception&) { rejected = true; }
|
||||
check(rejected, message);
|
||||
}
|
||||
void word(Bytes& data, size_t at, uint32_t value, size_t width = 2) {
|
||||
for (size_t i = 0; i < width; ++i) data.at(at + i) = uint8_t(value >> (i * 8));
|
||||
}
|
||||
void append(Bytes& data, uint32_t value, size_t width = 2) {
|
||||
for (size_t i = 0; i < width; ++i) data.push_back(uint8_t(value >> (i * 8)));
|
||||
}
|
||||
void save(const fs::path& path, const Bytes& bytes) {
|
||||
std::ofstream out(path, std::ios::binary);
|
||||
out.write(reinterpret_cast<const char*>(bytes.data()), std::streamsize(bytes.size()));
|
||||
check(bool(out), "write synthetic fixture");
|
||||
}
|
||||
|
||||
Database database(bool english) {
|
||||
Database db;
|
||||
db.club_names.resize(419);
|
||||
for (size_t i = 0; i < db.club_names.size(); ++i) db.club_names[i] = "Synthetic team " + std::to_string(i);
|
||||
db.club_names[0] = "Test M}nchen";
|
||||
db.club_names[357] = english ? "ENGLAND" : "DEUTSCHLAND";
|
||||
db.club_names[358] = english ? "GERMANY" : "SPANIEN";
|
||||
db.club_names[359] = english ? "ITALY" : "ENGLAND";
|
||||
db.club_names[360] = "FRANCE";
|
||||
db.club_names[361] = english ? "SPAIN" : "ITALIEN";
|
||||
if (english) db.club_names[150] = " ";
|
||||
db.players.resize(2574);
|
||||
for (size_t i = 0; i < db.players.size(); ++i)
|
||||
db.players[i] = {"Synthetic Player " + std::to_string(i), 60u | (90u << 7) | (80u << 14), 0x321, (6u << 21) | uint32_t(i % 4)};
|
||||
db.players[0].name = "T{st \"Name\"";
|
||||
db.players[1].w368 |= 1u << 27;
|
||||
db.raw_player_bonus_values.resize(3146);
|
||||
db.raw_player_bonus_values[1] = 128 | 17; // nationality 33, plus a bonus of 17
|
||||
db.raw_database_metadata.resize(100);
|
||||
db.raw_club_auxiliary_words.resize(168 * 2);
|
||||
db.raw_club_badge_selectors.resize(419 * 2);
|
||||
db.raw_foreign_club_strength.resize(251, 60);
|
||||
db.raw_league_auxiliary_bytes.resize(189);
|
||||
db.raw_referee_properties.resize(50);
|
||||
db.raw_club_kit_selectors.resize(419);
|
||||
db.raw_club_short_name_offsets.resize(168);
|
||||
db.squad_list.resize((3096 - 4) * 2 + 108);
|
||||
for (size_t i = 0; i < db.squad_list.size(); i += 2) word(db.squad_list, i, 4095);
|
||||
word(db.squad_list, 0, 0x8000); word(db.squad_list, 2, 1);
|
||||
word(db.squad_list, 90 * 24 * 2, 2); // first foreign squad, 16-slot stride
|
||||
word(db.squad_list, (2928 - 1) * 2, 3); // last squad
|
||||
db.referees = {"Synthetic Referee"};
|
||||
db.stadiums = {"Synthetic Stadium"};
|
||||
const auto pool = [](const std::vector<std::string>& names, Bytes& offsets) {
|
||||
Bytes result;
|
||||
for (const auto& name : names) {
|
||||
append(offsets, uint32_t(result.size()));
|
||||
result.insert(result.end(), name.begin(), name.end()); result.push_back(0);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
db.pools[0] = pool(db.club_names, db.raw_club_name_offsets);
|
||||
std::vector<std::string> names;
|
||||
for (const auto& player : db.players) names.push_back(player.name);
|
||||
db.pools[1] = pool(names, db.raw_player_name_offsets);
|
||||
Bytes unused;
|
||||
db.pools[2] = pool(db.referees, unused); db.pools[3] = pool(db.stadiums, unused);
|
||||
return db;
|
||||
}
|
||||
|
||||
LeImage executable(bool english) {
|
||||
constexpr uint32_t base = 0x10000;
|
||||
Bytes bytes(layout::GermanImageEnd - base);
|
||||
const auto put = [&](uint32_t address, uint32_t value, size_t width = 1) { word(bytes, address - base, value, width); };
|
||||
const int sizes[] = {english ? 20 : 18, english ? 20 : 18, english ? 20 : 18, english ? 20 : 18, english ? 10 : 18, 12, 12, 12, 12};
|
||||
for (uint32_t i = 0; i < 9; ++i) {
|
||||
put(layout::LeagueSizes + i, uint32_t(sizes[i]));
|
||||
put(layout::LeagueCalendarBits + i, english && i == 4 ? 31 : i);
|
||||
}
|
||||
if (!english) { put(layout::CareerSession_InstallLeagueSizes_RuntimeField3 + 4, 'A'); put(layout::CareerSession_InstallLeagueSizes_RuntimeField3 + 6, 'B'); }
|
||||
const std::vector<std::pair<int, uint32_t>> bindings = english ?
|
||||
std::vector<std::pair<int, uint32_t>>{{4, layout::EnglishFourTeamFixtureTable}, {6, layout::EnglishSixTeamFixtureTable},
|
||||
{12, layout::EnglishTwelveTeamFixtureTable}, {20, layout::EnglishTwentyTeamFixtureTable}} :
|
||||
std::vector<std::pair<int, uint32_t>>{{4, layout::CareerSession_RuntimeError_RuntimeField}, {6, layout::CareerSession_RuntimeError_RuntimeField2},
|
||||
{12, layout::CareerSession_RuntimeError_RuntimeField3}, {16, layout::CareerSession_RuntimeError_ExecutableField3},
|
||||
{18, layout::CareerSession_RuntimeError_ExecutableField}, {20, layout::CareerSession_RuntimeError_ExecutableField2}};
|
||||
uint32_t cursor = layout::GermanImageEnd - 4096; // synthetic data storage, outside pointer tables
|
||||
for (const auto& [teams, address] : bindings) {
|
||||
put(address, cursor, 4); ++cursor;
|
||||
std::vector<int> order;
|
||||
for (int i = 0; i < teams; ++i) order.push_back(i);
|
||||
for (int round = 1; round < teams; ++round) {
|
||||
put(address + uint32_t(round * 4), cursor, 4);
|
||||
for (int i = 0; i < teams / 2; ++i) {
|
||||
put(cursor++, uint32_t('a' + order[size_t(i)]));
|
||||
put(cursor++, uint32_t('a' + order[size_t(teams - 1 - i)]));
|
||||
}
|
||||
++cursor;
|
||||
std::rotate(order.begin() + 1, order.end() - 1, order.end());
|
||||
}
|
||||
}
|
||||
put(layout::Career_BuildStadium_RuntimeField4 - 1, 2);
|
||||
put(base, 0xdeadbeef, 4); // an executable instruction region must never be exported
|
||||
for (uint32_t i = 0; i < 5; ++i) {
|
||||
put(layout::ClubPlayerDetail_ClubPlayerDetailRedraw_RuntimeField2 + i, 4);
|
||||
put(layout::ClubPlayerDetail_DrawPortrait_RuntimeField + i, 2 + i);
|
||||
put(layout::ClubPlayerDetail_DrawPortrait_RuntimeField2 + i, 3 + i);
|
||||
put(layout::ClubPlayerDetail_DrawPortrait_RuntimeField3 + i, 3);
|
||||
put(layout::ClubPlayerDetail_DrawPortrait_RuntimeField4 + i, 2);
|
||||
put(layout::ClubPlayerDetail_DrawPortrait_RuntimeField7 + i * 2, 20, 2);
|
||||
}
|
||||
put(layout::ClubPlayerDetail_DrawPortrait_RuntimeField, 253);
|
||||
put(layout::ClubPlayerDetail_DrawPortrait_RuntimeField3, 70);
|
||||
put(layout::ClubPlayerDetail_DrawPortrait_RuntimeField7, 319, 2);
|
||||
const std::string suffix = english ? " &" : " DM";
|
||||
for (size_t i = 0; i < suffix.size(); ++i) put(layout::CurrencySuffixText + uint32_t(i), uint8_t(suffix[i]));
|
||||
return LeImage::from_bytes(base, std::move(bytes));
|
||||
}
|
||||
|
||||
Bytes serialize(const Database& db) {
|
||||
Bytes bytes;
|
||||
for (const auto& pool : db.pools) append(bytes, uint32_t(pool.size()));
|
||||
const auto add = [&](const Bytes& data) { bytes.insert(bytes.end(), data.begin(), data.end()); };
|
||||
add(db.raw_player_bonus_values);
|
||||
for (const auto& pool : db.pools) add(pool);
|
||||
for (const auto* table : {&db.raw_club_name_offsets, &db.raw_player_name_offsets, &db.raw_database_metadata,
|
||||
&db.raw_club_auxiliary_words, &db.raw_club_badge_selectors, &db.raw_foreign_club_strength,
|
||||
&db.raw_league_auxiliary_bytes, &db.raw_referee_properties, &db.raw_club_kit_selectors, &db.raw_club_short_name_offsets, &db.squad_list}) add(*table);
|
||||
for (int table = 0; table < 3; ++table)
|
||||
for (const auto& player : db.players) append(bytes, table == 0 ? player.w35c : table == 1 ? player.w368 : player.w364, 4);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
} // namespace fixture
|
||||
|
||||
namespace {
|
||||
void require(bool condition, const char *message) { if (!condition) throw std::runtime_error(message); }
|
||||
template<class F> void rejected(F action, const char *message) {
|
||||
bool failed = false; try { action(); } catch (const std::exception &) { failed = true; }
|
||||
require(failed, message);
|
||||
}
|
||||
void write(const fs::path &root, const std::string &name, const Json &value) {
|
||||
fs::create_directories((root / name).parent_path()); editor::write_atomic(root / name, value.dump());
|
||||
}
|
||||
Json tree(const fs::path &root) {
|
||||
std::map<std::string, std::string> result;
|
||||
if (fs::exists(root)) for (const auto &file : fs::recursive_directory_iterator(root))
|
||||
if (file.is_regular_file() && !file.is_symlink()) result[editor::utf8(file.path().lexically_relative(root))] = content::sha256(editor::read_file(file.path()));
|
||||
return Json(result);
|
||||
}
|
||||
struct Fixture {
|
||||
fs::path root;
|
||||
Fixture() : root(fs::temp_directory_path() / editor::new_id("openbmh-ui-mods-test-")) { fs::create_directory(root); }
|
||||
~Fixture() { std::error_code error; fs::remove_all(root, error); }
|
||||
};
|
||||
void modern(const fs::path &path) {
|
||||
write(path, "manifest.json", {{"format", "openbmh-world"}, {"kind", "world"}, {"format_version", "1.1"},
|
||||
{"id", "world:synthetic-mod-library"}, {"title", "Synthetic world"}, {"version", "2.7"},
|
||||
{"description", "Synthetic modern library fixture"}, {"start_date", "2032-07-01"},
|
||||
{"requires", {"editor:world-v1"}}, {"x-editor", {{"profile", "editor-world-v1"}}}});
|
||||
write(path, "world/nations.json", {{"items", {{{"id", "nation:de"}, {"name", "Synthetic nation"}}}}});
|
||||
write(path, "world/competitions.json", {{"items", {{{"id", "competition:test"}, {"name", "Synthetic league"}, {"type", "league"}, {"nation", "nation:de"}}}}});
|
||||
write(path, "world/clubs.json", {{"items", {{{"id", "club:test"}, {"name", "Synthetic club"}, {"competition", "competition:test"}, {"nation", "nation:de"}}}}});
|
||||
write(path, "world/players.json", {{"items", Json::array()}});
|
||||
write(path, "assets/index.json", {{"items", Json::array()}});
|
||||
}
|
||||
fs::path classic(const fs::path &root, bool english) {
|
||||
const auto input = root / (english ? "synthetic-en" : "synthetic-de");
|
||||
fs::create_directories(input);
|
||||
const auto db = fixture::database(english);
|
||||
const auto exe = fixture::executable(english);
|
||||
TextDb texts; texts.strings.resize(TEXT_COUNT, "Synthetic text");
|
||||
const obw::Options options{"2032-07-01", "Synthetic Classic"};
|
||||
auto docs = obw::convert_database(db, texts, exe, english, options);
|
||||
const auto raw_db = fixture::serialize(db);
|
||||
constexpr char digits[] = "0123456789abcdef";
|
||||
std::string encoded; for (auto value : raw_db) { encoded += digits[value >> 4]; encoded += digits[value & 15]; }
|
||||
docs["x-legacy/source-database.json"] = Json{{"schema", "legacy-source@1.0"}, {"name", english ? "M3E.MAN" : "M3D.MAN"}, {"encoding", "hex"}, {"bytes", encoded}}.dump();
|
||||
Bytes raw_text(7); for (const auto &value : texts.strings) { raw_text.insert(raw_text.end(), value.begin(), value.end()); raw_text.push_back(0); }
|
||||
fixture::save(input / (english ? "TEXTE.BLK" : "TEXTD.BLK"), raw_text);
|
||||
fixture::save(input / "M3.MEN", Bytes(864, 7)); fixture::save(input / "M3.DAT", Bytes(1408, 9));
|
||||
fixture::save(input / "M3PC.COL", Bytes(768, 31));
|
||||
for (const auto *name : {"KB", "W", "F", "S"}) fs::create_directory(input / name);
|
||||
Bytes font(37, 0); fixture::word(font, 0, 1); font[3] = 2; fixture::word(font, 4, 1); font[8] = font[9] = 'A'; fixture::word(font, 16, 1); font[28] = 0x80; fixture::word(font, 31, 1); fixture::word(font, 35, 1);
|
||||
fixture::save(input / "F/BMH2.FNT", font); fixture::save(input / "F/BMH3.FNT", font);
|
||||
const Bytes bank{'F','O','R','M',8,0,0,0,'A','L','P','T','R','A','U','M'};
|
||||
for (const char *name : {"2000", "2001", "2002", "2003"}) fixture::save(input / "S" / name, bank);
|
||||
const auto image = [&](const fs::path &path) {
|
||||
Bytes bytes(8, 0), rle;
|
||||
for (int i = 0; i < 320 * 240; i += 128) { rle.push_back(127); for (int k = 0; k < 128; ++k) rle.push_back(uint8_t((i + k) % 251)); }
|
||||
rle.push_back(0); fixture::word(bytes, 0, 320); fixture::word(bytes, 2, 240); fixture::word(bytes, 4, uint32_t(rle.size()), 4);
|
||||
bytes.insert(bytes.end(), rle.begin(), rle.end()); fixture::save(path, bytes);
|
||||
};
|
||||
image(input / "KB/0.VGA"); image(input / "KB/29.VGA"); image(input / "W/0.VGA");
|
||||
obw::complete_classic(docs, input, db, exe, exe, english, options);
|
||||
content::seal(docs);
|
||||
const auto package = root / (english ? "classic-en.obw" : "classic-de.obw");
|
||||
content::write_archive(docs, package);
|
||||
return package;
|
||||
}
|
||||
void lifecycle() {
|
||||
Fixture fixture;
|
||||
const auto source = fixture.root / "source"; modern(source);
|
||||
const auto portable = fixture.root / "portable";
|
||||
UiModLibrary library(portable);
|
||||
require(library.snapshot().entries.empty() && !library.snapshot().active && !fs::exists(portable), "Empty library has implicit active mod or writes on read");
|
||||
auto plan = library.inspect(source);
|
||||
require(!fs::exists(portable), "Inspect or cancellation created library data");
|
||||
require(plan.metadata.type == "Modern" && plan.metadata.source == "OpenBMH" && plan.metadata.version == "2.7" &&
|
||||
plan.metadata.description == "Synthetic modern library fixture" && plan.metadata.file_count == 6 && plan.metadata.bytes > 0,
|
||||
"Modern metadata is not derived from actual package contents");
|
||||
require(plan.metadata.path.empty() && plan.metadata.id.empty(), "Import plan falsely claims installed membership");
|
||||
for (const std::string &name : std::vector<std::string>{"../outside", "CON.txt", "bad:name", ".hidden", "", std::string(65, 'x')})
|
||||
rejected([&] { library.commit(plan, name); }, "Invalid portable mod name accepted");
|
||||
require(!fs::exists(portable), "Invalid import name changed library");
|
||||
require(UiModLibrary::name_key("Öffnung") == UiModLibrary::name_key("o\xcc\x88" "FFNUNG") &&
|
||||
UiModLibrary::name_key("Straße") == UiModLibrary::name_key("STRASSE"), "Mod Unicode casefold differs from file UI");
|
||||
std::string unicode; for (int i = 0; i < 64; ++i) unicode += "Ä";
|
||||
require(UiModLibrary::clean_name(unicode) == unicode, "64 German Unicode characters rejected");
|
||||
plan.metadata.type = "Classic"; plan.source_token = "forged display token";
|
||||
const auto first = library.commit(plan, "Öffnung");
|
||||
require(first.valid() && first.type == "Modern" && first.path == library.root() / "mods" / editor::path("Öffnung"), "Commit trusted mutable display metadata or returned wrong directory");
|
||||
require(!library.snapshot().active, "Installation automatically activated a mod");
|
||||
const auto before_duplicate = tree(portable);
|
||||
rejected([&] { library.commit(plan, "o\xcc\x88" "FFNUNG"); }, "Casefold duplicate import accepted");
|
||||
require(tree(portable) == before_duplicate, "Duplicate import changed existing library");
|
||||
auto selected = library.snapshot(); library.activate(first, selected.selection_token);
|
||||
selected = UiModLibrary(portable).snapshot();
|
||||
require(selected.active == first.id && std::count_if(selected.entries.begin(), selected.entries.end(), [](const auto &r) { return r.active; }) == 1, "Active selection not exactly one after restart");
|
||||
const auto second = library.commit(library.inspect(source), "Second");
|
||||
rejected([&] { library.activate(second, before_duplicate.dump()); }, "Stale selection token accepted");
|
||||
require(library.snapshot().active == first.id, "Rejected activation changed active mod");
|
||||
selected = library.snapshot(); library.activate(second, selected.selection_token);
|
||||
require(UiModLibrary(portable).snapshot().active == second.id, "Replacement activation not persisted");
|
||||
selected = library.snapshot(); library.deactivate(selected.selection_token);
|
||||
require(!UiModLibrary(portable).snapshot().active, "Explicit no-active selection not persisted");
|
||||
selected = library.snapshot(); library.activate(first, selected.selection_token);
|
||||
fs::create_directories(portable / "userdata" / first.content_id);
|
||||
editor::write_atomic(portable / "userdata" / first.content_id / "keep.obs", "synthetic personal data");
|
||||
selected = library.snapshot();
|
||||
const auto renamed = library.rename(first, "ÖFFNUNG", selected.selection_token);
|
||||
require(renamed.valid() && library.snapshot().active == renamed.id && fs::exists(renamed.path / "content.obw"), "Case-only rename lost active selection");
|
||||
rejected([&] { library.remove(first, library.snapshot().selection_token); }, "Old membership token survived rename");
|
||||
const auto foreign = UiModLibrary(fixture.root / "other").commit(library.inspect(source), "Foreign");
|
||||
const auto stable = tree(portable);
|
||||
rejected([&] { library.remove(foreign, library.snapshot().selection_token); }, "Foreign library membership accepted");
|
||||
require(tree(portable) == stable, "Foreign deletion changed local files");
|
||||
selected = library.snapshot(); library.remove(renamed, selected.selection_token);
|
||||
require(!library.snapshot().active && fs::exists(portable / "userdata" / first.content_id / "keep.obs"), "Active deletion failed to clear selection or removed userdata");
|
||||
const auto before_stale = tree(portable);
|
||||
const auto stale = library.inspect(source);
|
||||
auto manifest = Json::parse(editor::read_file(source / "manifest.json")); manifest["description"] = "Changed after inspect";
|
||||
write(source, "manifest.json", manifest);
|
||||
rejected([&] { library.commit(stale, "Stale"); }, "Changed inspected source accepted");
|
||||
require(tree(portable) == before_stale, "Stale source import changed library");
|
||||
const auto changing = library.inspect(source);
|
||||
rejected([&] { library.commit(changing, "Changed during staging", [&](const std::string &progress) {
|
||||
if (progress.find("übernommen") != progress.npos) { manifest["description"] = "Changed during final progress"; write(source, "manifest.json", manifest); }
|
||||
}); }, "Source changed during staging was published");
|
||||
require(tree(portable) == before_stale, "Failed staged import left named or temporary library data");
|
||||
fs::create_directory(portable / ".ui-mod-lock");
|
||||
rejected([&] { library.deactivate(library.snapshot().selection_token); }, "Busy mutation ignored transaction lock");
|
||||
fs::remove(portable / ".ui-mod-lock");
|
||||
require(tree(portable) == before_stale, "Busy mutation changed library files");
|
||||
fs::create_directories(portable / "mods/Broken"); editor::write_atomic(portable / "mods/Broken/content.obw", "synthetic damaged archive");
|
||||
auto rows = library.snapshot().entries;
|
||||
auto broken = std::find_if(rows.begin(), rows.end(), [](const auto &row) { return row.name == "Broken"; });
|
||||
require(broken != rows.end() && !broken->valid(), "Invalid mod disappeared rather than showing an error row");
|
||||
rejected([&] { library.activate(*broken, library.snapshot().selection_token); }, "Invalid mod was activated");
|
||||
library.remove(*broken, library.snapshot().selection_token);
|
||||
require(!fs::exists(portable / "mods/Broken"), "Invalid owned mod cannot be removed safely");
|
||||
fs::create_directories(portable / "mods/BadProfile");
|
||||
fs::copy_file(second.path / "content.obw", portable / "mods/BadProfile/content.obw");
|
||||
editor::write_atomic(portable / "mods/BadProfile/mod.json", "{broken profile");
|
||||
rows = library.snapshot().entries;
|
||||
const auto bad_profile = std::find_if(rows.begin(), rows.end(), [](const auto &row) { return row.name == "BadProfile"; });
|
||||
require(bad_profile != rows.end() && !bad_profile->valid() && !bad_profile->token.empty(), "Malformed mod profile lost selectable membership token");
|
||||
library.remove(*bad_profile, library.snapshot().selection_token);
|
||||
fs::create_directory(portable / "mods" / std::string(130, 'x'));
|
||||
const auto installed_despite_error = library.commit(library.inspect(source), "Alongside error row");
|
||||
require(installed_despite_error.valid(), "Foreign non-normalizable error row blocked all imports");
|
||||
const auto selection_before_io = library.snapshot();
|
||||
fs::rename(portable / ".ui-active-mod.json", portable / "selection-preserved.json");
|
||||
fs::create_directory(portable / ".ui-active-mod.json");
|
||||
const auto blocked = tree(portable);
|
||||
rejected([&] { library.rename(second, "Blocked selection IO", selection_before_io.selection_token); }, "Selection IO failure did not reject mutation");
|
||||
require(tree(portable) == blocked && fs::exists(second.path), "Selection IO failure partially renamed/deleted a mod");
|
||||
fs::remove(portable / ".ui-active-mod.json");
|
||||
fs::rename(portable / "selection-preserved.json", portable / ".ui-active-mod.json");
|
||||
std::error_code symlink_error;
|
||||
fs::create_directory_symlink(second.path, portable / "mods/Linked", symlink_error);
|
||||
if (!symlink_error) {
|
||||
rows = library.snapshot().entries; const auto linked = std::find_if(rows.begin(), rows.end(), [](const auto &row) { return row.name == "Linked"; });
|
||||
require(linked != rows.end() && !linked->valid(), "Linked mod not reported as unsafe");
|
||||
rejected([&] { library.activate(*linked, library.snapshot().selection_token); }, "Linked member activated");
|
||||
rejected([&] { library.remove(*linked, library.snapshot().selection_token); }, "Deletion followed linked member");
|
||||
fs::remove(portable / "mods/Linked");
|
||||
}
|
||||
}
|
||||
void package_kinds() {
|
||||
Fixture fixture; const auto source = fixture.root / "world"; modern(source);
|
||||
const auto archive = fixture.root / "modern.obw";
|
||||
editor::ArchiveStore::open(source)->save(archive, {}, {});
|
||||
fs::copy_file(archive, fixture.root / "modern.zip");
|
||||
UiModLibrary library(fixture.root / "portable");
|
||||
require(library.inspect(fixture.root / "modern.zip").metadata.type == "Modern", "Modern ZIP unsupported");
|
||||
fs::create_directory(fixture.root / "hinted"); fs::copy_file(archive, fixture.root / "hinted/content.obw");
|
||||
write(fixture.root / "hinted", "mod.json", {{"schema", "openbmh-mod@1.0"}, {"type", "Classic"}});
|
||||
require(library.inspect(fixture.root / "hinted").metadata.type == "Modern", "Untrusted mod profile forced Classic classification");
|
||||
auto bad = Json::parse(editor::read_file(source / "manifest.json")); bad["requires"] = {"runtime:unknown-v9"};
|
||||
write(source, "manifest.json", bad);
|
||||
rejected([&] { library.inspect(source); }, "Unknown world requirement treated as supported");
|
||||
for (bool english : {false, true}) {
|
||||
const auto file = classic(fixture.root, english);
|
||||
const auto plan = library.inspect(file);
|
||||
require(plan.metadata.type == "Classic" && plan.metadata.source == (english ? "FTLD" : "BMH") && plan.metadata.content_id.size() == 64 && plan.metadata.file_count > 10 && plan.metadata.bytes > 1000, "Validated synthetic Classic metadata missing or guessed");
|
||||
const auto installed = library.commit(plan, english ? "English Classic" : "German Classic");
|
||||
require(installed.valid() && content::open(installed.path / "content.obw")->english == english, "Committed Classic package is not sealed/validated");
|
||||
require(!fs::exists(installed.path / "mod.json") &&
|
||||
std::distance(fs::directory_iterator(installed.path), fs::directory_iterator()) == 1,
|
||||
"Classic installation violated the content-only launcher contract");
|
||||
const auto launcher_rows = launch::ModLibrary(library.root()).list();
|
||||
const auto launcher_mod = std::find_if(launcher_rows.begin(), launcher_rows.end(), [&](const auto &row) { return row.name == installed.name; });
|
||||
require(launcher_mod != launcher_rows.end() && launcher_mod->error.empty() &&
|
||||
launcher_mod->type == "Classic" && launcher_mod->content_id == installed.content_id,
|
||||
"Existing0.2 launcher rejects the UI-imported sealed Classic mod");
|
||||
const auto old = tree(library.root());
|
||||
editor::ArchiveStore::open(file)->save(fixture.root / "tampered.obw", {{"x-classic/desktop-seed.bin", std::string(864, 'x')}}, {});
|
||||
rejected([&] { library.inspect(fixture.root / "tampered.obw"); }, "Unsealed/tampered Classic import accepted");
|
||||
require(tree(library.root()) == old, "Rejected Classic package changed library");
|
||||
const auto legacy_name = std::string(80, english ? 'E' : 'G');
|
||||
fs::create_directory(library.root() / "mods" / legacy_name);
|
||||
fs::copy_file(file, library.root() / "mods" / legacy_name / "content.obw");
|
||||
auto rows = library.snapshot().entries;
|
||||
const auto legacy = std::find_if(rows.begin(), rows.end(), [&](const auto &r) { return r.name == legacy_name; });
|
||||
require(legacy != rows.end() && legacy->valid(), "Existing0.2 content-only mod layout/name rejected");
|
||||
library.activate(*legacy, library.snapshot().selection_token);
|
||||
require(UiModLibrary(library.root()).snapshot().active == legacy_name, "Legacy active name not restart-safe");
|
||||
const auto renamed = library.rename(*legacy, english ? "English legacy" : "German legacy", library.snapshot().selection_token);
|
||||
require(renamed.valid() && library.snapshot().active == renamed.id, "Legacy mod cannot be renamed safely");
|
||||
}
|
||||
const auto original = fixture.root / "unsupported-original"; fs::create_directory(original);
|
||||
editor::write_atomic(original / "M3.EXE", "MZ synthetic unsupported original");
|
||||
const auto before = tree(library.root());
|
||||
rejected([&] { library.inspect(original); }, "Unsupported original edition treated as playable");
|
||||
require(tree(library.root()) == before, "Original inspect changed library before confirmation");
|
||||
}
|
||||
void write_fixtures(const fs::path &requested) {
|
||||
if (fs::is_symlink(fs::symlink_status(requested)) ||
|
||||
(fs::exists(requested) && (!fs::is_directory(requested) || !fs::is_empty(requested))))
|
||||
throw std::runtime_error("Fixture destination must be a new or empty directory");
|
||||
const auto output = fs::weakly_canonical(fs::absolute(requested));
|
||||
fs::create_directories(output);
|
||||
modern(output / "modern-directory");
|
||||
editor::ArchiveStore::open(output / "modern-directory")->save(output / "modern.obw", {}, {});
|
||||
fs::copy_file(output / "modern.obw", output / "modern.zip");
|
||||
fs::create_directory(output / "modern-mod");
|
||||
fs::copy_file(output / "modern.obw", output / "modern-mod/content.obw");
|
||||
write(output / "modern-mod", "mod.json", {{"schema", "openbmh-mod@1.0"}, {"type", "Modern"}});
|
||||
const auto german = classic(output, false), english = classic(output, true);
|
||||
require(!content::open(german)->english && content::open(english)->english,
|
||||
"Synthetic fixture Classic editions failed validation");
|
||||
write(output, "fixtures.json", {{"schema", "openbmh-synthetic-mod-fixtures@1"},
|
||||
{"proprietary_data", false}, {"engine_started", false},
|
||||
{"modern_directory", "modern-directory"}, {"modern_obw", "modern.obw"},
|
||||
{"modern_zip", "modern.zip"}, {"modern_mod_directory", "modern-mod"},
|
||||
{"classic_german", "classic-de.obw"}, {"classic_english", "classic-en.obw"},
|
||||
{"note", "synthetic-de/en are generation inputs, not complete original installations"},
|
||||
{"file_hashes", tree(output)}});
|
||||
std::cout << "Wrote synthetic Modern and sealed Classic DE/EN fixtures to " << editor::utf8(output) << '\n';
|
||||
}
|
||||
} // namespace
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
const auto args = launch::utf8_arguments(argc, argv);
|
||||
if (args.size() == 3 && args[1] == "--write-fixtures") {
|
||||
write_fixtures(editor::path(args[2])); return 0;
|
||||
}
|
||||
if (args.size() != 1) throw std::runtime_error("usage: modern_mods_ui_tests [--write-fixtures DIR]");
|
||||
lifecycle(); package_kinds(); std::cout << "PASS native mod library: staged import, Modern/sealed Classic metadata, 0/1 active persistence, Unicode conflicts, stale guards, ownership, rollback and retained userdata\n"; return 0;
|
||||
}
|
||||
catch (const std::exception &e) { std::cerr << e.what() << '\n'; return 1; }
|
||||
}
|
||||
Reference in new issue
Block a user