/
nacha
/
pseado
Обзор
Документация
Войти
/
nacha
/
pseado
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
1
CI/CD
Аналитика
Безопасность
master
pseado_engine.js
152 строки
5 KB
alex
feat: add Pseado Engine Core interpreter
04 авг 2026, 21:19
Верифицирован
04 авг 2026, 21:19
3798c92
Код
Авторство
О чём код?
#!/usr/bin/env node /** * PSEADO ENGINE CORE * Универсальная среда цифровых двойников черчения (Ядро v0.1) * * Интерпретирует скрипты .pseado и генерирует сценарии. * Концепция: Линия — это физический объект с весом, вязкостью и материалом. */ const fs = require('fs'); const path = require('path'); // --- Ядро интерпретатора --- class PseadoInterpreter { constructor() { this.metadata = { project: 'Unnamed', author: 'Unknown' }; this.state = { activeTool: null, strokes: [] }; this.tools = { 'цилиндрическая-шестерня': { type: 'generator', params: {} }, 'карандаш': { type: 'brush', params: { weight: 1, viscosity: 0.2, material: 'graphite' } }, 'масло': { type: 'brush', params: { weight: 3, viscosity: 0.8, material: 'oil-paint' } }, 'фреза': { type: 'cutter', params: { weight: 50, material: 'carbide' } } }; } /** * Парсит файл .pseado */ parse(filePath) { if (!fs.existsSync(filePath)) { console.error(`[Error] File not found: ${filePath}`); return null; } const content = fs.readFileSync(filePath, 'utf8'); const lines = content.split('\n'); lines.forEach((line, index) => { const trimmed = line.trim(); if (!trimmed || trimmed.startsWith('#')) return; try { this._processLine(trimmed); } catch (e) { console.warn(`[Warning] Line ${index + 1}: ${e.message}`); } }); return this.state; } /** * Обработка одной строки скрипта */ _processLine(line) { // Метаданные проекта if (line.startsWith('!проект')) { this.metadata.project = line.split('=')[1]?.trim().replace(/[""]/g, ''); return; } if (line.startsWith('!автор')) { this.metadata.author = line.split('=')[1]?.trim().replace(/[""]/g, ''); return; } // Выбор инструмента if (line.startsWith('выбрать-инструмент')) { const match = line.match(/тип=(\S+)/); if (match) { const toolName = match[1]; this.state.activeTool = toolName; console.log(`[System] Selected tool: ${toolName}`); } return; } // Отрисовка if (line.startsWith('отрисовать') || line.startsWith('generate')) { this._draw(line); return; } } /** * Генерация физически точной линии */ _draw(commandLine) { if (!this.state.activeTool) { console.warn('[System] Tool not selected. Drawing defaults to pencil.'); this.state.activeTool = 'карандаш'; } const tool = this.tools[this.state.activeTool] || this.tools['карандаш']; const now = new Date().toISOString(); // Генерация "физического двойника" линии const stroke = { id: crypto.randomUUID(), timestamp: now, toolType: tool.type, params: { ...tool.params, thickness: Math.random() * tool.params.weight + 0.5 // Естественное дрожание/неоднородность }, rawCommand: commandLine }; this.state.strokes.push(stroke); console.log(`[System] Stroke generated (${this.state.activeTool}): ${stroke.id}`); } /** * Экспорт (заглушка) */ exportJson() { return JSON.stringify({ metadata: this.metadata, state: this.state }, null, 2); } } // --- CLI Интерфейс --- if (require.main === module) { const args = process.argv.slice(2); if (args.length === 0) { console.log(`Usage: node ${path.basename(__filename)} <script.pseado>`); console.log(`Example: node ${path.basename(__filename)} test.pseado`); process.exit(1); } const scriptPath = args[0]; const engine = new PseadoInterpreter(); console.log(`--- PSEADO ENGINE CORE v0.1 ---`); console.log(`Loading script: ${scriptPath}...`); const result = engine.parse(scriptPath); if (result) { console.log('\n--- Execution Report ---'); console.log(result.exportJson()); } } module.exports = PseadoInterpreter;