feat: 添加液化操作串行Promise队列,确保液化操作按顺序执行
This commit is contained in:
@@ -46,6 +46,9 @@ export class LiquifyManager {
|
|||||||
|
|
||||||
// 初始化液化管理器
|
// 初始化液化管理器
|
||||||
this.initialize();
|
this.initialize();
|
||||||
|
|
||||||
|
// 新增:液化操作串行Promise队列
|
||||||
|
this._liquifyPromise = Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,30 +128,45 @@ export class LiquifyManager {
|
|||||||
* @returns {ImageData} 处理后的图像数据
|
* @returns {ImageData} 处理后的图像数据
|
||||||
*/
|
*/
|
||||||
async applyLiquify(targetObject, mode, params, x, y) {
|
async applyLiquify(targetObject, mode, params, x, y) {
|
||||||
if (!this.enhancedManager || !targetObject) {
|
// 串行化:等待上一次液化操作完成
|
||||||
console.error("液化管理器未正确初始化");
|
this._liquifyPromise = this._liquifyPromise.then(async () => {
|
||||||
return null;
|
if (!this.enhancedManager || !targetObject) {
|
||||||
}
|
console.error("液化管理器未正确初始化");
|
||||||
|
return null;
|
||||||
console.log(`LiquifyManager.applyLiquify: 模式=${mode}, 坐标=(${x}, ${y}), 参数=`, params);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 直接调用EnhancedLiquifyManager的applyLiquify方法
|
|
||||||
// 避免重复设置参数,让EnhancedLiquifyManager处理参数设置
|
|
||||||
const resultData = await this.enhancedManager.applyLiquify(targetObject, mode, params, x, y);
|
|
||||||
|
|
||||||
// 确保返回结果数据
|
|
||||||
if (!resultData) {
|
|
||||||
console.warn("液化变形没有返回结果数据");
|
|
||||||
} else {
|
|
||||||
console.log("✅ 液化变形成功,返回图像数据尺寸:", resultData.width, "x", resultData.height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultData;
|
console.log(
|
||||||
} catch (error) {
|
`LiquifyManager.applyLiquify: 模式=${mode}, 坐标=(${x}, ${y}), 参数=`,
|
||||||
console.error("液化变形应用失败:", error);
|
params
|
||||||
return null;
|
);
|
||||||
}
|
|
||||||
|
try {
|
||||||
|
// 直接调用EnhancedLiquifyManager的applyLiquify方法
|
||||||
|
const resultData = await this.enhancedManager.applyLiquify(
|
||||||
|
targetObject,
|
||||||
|
mode,
|
||||||
|
params,
|
||||||
|
x,
|
||||||
|
y
|
||||||
|
);
|
||||||
|
if (!resultData) {
|
||||||
|
console.warn("液化变形没有返回结果数据");
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
"✅ 液化变形成功,返回图像数据尺寸:",
|
||||||
|
resultData.width,
|
||||||
|
"x",
|
||||||
|
resultData.height
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return resultData;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("液化变形应用失败:", error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 返回当前Promise,保证外部可await
|
||||||
|
return this._liquifyPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user