d1f180ee0a
Offline Electron app seeds 10 system presets, supports create-from-scratch designer with palette/drag/resize/bricks, and exports .ttrpg-system.json for the player. Co-authored-by: Cursor <cursoragent@cursor.com>
44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { createRequire } from 'node:module';
|
|
|
|
const require = createRequire(import.meta.url);
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const root = path.resolve(__dirname, '..');
|
|
|
|
// Run via tsx so we can import TS modules
|
|
const { validateSystemDefinition } = await import('../app/shared/systemValidate.ts');
|
|
const { computeDerived } = await import('../app/shared/derived.ts');
|
|
|
|
const presetsDir = path.join(root, 'presets');
|
|
const files = fs.readdirSync(presetsDir).filter((f) => f.endsWith('.json') && !f.includes('sample'));
|
|
|
|
let failed = 0;
|
|
for (const file of files) {
|
|
const system = JSON.parse(fs.readFileSync(path.join(presetsDir, file), 'utf8'));
|
|
const v = validateSystemDefinition(system);
|
|
if (!v.ok) {
|
|
console.error('FAIL validate', file, v.errors);
|
|
failed += 1;
|
|
continue;
|
|
}
|
|
const attrs = {};
|
|
for (const a of system.bricks.attributes ?? []) {
|
|
attrs[a.key] = typeof a.default === 'number' ? a.default : 10;
|
|
}
|
|
try {
|
|
computeDerived(system.bricks.derived ?? [], { attributes: attrs });
|
|
console.log('OK', file);
|
|
} catch (e) {
|
|
console.error('FAIL derived', file, e);
|
|
failed += 1;
|
|
}
|
|
}
|
|
|
|
if (failed) {
|
|
console.error(`preset-smoke: ${failed} failed`);
|
|
process.exit(1);
|
|
}
|
|
console.log(`preset-smoke: ${files.length} presets ok`);
|