放宽 UI 生成代码文件上限
为生成 JavaScript 引入独立的 8 倍 State 大小上限 保留原子写入流程并让错误提示使用实际代码上限
This commit is contained in:
@@ -19,6 +19,7 @@ use typed_floats::tf32::StrictlyPositiveFinite;
|
||||
|
||||
const UI_DESIGN_STATE_SCHEMA_VERSION: &str = "game-creator-ui-design-state.v1";
|
||||
const UI_DESIGN_STATE_MAX_BYTES: usize = 2 * 1024 * 1024;
|
||||
const UI_DESIGN_CODE_MAX_BYTES: usize = UI_DESIGN_STATE_MAX_BYTES * 8;
|
||||
const UI_DESIGN_STATE_MAX_IMAGES: usize = 4;
|
||||
const UI_DESIGN_STATE_MAX_SPRITES: usize = 1_024;
|
||||
pub(crate) const UI_DESIGN_STATE_MAX_NODES: usize = 10_000;
|
||||
@@ -180,7 +181,12 @@ pub(crate) fn generate_ui_design_code_at(
|
||||
let (content, tree_exports, node_count) = render_ui_design_state_js(&document.state)?;
|
||||
let relative_path = format!("ui/generated-{}.js", generated_file_stem(&asset_id));
|
||||
let path = resolve_local_project_path(root, &relative_path)?;
|
||||
write_ui_design_raw_file(&path, "UI 设计生成代码", content.as_bytes())?;
|
||||
write_ui_design_raw_file_with_limit(
|
||||
&path,
|
||||
"UI 设计生成代码",
|
||||
content.as_bytes(),
|
||||
UI_DESIGN_CODE_MAX_BYTES,
|
||||
)?;
|
||||
Ok(GenerateUiDesignCodeResult {
|
||||
relative_path,
|
||||
tree_count: tree_exports.len(),
|
||||
@@ -438,8 +444,17 @@ fn serialize_ui_design_document(document: &PersistedUiDesignState) -> Result<Vec
|
||||
/// runtime sidecar protocol: a stable `.previous` is recoverable after a
|
||||
/// process crash, unlike a random `.replace.<pid>.<nonce>` file.
|
||||
fn write_ui_design_raw_file(path: &Path, label: &str, bytes: &[u8]) -> Result<(), String> {
|
||||
if bytes.len() > UI_DESIGN_STATE_MAX_BYTES {
|
||||
return Err(format!("{label} 超过 {UI_DESIGN_STATE_MAX_BYTES} 字节上限"));
|
||||
write_ui_design_raw_file_with_limit(path, label, bytes, UI_DESIGN_STATE_MAX_BYTES)
|
||||
}
|
||||
|
||||
fn write_ui_design_raw_file_with_limit(
|
||||
path: &Path,
|
||||
label: &str,
|
||||
bytes: &[u8],
|
||||
max_bytes: usize,
|
||||
) -> Result<(), String> {
|
||||
if bytes.len() > max_bytes {
|
||||
return Err(format!("{label} 超过 {max_bytes} 字节上限"));
|
||||
}
|
||||
let parent = path.parent().ok_or_else(|| format!("{label} 缺少父目录"))?;
|
||||
fs::create_dir_all(parent).map_err(|error| format!("创建 {label} 目录失败:{error}"))?;
|
||||
|
||||
Reference in New Issue
Block a user