Règles des systèmes en deux langues ; import de campagne dans la langue de l'UI
Qualité & Sécurité / Web (ESLint · angular-eslint + sonarjs) (push) Successful in 35s
Qualité & Sécurité / Trivy (CVE dépendances Maven / pip / npm) (push) Failing after 50s
Qualité & Sécurité / MegaLinter (PMD · Ruff · Bandit · gitleaks · hadolint) (push) Failing after 1m26s
Qualité & Sécurité / Web (ESLint · angular-eslint + sonarjs) (push) Successful in 35s
Qualité & Sécurité / Trivy (CVE dépendances Maven / pip / npm) (push) Failing after 50s
Qualité & Sécurité / MegaLinter (PMD · Ruff · Bandit · gitleaks · hadolint) (push) Failing after 1m26s
- Règles d'un système de jeu stockées en français et en anglais (migration V28, rules_markdown_en). L'import d'un PDF garde l'extraction fidèle dans la langue du livre (détectée) et traduit section par section vers l'autre langue, noms propres conservés ; la progression de la traduction s'affiche. Un échec de traduction n'annule pas l'import. - Éditeur du système : onglets Français / English ; l'import remplit les deux. Règles en séance et contexte de l'IA : version de la langue de l'interface, avec repli sur l'autre si elle est vide. - Import de campagne : textes rédigés (ou traduits) dans la langue de l'interface ; titres et noms propres conservés tels quels ; arc par défaut nommé dans la bonne langue. - Les règles anglaises suivent l'export/import de sauvegarde. Vérifié : brain (détection, découpe, traduction, flux d'import, langue de l'import de campagne), core clean verify (1299 tests), web build + vitest + lint. Traduction non essayée avec un vrai modèle.
This commit is contained in:
@@ -75,6 +75,18 @@
|
||||
<p class="import-error">{{ importError }}</p>
|
||||
}
|
||||
|
||||
<!-- Règles en deux langues : un onglet par version (l'import d'un PDF remplit les deux). -->
|
||||
<div class="rules-langs" role="tablist" [attr.aria-label]="'gameSystemEdit.langTabs' | translate">
|
||||
@for (lang of rulesLangs; track lang) {
|
||||
<button type="button" role="tab" class="rules-lang" [class.active]="rulesLang === lang"
|
||||
[attr.aria-selected]="rulesLang === lang" (click)="rulesLang = lang">
|
||||
{{ ('gameSystemEdit.lang.' + lang) | translate }}
|
||||
<span class="rules-lang-count">{{ sectionCount(lang) }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
<p class="sections-hint">{{ 'gameSystemEdit.langHint' | translate }}</p>
|
||||
|
||||
<div class="section-list">
|
||||
@for (section of sections; track section; let i = $index) {
|
||||
<div class="section-card" [class.collapsed]="section.collapsed">
|
||||
|
||||
@@ -359,3 +359,32 @@
|
||||
|
||||
&:hover { border-color: #374151; color: #e5e7eb; }
|
||||
}
|
||||
|
||||
// Règles en deux langues : onglets Français / English au-dessus des sections.
|
||||
.rules-langs {
|
||||
display: flex;
|
||||
gap: 0.4rem;
|
||||
margin: 0.75rem 0 0.35rem;
|
||||
}
|
||||
|
||||
.rules-lang {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
padding: 0.4rem 0.85rem;
|
||||
border-radius: 999px;
|
||||
border: 1px solid #374151;
|
||||
background: transparent;
|
||||
color: #d1d5db;
|
||||
cursor: pointer;
|
||||
font-size: 0.85rem;
|
||||
|
||||
&.active { border-color: #6c63ff; background: rgba(108, 99, 255, 0.15); color: white; }
|
||||
}
|
||||
|
||||
.rules-lang-count {
|
||||
font-size: 0.72rem;
|
||||
padding: 0 0.4rem;
|
||||
border-radius: 999px;
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ const NPC_FIELD_SUGGESTIONS = ['Motivation', 'Apparence', 'Faction', 'Notes MJ']
|
||||
/** Suggestions de champs pour la fiche ENNEMI — stats de combat. */
|
||||
const ENEMY_FIELD_SUGGESTIONS = ['Stats', 'Attaques', 'Capacités', 'Faiblesses', 'Butin', 'Tactique'];
|
||||
|
||||
/** Langue d'une version des règles. */
|
||||
type RulesLang = 'fr' | 'en';
|
||||
|
||||
@Component({
|
||||
selector: 'app-game-system-edit',
|
||||
imports: [FormsModule, LucideAngularModule, TranslatePipe, TemplateFieldsEditorComponent],
|
||||
@@ -83,7 +86,15 @@ export class GameSystemEditComponent implements OnInit {
|
||||
name = '';
|
||||
description = '';
|
||||
author = '';
|
||||
sections: RuleSection[] = [];
|
||||
/** Règles en deux langues : sections par langue ; l'onglet affiché est `rulesLang`. */
|
||||
sectionsByLang: Record<RulesLang, RuleSection[]> = { fr: [], en: [] };
|
||||
rulesLang: RulesLang = 'fr';
|
||||
readonly rulesLangs: RulesLang[] = ['fr', 'en'];
|
||||
|
||||
/** Sections de l'onglet affiché (même tableau : push/splice modifient la bonne langue). */
|
||||
get sections(): RuleSection[] {
|
||||
return this.sectionsByLang[this.rulesLang];
|
||||
}
|
||||
characterTemplate: TemplateField[] = [];
|
||||
npcTemplate: TemplateField[] = [];
|
||||
enemyTemplate: TemplateField[] = [];
|
||||
@@ -107,6 +118,8 @@ export class GameSystemEditComponent implements OnInit {
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
// Onglet de règles par défaut : la langue de l'interface.
|
||||
this.rulesLang = this.translate.getCurrentLang() === 'en' ? 'en' : 'fr';
|
||||
this.id = this.route.snapshot.paramMap.get('id');
|
||||
if (this.id) {
|
||||
this.service.getById(this.id).subscribe({
|
||||
@@ -114,7 +127,10 @@ export class GameSystemEditComponent implements OnInit {
|
||||
this.name = gs.name;
|
||||
this.description = gs.description ?? '';
|
||||
this.author = gs.author ?? '';
|
||||
this.sections = this.parseMarkdown(gs.rulesMarkdown ?? '');
|
||||
this.sectionsByLang = {
|
||||
fr: this.parseMarkdown(gs.rulesMarkdown ?? ''),
|
||||
en: this.parseMarkdown(gs.rulesMarkdownEn ?? '')
|
||||
};
|
||||
this.characterTemplate = gs.characterTemplate ? [...gs.characterTemplate] : [];
|
||||
this.npcTemplate = gs.npcTemplate ? [...gs.npcTemplate] : [];
|
||||
this.enemyTemplate = gs.enemyTemplate ? [...gs.enemyTemplate] : [];
|
||||
@@ -181,7 +197,7 @@ export class GameSystemEditComponent implements OnInit {
|
||||
} else if (ev.type === 'status') {
|
||||
this.importStatus = ev.message;
|
||||
} else if (ev.type === 'done') {
|
||||
this.finishImport(ev.sections, ev.pageCount, ev.ocrPageCount);
|
||||
this.finishImport(ev.sections, ev.pageCount, ev.ocrPageCount, ev.sectionsByLanguage, ev.sourceLanguage);
|
||||
}
|
||||
},
|
||||
error: (err: Error) => {
|
||||
@@ -193,9 +209,21 @@ export class GameSystemEditComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
private finishImport(sections: Record<string, string>, pageCount: number, ocrPageCount: number): void {
|
||||
private finishImport(sections: Record<string, string>, pageCount: number, ocrPageCount: number,
|
||||
byLanguage?: Record<string, Record<string, string>>, sourceLanguage?: string | null): void {
|
||||
this.resetImportProgress();
|
||||
const added = this.mergeImportedSections(sections);
|
||||
// Règles en deux langues (Brain récent) : chaque version va dans son onglet ; sinon,
|
||||
// les sections vont dans l'onglet affiché (comportement historique).
|
||||
const bilingual = !!byLanguage && Object.keys(byLanguage).some(l => l === 'fr' || l === 'en');
|
||||
let added = 0;
|
||||
if (bilingual) {
|
||||
for (const lang of this.rulesLangs) {
|
||||
const merged = this.mergeImportedSections(byLanguage![lang] ?? {}, this.sectionsByLang[lang]);
|
||||
if (lang === this.rulesLang || added === 0) added = Math.max(added, merged);
|
||||
}
|
||||
} else {
|
||||
added = this.mergeImportedSections(sections, this.sections);
|
||||
}
|
||||
if (added === 0) {
|
||||
this.importError = this.translate.instant('gameSystemEdit.importNoRules');
|
||||
return;
|
||||
@@ -208,6 +236,18 @@ export class GameSystemEditComponent implements OnInit {
|
||||
pages: pageCount,
|
||||
ocr
|
||||
});
|
||||
const translatedLangs = this.rulesLangs.filter(l => l !== sourceLanguage && (byLanguage?.[l] && Object.keys(byLanguage[l]).length));
|
||||
if (bilingual && sourceLanguage && translatedLangs.length) {
|
||||
this.importNote += ' ' + this.translate.instant('gameSystemEdit.importTranslated', {
|
||||
source: this.translate.instant('gameSystemEdit.lang.' + sourceLanguage),
|
||||
target: translatedLangs.map(l => this.translate.instant('gameSystemEdit.lang.' + l)).join(', ')
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** Nombre de sections non vides d'une langue (badge de l'onglet). */
|
||||
sectionCount(lang: RulesLang): number {
|
||||
return this.sectionsByLang[lang].filter(s => s.title.trim() || s.content.trim()).length;
|
||||
}
|
||||
|
||||
private resetImportProgress(): void {
|
||||
@@ -221,20 +261,20 @@ export class GameSystemEditComponent implements OnInit {
|
||||
* (insensible à la casse) → contenu ajouté à la suite ; sinon nouvelle carte.
|
||||
* Retourne le nombre de sections effectivement intégrées.
|
||||
*/
|
||||
private mergeImportedSections(sections: Record<string, string>): number {
|
||||
private mergeImportedSections(sections: Record<string, string>, target: RuleSection[]): number {
|
||||
let count = 0;
|
||||
for (const [rawTitle, rawContent] of Object.entries(sections ?? {})) {
|
||||
const title = (rawTitle ?? '').trim();
|
||||
const content = (rawContent ?? '').trim();
|
||||
if (!title || !content) continue;
|
||||
const existing = this.sections.find(
|
||||
const existing = target.find(
|
||||
s => s.title.trim().toLowerCase() === title.toLowerCase()
|
||||
);
|
||||
if (existing) {
|
||||
existing.content = `${existing.content.trim()}\n\n${content}`.trim();
|
||||
existing.collapsed = false;
|
||||
} else {
|
||||
this.sections.push({ title, content, collapsed: false });
|
||||
target.push({ title, content, collapsed: false });
|
||||
}
|
||||
count++;
|
||||
}
|
||||
@@ -300,7 +340,8 @@ export class GameSystemEditComponent implements OnInit {
|
||||
name: this.name.trim(),
|
||||
description: this.description.trim() || null,
|
||||
author: this.author.trim() || null,
|
||||
rulesMarkdown: this.serializeMarkdown(),
|
||||
rulesMarkdown: this.serializeMarkdown(this.sectionsByLang.fr),
|
||||
rulesMarkdownEn: this.serializeMarkdown(this.sectionsByLang.en),
|
||||
characterTemplate: this.characterTemplate,
|
||||
npcTemplate: this.npcTemplate,
|
||||
enemyTemplate: this.enemyTemplate,
|
||||
@@ -377,8 +418,8 @@ export class GameSystemEditComponent implements OnInit {
|
||||
}
|
||||
|
||||
/** Reconstruit le markdown à partir des sections (ignore les sections vides). */
|
||||
private serializeMarkdown(): string | null {
|
||||
const valid = this.sections.filter(s => s.title.trim() || s.content.trim());
|
||||
private serializeMarkdown(sections: RuleSection[]): string | null {
|
||||
const valid = sections.filter(s => s.title.trim() || s.content.trim());
|
||||
if (valid.length === 0) return null;
|
||||
return valid
|
||||
.map(s => {
|
||||
|
||||
@@ -12,6 +12,8 @@ export interface GameSystem {
|
||||
name: string;
|
||||
description?: string | null;
|
||||
rulesMarkdown?: string | null;
|
||||
/** Version anglaise des règles (rulesMarkdown = version française). */
|
||||
rulesMarkdownEn?: string | null;
|
||||
characterTemplate?: TemplateField[];
|
||||
npcTemplate?: TemplateField[];
|
||||
enemyTemplate?: TemplateField[];
|
||||
@@ -43,7 +45,9 @@ export interface RulesImportResponse {
|
||||
export type RulesImportStreamEvent =
|
||||
| { type: 'progress'; current: number; total: number; pageCount: number; ocrPageCount: number; newSectionTitles: string[] }
|
||||
| { type: 'status'; message: string }
|
||||
| { type: 'done'; sections: Record<string, string>; pageCount: number; ocrPageCount: number }
|
||||
| { type: 'done'; sections: Record<string, string>; pageCount: number; ocrPageCount: number;
|
||||
/** Règles en deux langues : {fr|en → sections} ; langue d'origine du livre. */
|
||||
sectionsByLanguage?: Record<string, Record<string, string>>; sourceLanguage?: string | null }
|
||||
| { type: 'error'; message: string };
|
||||
|
||||
/** Payload de creation/mise a jour (sans id). */
|
||||
@@ -51,6 +55,8 @@ export interface GameSystemCreate {
|
||||
name: string;
|
||||
description?: string | null;
|
||||
rulesMarkdown?: string | null;
|
||||
/** Version anglaise des règles (rulesMarkdown = version française). */
|
||||
rulesMarkdownEn?: string | null;
|
||||
characterTemplate?: TemplateField[];
|
||||
npcTemplate?: TemplateField[];
|
||||
enemyTemplate?: TemplateField[];
|
||||
|
||||
@@ -100,7 +100,12 @@ export class SessionRulesPanelComponent implements OnChanges, OnDestroy {
|
||||
private applySystem(gs: GameSystem | null): void {
|
||||
this.gameSystem = gs;
|
||||
if (!gs) { this.state = 'noSystem'; return; }
|
||||
this.sections = parseRuleSections(gs.rulesMarkdown, this.translate.instant('sessionRules.preamble'));
|
||||
// Règles dans la langue de l'interface, avec repli sur l'autre version si elle est vide.
|
||||
const english = this.translate.getCurrentLang() === 'en';
|
||||
const preferred = english ? gs.rulesMarkdownEn : gs.rulesMarkdown;
|
||||
const fallback = english ? gs.rulesMarkdown : gs.rulesMarkdownEn;
|
||||
const rules = preferred?.trim() ? preferred : fallback;
|
||||
this.sections = parseRuleSections(rules, this.translate.instant('sessionRules.preamble'));
|
||||
if (this.sections.length === 0) { this.state = 'noRules'; return; }
|
||||
this.pinned = this.readPins();
|
||||
this.opened = new Set(this.sections.filter(s => this.pinned.has(s.title)).map(s => s.id));
|
||||
|
||||
@@ -53,7 +53,14 @@
|
||||
"importFailedReason": "Import failed: {{reason}}",
|
||||
"importNoRules": "No usable rules could be extracted from this PDF (scan without OCR, or unrecognized content).",
|
||||
"importOcrSuffix": " (including {{count}} page(s) via OCR)",
|
||||
"importNote": "{{added}} section(s) suggested from {{pages}} page(s){{ocr}}. Review and adjust below before saving."
|
||||
"importNote": "{{added}} section(s) suggested from {{pages}} page(s){{ocr}}. Review and adjust below before saving.",
|
||||
"langTabs": "Rules language",
|
||||
"lang": {
|
||||
"fr": "Français",
|
||||
"en": "English"
|
||||
},
|
||||
"langHint": "Rules exist in two versions: the app and the AI use the one matching the interface language (or the other if it's empty). Importing a PDF fills both, whatever its language.",
|
||||
"importTranslated": "Book in {{source}}: the {{target}} version was translated automatically (proper names kept); review it in its tab."
|
||||
},
|
||||
"ollamaModelManager": {
|
||||
"installedModels": "Installed models",
|
||||
|
||||
@@ -53,7 +53,14 @@
|
||||
"importFailedReason": "Échec de l'import : {{reason}}",
|
||||
"importNoRules": "Aucune règle exploitable n'a été extraite de ce PDF (scan sans OCR, ou contenu non reconnu).",
|
||||
"importOcrSuffix": " (dont {{count}} page(s) via OCR)",
|
||||
"importNote": "{{added}} section(s) proposée(s) depuis {{pages}} page(s){{ocr}}. Relisez et ajustez ci-dessous avant d'enregistrer."
|
||||
"importNote": "{{added}} section(s) proposée(s) depuis {{pages}} page(s){{ocr}}. Relisez et ajustez ci-dessous avant d'enregistrer.",
|
||||
"langTabs": "Langue des règles",
|
||||
"lang": {
|
||||
"fr": "Français",
|
||||
"en": "English"
|
||||
},
|
||||
"langHint": "Les règles existent en deux versions : l'appli et l'IA utilisent celle de la langue de l'interface (ou l'autre si elle est vide). Importer un PDF remplit les deux, dans n'importe quelle langue.",
|
||||
"importTranslated": "Livre en {{source}} : version {{target}} traduite automatiquement (noms propres conservés), relis-la dans son onglet."
|
||||
},
|
||||
"ollamaModelManager": {
|
||||
"installedModels": "Modèles installés",
|
||||
|
||||
Reference in New Issue
Block a user