* feat(fairygui): FairyGUI ECS 集成核心架构 实现 FairyGUI 的 ECS 原生集成,完全替代旧 UI 系统: 核心类: - GObject: UI 对象基类,支持变换、可见性、关联、齿轮 - GComponent: 容器组件,管理子对象和控制器 - GRoot: 根容器,管理焦点、弹窗、输入分发 - GGroup: 组容器,支持水平/垂直布局 抽象层: - DisplayObject: 显示对象基类 - EventDispatcher: 事件分发 - Timer: 计时器 - Stage: 舞台,管理输入和缩放 布局系统: - Relations: 约束关联管理 - RelationItem: 24 种关联类型 基础设施: - Controller: 状态控制器 - Transition: 过渡动画 - ScrollPane: 滚动面板 - UIPackage: 包管理 - ByteBuffer: 二进制解析 * refactor(ui): 删除旧 UI 系统,使用 FairyGUI 替代 * feat(fairygui): 实现 UI 控件 - 添加显示类:Image、TextField、Graph - 添加基础控件:GImage、GTextField、GGraph - 添加交互控件:GButton、GProgressBar、GSlider - 更新 IRenderCollector 支持 Graph 渲染 - 扩展 Controller 添加 selectedPageId - 添加 STATE_CHANGED 事件类型 * feat(fairygui): 现代化架构重构 - 增强 EventDispatcher 支持类型安全、优先级和传播控制 - 添加 PropertyBinding 响应式属性绑定系统 - 添加 ServiceContainer 依赖注入容器 - 添加 UIConfig 全局配置系统 - 添加 UIObjectFactory 对象工厂 - 实现 RenderBridge 渲染桥接层 - 实现 Canvas2DBackend 作为默认渲染后端 - 扩展 IRenderCollector 支持更多图元类型 * feat(fairygui): 九宫格渲染和资源加载修复 - 修复 FGUIUpdateSystem 支持路径和 GUID 两种加载方式 - 修复 GTextInput 同时设置 _displayObject 和 _textField - 实现九宫格渲染展开为 9 个子图元 - 添加 sourceWidth/sourceHeight 用于九宫格计算 - 添加 DOMTextRenderer 文本渲染层(临时方案) * fix(fairygui): 修复 GGraph 颜色读取 * feat(fairygui): 虚拟节点 Inspector 和文本渲染支持 * fix(fairygui): 编辑器状态刷新和遗留引用修复 - 修复切换 FGUI 包后组件列表未刷新问题 - 修复切换组件后 viewport 未清理旧内容问题 - 修复虚拟节点在包加载后未刷新问题 - 重构为事件驱动架构,移除轮询机制 - 修复 @esengine/ui 遗留引用,统一使用 @esengine/fairygui * fix: 移除 tsconfig 中的 @esengine/ui 引用
212 lines
7.6 KiB
Rust
212 lines
7.6 KiB
Rust
//! ESEngine Editor - Tauri Backend
|
|
//!
|
|
//! Clean entry point that handles application setup and command registration.
|
|
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
|
|
|
mod commands;
|
|
mod profiler_ws;
|
|
mod state;
|
|
|
|
use std::collections::HashMap;
|
|
use std::sync::{Arc, Mutex};
|
|
use tauri::Manager;
|
|
|
|
use state::{ProfilerState, ProjectPaths, ScriptWatcherState};
|
|
|
|
fn main() {
|
|
// Initialize shared state | 初始化共享状态
|
|
let project_paths: ProjectPaths = Arc::new(Mutex::new(HashMap::new()));
|
|
let project_paths_for_protocol = Arc::clone(&project_paths);
|
|
|
|
let profiler_state = ProfilerState::new();
|
|
let script_watcher_state = ScriptWatcherState::new();
|
|
|
|
// Build and run the Tauri application
|
|
tauri::Builder::default()
|
|
// Register plugins
|
|
.plugin(tauri_plugin_shell::init())
|
|
.plugin(tauri_plugin_dialog::init())
|
|
.plugin(tauri_plugin_fs::init())
|
|
.plugin(tauri_plugin_updater::Builder::new().build())
|
|
.plugin(tauri_plugin_http::init())
|
|
.plugin(tauri_plugin_cli::init())
|
|
// Register custom URI scheme for project files
|
|
.register_uri_scheme_protocol("project", move |_app, request| {
|
|
handle_project_protocol(request, &project_paths_for_protocol)
|
|
})
|
|
// Setup application state | 设置应用状态
|
|
.setup(move |app| {
|
|
app.manage(project_paths);
|
|
app.manage(profiler_state);
|
|
app.manage(script_watcher_state);
|
|
Ok(())
|
|
})
|
|
// Register all commands
|
|
.invoke_handler(tauri::generate_handler![
|
|
// Project management
|
|
commands::open_project,
|
|
commands::save_project,
|
|
commands::export_binary,
|
|
commands::set_project_base_path,
|
|
commands::scan_behavior_trees,
|
|
// File system operations
|
|
commands::read_file_content,
|
|
commands::write_file_content,
|
|
commands::write_binary_file,
|
|
commands::append_to_log,
|
|
commands::path_exists,
|
|
commands::create_directory,
|
|
commands::create_file,
|
|
commands::delete_file,
|
|
commands::delete_folder,
|
|
commands::rename_file_or_folder,
|
|
commands::list_directory,
|
|
commands::scan_directory,
|
|
commands::read_file_as_base64,
|
|
commands::copy_file,
|
|
commands::get_file_mtime,
|
|
// Dialog operations
|
|
commands::open_folder_dialog,
|
|
commands::open_file_dialog,
|
|
commands::save_file_dialog,
|
|
// Profiler server
|
|
commands::start_profiler_server,
|
|
commands::stop_profiler_server,
|
|
commands::get_profiler_status,
|
|
// Plugin management
|
|
commands::build_plugin,
|
|
commands::install_marketplace_plugin,
|
|
commands::uninstall_marketplace_plugin,
|
|
// System operations
|
|
commands::toggle_devtools,
|
|
commands::open_file_with_default_app,
|
|
commands::open_folder,
|
|
commands::show_in_folder,
|
|
commands::get_temp_dir,
|
|
commands::open_with_editor,
|
|
commands::update_project_tsconfig,
|
|
commands::get_app_resource_dir,
|
|
commands::get_current_dir,
|
|
commands::start_local_server,
|
|
commands::stop_local_server,
|
|
commands::get_local_ip,
|
|
commands::generate_qrcode,
|
|
// User code compilation | 用户代码编译
|
|
commands::compile_typescript,
|
|
commands::watch_scripts,
|
|
commands::watch_assets,
|
|
commands::stop_watch_scripts,
|
|
commands::check_environment,
|
|
commands::install_esbuild,
|
|
// Build commands | 构建命令
|
|
commands::prepare_build_directory,
|
|
commands::copy_directory,
|
|
commands::bundle_scripts,
|
|
commands::generate_html,
|
|
commands::get_file_size,
|
|
commands::get_directory_size,
|
|
commands::write_json_file,
|
|
commands::list_files_by_extension,
|
|
commands::read_binary_file_as_base64,
|
|
commands::read_binary_file,
|
|
// Engine modules | 引擎模块
|
|
commands::read_engine_modules_index,
|
|
commands::read_module_manifest,
|
|
commands::get_engine_modules_base_path,
|
|
])
|
|
.run(tauri::generate_context!())
|
|
.expect("error while running tauri application");
|
|
}
|
|
|
|
/// Handle the custom 'project://' URI scheme protocol
|
|
///
|
|
/// This allows the frontend to load project files through a custom protocol,
|
|
/// enabling features like hot-reloading plugins from the project directory.
|
|
fn handle_project_protocol(
|
|
request: tauri::http::Request<Vec<u8>>,
|
|
project_paths: &ProjectPaths,
|
|
) -> tauri::http::Response<Vec<u8>> {
|
|
let uri = request.uri();
|
|
let path = uri.path();
|
|
|
|
// Debug logging
|
|
println!("[project://] Full URI: {}", uri);
|
|
println!("[project://] Path: {}", path);
|
|
|
|
let file_path = {
|
|
let paths = match project_paths.lock() {
|
|
Ok(p) => p,
|
|
Err(_) => {
|
|
return tauri::http::Response::builder()
|
|
.status(500)
|
|
.body(Vec::new())
|
|
.unwrap();
|
|
}
|
|
};
|
|
|
|
match paths.get("current") {
|
|
Some(base_path) => format!("{}{}", base_path, path),
|
|
None => {
|
|
return tauri::http::Response::builder()
|
|
.status(404)
|
|
.body(Vec::new())
|
|
.unwrap();
|
|
}
|
|
}
|
|
};
|
|
|
|
match std::fs::read(&file_path) {
|
|
Ok(content) => {
|
|
let mime_type = get_mime_type(&file_path);
|
|
|
|
tauri::http::Response::builder()
|
|
.status(200)
|
|
.header("Content-Type", mime_type)
|
|
// CORS headers for dynamic ES module imports | 动态 ES 模块导入所需的 CORS 头
|
|
.header("Access-Control-Allow-Origin", "*")
|
|
.header("Access-Control-Allow-Methods", "GET, OPTIONS")
|
|
.header("Access-Control-Allow-Headers", "Content-Type")
|
|
.header("Access-Control-Expose-Headers", "Content-Length")
|
|
// Allow cross-origin script loading | 允许跨域脚本加载
|
|
.header("Cross-Origin-Resource-Policy", "cross-origin")
|
|
.body(content)
|
|
.unwrap()
|
|
}
|
|
Err(e) => {
|
|
eprintln!("Failed to read file {}: {}", file_path, e);
|
|
tauri::http::Response::builder()
|
|
.status(404)
|
|
.header("Access-Control-Allow-Origin", "*")
|
|
.body(Vec::new())
|
|
.unwrap()
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Get MIME type based on file extension
|
|
/// 根据文件扩展名获取 MIME 类型
|
|
fn get_mime_type(file_path: &str) -> &'static str {
|
|
if file_path.ends_with(".ts") || file_path.ends_with(".tsx") {
|
|
"application/javascript"
|
|
} else if file_path.ends_with(".js") || file_path.ends_with(".mjs") {
|
|
"application/javascript"
|
|
} else if file_path.ends_with(".json") {
|
|
"application/json"
|
|
} else if file_path.ends_with(".wasm") {
|
|
"application/wasm"
|
|
} else if file_path.ends_with(".css") {
|
|
"text/css"
|
|
} else if file_path.ends_with(".html") {
|
|
"text/html"
|
|
} else if file_path.ends_with(".png") {
|
|
"image/png"
|
|
} else if file_path.ends_with(".jpg") || file_path.ends_with(".jpeg") {
|
|
"image/jpeg"
|
|
} else if file_path.ends_with(".svg") {
|
|
"image/svg+xml"
|
|
} else {
|
|
"application/octet-stream"
|
|
}
|
|
}
|