feat: 添加跨平台运行时、资产系统和UI适配功能 (#256)

* feat(platform-common): 添加WASM加载器和环境检测API

* feat(rapier2d): 新增Rapier2D WASM绑定包

* feat(physics-rapier2d): 添加跨平台WASM加载器

* feat(asset-system): 添加运行时资产目录和bundle格式

* feat(asset-system-editor): 新增编辑器资产管理包

* feat(editor-core): 添加构建系统和模块管理

* feat(editor-app): 重构浏览器预览使用import maps

* feat(platform-web): 添加BrowserRuntime和资产读取

* feat(engine): 添加材质系统和着色器管理

* feat(material): 新增材质系统和着色器编辑器

* feat(tilemap): 增强tilemap编辑器和动画系统

* feat(modules): 添加module.json配置

* feat(core): 添加module.json和类型定义更新

* chore: 更新依赖和构建配置

* refactor(plugins): 更新插件模板使用ModuleManifest

* chore: 添加第三方依赖库

* chore: 移除BehaviourTree-ai和ecs-astar子模块

* docs: 更新README和文档主题样式

* fix: 修复Rust文档测试和添加rapier2d WASM绑定

* fix(tilemap-editor): 修复画布高DPI屏幕分辨率适配问题

* feat(ui): 添加UI屏幕适配系统(CanvasScaler/SafeArea)

* fix(ecs-engine-bindgen): 添加缺失的ecs-framework-math依赖

* fix: 添加缺失的包依赖修复CI构建

* fix: 修复CodeQL检测到的代码问题

* fix: 修复构建错误和缺失依赖

* fix: 修复类型检查错误

* fix(material-system): 修复tsconfig配置支持TypeScript项目引用

* fix(editor-core): 修复Rollup构建配置添加tauri external

* fix: 修复CodeQL检测到的代码问题

* fix: 修复CodeQL检测到的代码问题
This commit is contained in:
YHH
2025-12-03 22:15:22 +08:00
committed by GitHub
parent caf7622aa0
commit 63f006ab62
496 changed files with 77601 additions and 4067 deletions

View File

@@ -0,0 +1,125 @@
/**
* Generate 2D-specific source code from rapier.js source.
* 从 rapier.js 源码生成 2D 专用代码。
*
* This script:
* 1. Copies TypeScript source from rapier.js/src.ts
* 2. Removes #if DIM3 ... #endif blocks (keeps only 2D code)
* 3. Overwrites raw.ts and init.ts with 2D-specific versions
*/
import { readFileSync, writeFileSync, readdirSync, mkdirSync, cpSync, existsSync, renameSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const packageRoot = join(__dirname, '..');
const rapierRoot = join(packageRoot, '..', '..', 'thirdparty', 'rapier.js');
const srcTsDir = join(rapierRoot, 'src.ts');
const src2dDir = join(rapierRoot, 'rapier-compat', 'src2d');
const outputDir = join(packageRoot, 'src');
// Check if rapier.js exists
if (!existsSync(srcTsDir)) {
console.error(`Error: rapier.js source not found at ${rapierRoot}`);
console.error('Please clone https://github.com/esengine/rapier.js.git to thirdparty/rapier.js');
process.exit(1);
}
/**
* Remove #if DIM3 ... #endif blocks from source code
*/
function removeDim3Blocks(content) {
// Remove lines between #if DIM3 and #endif (inclusive)
const lines = content.split('\n');
const result = [];
let skipDepth = 0;
for (const line of lines) {
const trimmed = line.trim();
if (trimmed.startsWith('//#if DIM3') || trimmed.startsWith('// #if DIM3')) {
skipDepth++;
continue;
}
if (skipDepth > 0 && (trimmed.startsWith('//#endif') || trimmed.startsWith('// #endif'))) {
skipDepth--;
continue;
}
if (skipDepth === 0) {
// Also remove #if DIM2 and its #endif (but keep the content)
if (trimmed.startsWith('//#if DIM2') || trimmed.startsWith('// #if DIM2')) {
continue;
}
if (trimmed.startsWith('//#endif') || trimmed.startsWith('// #endif')) {
continue;
}
result.push(line);
}
}
return result.join('\n');
}
/**
* Process a single TypeScript file
*/
function processFile(srcPath, destPath) {
const content = readFileSync(srcPath, 'utf-8');
const processed = removeDim3Blocks(content);
writeFileSync(destPath, processed);
}
/**
* Recursively copy and process directory
*/
function processDirectory(srcDir, destDir) {
mkdirSync(destDir, { recursive: true });
const entries = readdirSync(srcDir, { withFileTypes: true });
for (const entry of entries) {
const srcPath = join(srcDir, entry.name);
const destPath = join(destDir, entry.name);
if (entry.isDirectory()) {
processDirectory(srcPath, destPath);
} else if (entry.name.endsWith('.ts')) {
processFile(srcPath, destPath);
console.log(`Processed: ${entry.name}`);
}
}
}
// Main
console.log('Generating 2D source code...');
console.log(`Source: ${srcTsDir}`);
console.log(`Output: ${outputDir}`);
// Step 1: Copy and process src.ts directory
processDirectory(srcTsDir, outputDir);
// Step 2: Overwrite with 2D-specific files (raw.ts, init.ts)
if (existsSync(src2dDir)) {
const entries = readdirSync(src2dDir, { withFileTypes: true });
for (const entry of entries) {
if (entry.isFile() && entry.name.endsWith('.ts')) {
const srcPath = join(src2dDir, entry.name);
const destPath = join(outputDir, entry.name);
cpSync(srcPath, destPath);
console.log(`Overwrote: ${entry.name} (2D-specific)`);
}
}
}
// Step 3: Rename rapier.ts to index.ts
const rapierTs = join(outputDir, 'rapier.ts');
const indexTs = join(outputDir, 'index.ts');
if (existsSync(rapierTs)) {
renameSync(rapierTs, indexTs);
console.log('Renamed: rapier.ts -> index.ts');
}
console.log('Done!');