Add persistent tabs to generated D10 sheets

This commit is contained in:
Dandaedre 2026-09-19 00:09:23 +02:00
parent d5182fb521
commit 5dc05e8b0b
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
6 changed files with 76 additions and 4 deletions

View File

@ -102,3 +102,20 @@ Le style commun se trouve dans `templates/sheet.css`; les couleurs restent dans
`data/themes.yaml`. Les noms d'attributs et les formules de jet n'ont pas changé
avec cette refonte visuelle. Les fichiers dans `build/` doivent être régénérés
avant de remplacer le HTML et le CSS dans Roll20.
### Onglets
L'en-tête du personnage reste visible. Quatre onglets organisent la feuille :
**Personnage** (caractéristiques et ressources), **Compétences**, **Combat** et
**Autres** (sections répétables). Le choix est enregistré dans l'attribut Roll20
`d10_tab` par un sheet worker, sans changer les valeurs des autres champs.
Pour tester localement les actions après avoir généré les deux variantes
`parchment` :
```sh
node tests/test_tabs.mjs
```
Le test simule les clics et les mises à jour d'attribut. Vérifier aussi dans
Roll20 que le clic affiche le bon onglet et que celui-ci est conservé après
fermeture puis réouverture de la feuille.

View File

@ -7,6 +7,7 @@
- [x] Test validation, generated fields, references, and both variant builds.
- [x] Document build, use, variant differences, migration limits, and Roll20 sandbox checks.
- [x] Replace stacked characteristic and skill controls with compact themed grids; verify both variants and themes.
- [x] Split the generated sheet into Personnage, Compétences, Combat, and Autres tabs; verify action handlers and builds.
## Live Roll20 checks after local verification

View File

@ -17,6 +17,18 @@
.sheet-d10 .sheet-identity { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet-d10 .sheet-identity label, .sheet-d10 .sheet-die-choice { display: grid; gap: 3px; margin: 0 !important; color: var(--d10-accent); font: bold 10px Arial,sans-serif; letter-spacing: .07em; text-transform: uppercase; }
.sheet-d10 .sheet-die-choice { align-self: end; }
.sheet-d10 .sheet-tab-nav { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 4px; margin: 14px 0 0; border-bottom: 2px solid var(--d10-accent); }
.sheet-d10 .sheet-tab-nav button[type=action] { width: 100%; min-height: 38px; margin: 0 !important; padding: 7px 5px; color: var(--d10-accent); background: var(--d10-background); border: 1px solid var(--d10-border); border-bottom: 0; border-radius: 3px 3px 0 0; box-shadow: none; font: bold 12px Georgia,serif; text-shadow: none; }
.sheet-d10 .sheet-tab-nav button[type=action]:hover, .sheet-d10 .sheet-tab-nav button[type=action]:focus { background: var(--d10-panel); outline: 2px solid var(--d10-border); outline-offset: -2px; }
.sheet-d10 .sheet-page { display: none; }
.sheet-d10 .sheet-tab-state[value="core"] ~ .sheet-page-core,
.sheet-d10 .sheet-tab-state[value="skills"] ~ .sheet-page-skills,
.sheet-d10 .sheet-tab-state[value="combat"] ~ .sheet-page-combat,
.sheet-d10 .sheet-tab-state[value="other"] ~ .sheet-page-other { display: block; }
.sheet-d10 .sheet-tab-state[value="core"] ~ .sheet-tab-nav .sheet-tab-core,
.sheet-d10 .sheet-tab-state[value="skills"] ~ .sheet-tab-nav .sheet-tab-skills,
.sheet-d10 .sheet-tab-state[value="combat"] ~ .sheet-tab-nav .sheet-tab-combat,
.sheet-d10 .sheet-tab-state[value="other"] ~ .sheet-tab-nav .sheet-tab-other { color: var(--d10-panel); background: var(--d10-accent); border-color: var(--d10-accent); }
.sheet-d10 input, .sheet-d10 select { box-sizing: border-box; width: 100%; min-width: 0; height: 30px; margin: 0 !important; padding: 3px 6px; color: var(--d10-ink); background: var(--d10-panel); border: 1px solid var(--d10-border); border-radius: 2px; box-shadow: none; font: 13px Arial,sans-serif; }
.sheet-d10 input:focus, .sheet-d10 select:focus { outline: 2px solid var(--d10-accent); outline-offset: 1px; }
.sheet-d10 input[type=checkbox] { width: 18px; height: 18px; padding: 0; accent-color: var(--d10-accent); }
@ -71,6 +83,7 @@
.sheet-d10 .sheet-hero { grid-template-columns: 45px minmax(0,1fr); gap: 9px; }
.sheet-d10 .sheet-hero-mark { width: 42px; height: 42px; font-size: 14px; }
.sheet-d10 .sheet-die-choice { grid-column: 2; }
.sheet-d10 .sheet-tab-nav button[type=action] { min-height: 36px; padding: 5px 2px; font-size: 10px; }
.sheet-d10 .sheet-skill-head, .sheet-d10 .sheet-skill-row { grid-template-columns: minmax(110px,1fr) 72px 48px 48px 36px; gap: 4px; padding: 4px; }
.sheet-d10 .sheet-location-head, .sheet-d10 .sheet-location { grid-template-columns: minmax(75px,1fr) repeat(3,60px); gap: 4px; }
}

View File

@ -23,6 +23,9 @@ class BuildTests(unittest.TestCase):
self.assertIn('sheet-rolltemplate-d10skillcheck', files['sheet.html'])
self.assertIn('class="sheet-stat-grid"', files['sheet.html'])
self.assertIn('class="sheet-skill-head"', files['sheet.html'])
self.assertEqual(files['sheet.html'].count('class="sheet-page sheet-page-'), 4)
self.assertIn('name="attr_d10_tab" value="core"', files['sheet.html'])
self.assertIn('.sheet-tab-state[value="skills"] ~ .sheet-page-skills', files['sheet.css'])
self.assertEqual(files['sheet.html'].count('class="sheet-skill-row'), info['skills'])
self.assertIn('.sheet-d10 .sheet-stat-grid { display: grid;', files['sheet.css'])
self.assertIn('.sheet-d10 .sheet-skill-head, .sheet-d10 .sheet-skill-row { display: grid;', files['sheet.css'])

26
tests/test_tabs.mjs Normal file
View File

@ -0,0 +1,26 @@
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import vm from 'node:vm';
const tabs = ['core', 'skills', 'combat', 'other'];
for (const variant of ['base', 'cyberpunk']) {
const html = readFileSync(`build/${variant}/parchment/sheet.html`, 'utf8');
const script = html.match(/<script type="text\/worker">\s*([\s\S]*?)<\/script>/)?.[1];
assert.ok(script, `${variant}: generated sheet worker`);
const handlers = new Map();
const attributes = { d10_tab: 'core' };
vm.runInNewContext(script, {
on: (event, handler) => {
assert.ok(!handlers.has(event), `duplicate handler: ${event}`);
handlers.set(event, handler);
},
setAttrs: changes => Object.assign(attributes, changes),
});
assert.equal(handlers.size, tabs.length);
for (const tab of tabs) {
assert.match(html, new RegExp(`name="act_tab_${tab}"`));
assert.match(html, new RegExp(`class="sheet-page sheet-page-${tab}"`));
handlers.get(`clicked:tab_${tab}`)();
assert.equal(attributes.d10_tab, tab);
}
}

View File

@ -13,6 +13,8 @@ ROOT = Path(__file__).resolve().parents[1]
DATA = ROOT / 'data'
IDENT = re.compile(r'^[A-Za-z][A-Za-z0-9_-]*$')
COLOR = re.compile(r'^#[0-9a-fA-F]{6}$')
TABS = (('core', 'Personnage'), ('skills', 'Compétences'),
('combat', 'Combat'), ('other', 'Autres'))
def read_yaml(path):
@ -126,6 +128,11 @@ def render(model, skills, variant, theme_name, theme):
'<label class="sheet-die-choice">Dé de jeu <select name="attr_dice">' + ''.join(
f'<option value="{n}"{" selected" if n == 10 else ""}>d{n}</option>'
for n in (4, 6, 8, 10, 12, 20)) + '</select></label></header>',
'<input type="hidden" class="sheet-tab-state" name="attr_d10_tab" value="core">',
'<nav class="sheet-tab-nav" aria-label="Sections de la feuille">',
*(f'<button type="action" class="sheet-tab-button sheet-tab-{key}" name="act_tab_{key}">{label}</button>'
for key, label in TABS),
'</nav><div class="sheet-page sheet-page-core">',
'<section class="sheet-panel"><div class="sheet-section-title"><span>01</span><h2>Caractéristiques</h2></div>',
'<div class="sheet-stat-grid">']
for item in model['attributes']:
@ -151,7 +158,7 @@ def render(model, skills, variant, theme_name, theme):
parts.append('</div>')
else:
parts.append('</div>')
parts.append('</section><section class="sheet-panel"><div class="sheet-section-title"><span>03</span><h2>Combat</h2></div><div class="sheet-combat-grid">')
parts.append('</section></div><div class="sheet-page sheet-page-combat"><section class="sheet-panel"><div class="sheet-section-title"><span>03</span><h2>Combat</h2></div><div class="sheet-combat-grid">')
for item in model.get('combat', []):
parts.append(f'<label class="sheet-combat-field">{esc(item["name"])}'
f'<input type="number" name="attr_{esc(item["id"])}" value="0"></label>')
@ -164,7 +171,7 @@ def render(model, skills, variant, theme_name, theme):
f'<input type="text" name="attr_general_item_weapon{number}_name" title="Nom">'
f'<input type="number" name="attr_general_item_weapon{number}" value="0" title="Dégâts">'
f'<input type="checkbox" name="attr_item_weapon{number}_activation" value="1" title="Équipée"></div>')
parts.append('</div></section><section class="sheet-panel"><div class="sheet-section-title"><span>04</span><h2>Compétences</h2></div>')
parts.append('</div></section></div><div class="sheet-page sheet-page-skills"><section class="sheet-panel"><div class="sheet-section-title"><span>04</span><h2>Compétences</h2></div>')
for section in skills['sections']:
parts.append(f'<h3 class="sheet-subheading">{esc(section["name"])}</h3>')
for group in section['groups']:
@ -172,7 +179,7 @@ def render(model, skills, variant, theme_name, theme):
'<div class="sheet-skill-head"><span>Compétence</span><span>Carac.</span><span>Niveau</span><span>Coût</span><span>Jet</span></div>')
parts.extend(render_skill(group, skill, variant) for skill in group.get('skills', []))
parts.append('</div>')
parts.append('</section><section class="sheet-panel"><div class="sheet-section-title"><span>05</span><h2>Autres</h2></div>')
parts.append('</section></div><div class="sheet-page sheet-page-other"><section class="sheet-panel"><div class="sheet-section-title"><span>05</span><h2>Autres</h2></div>')
for block in model['repeating']:
parts.append(f'<details><summary>{esc(block["name"])}</summary>'
f'<fieldset class="repeating_{esc(block["id"])}">')
@ -186,7 +193,7 @@ def render(model, skills, variant, theme_name, theme):
parts.append(f'<select name="attr_attribute_select">{options}</select>')
parts.append(roll('@{skillname}', '@{skilllevel}+@{attribute_select}'))
parts.append('</fieldset></details>')
parts.append('</section></div>')
parts.append('</section></div></div>')
html_text = '\n'.join(parts) + '\n'
css = '.sheet-d10, .sheet-rolltemplate-d10skillcheck {\n' + '\n'.join(
f' --d10-{key}: {value};' for key, value in theme.items()) + '\n}\n'
@ -196,6 +203,11 @@ def render(model, skills, variant, theme_name, theme):
<div>Seuil: {{threshold}} · Résultat: {{result}}</div>
</rolltemplate>
'''
html_text += '<script type="text/worker">\n'
html_text += ''.join(
f'on("clicked:tab_{key}", function () {{ setAttrs({{d10_tab: "{key}"}}); }});\n'
for key, _ in TABS)
html_text += '</script>\n'
return html_text, css