feat: 增加找字模板

This commit is contained in:
R524809
2025-11-20 17:35:37 +08:00
parent 2e0f8f0fe1
commit 654ea69915
11 changed files with 1061 additions and 532 deletions
+47
View File
@@ -0,0 +1,47 @@
import TextDrawService from './textDrawService';
import FindWordDrawService from './findWordDrawService';
/**
* 绘制服务接口
*/
export interface IDrawService {
draw(list: Array<{ color: string; word: string }>): Promise<void>;
clear(): void;
setPaper(): void;
}
/**
* 模板类型
*/
export type TemplateType = 'grid' | 'find';
/**
* 绘制服务工厂类
* 根据模板类型创建对应的绘制服务实例
*/
export class DrawServiceFactory {
/**
* 创建绘制服务实例
* @param templateType 模板类型
* @param canvas Canvas 对象
* @param ctx 渲染上下文
* @param options 可选配置
* @returns 绘制服务实例
*/
static create(
templateType: TemplateType,
canvas: Canvas,
ctx: RenderingContext,
options?: Record<string, any>,
): IDrawService {
switch (templateType) {
case 'grid':
return new TextDrawService(canvas, ctx, options);
case 'find':
return new FindWordDrawService(canvas, ctx, options);
default:
// 默认使用网格模板
return new TextDrawService(canvas, ctx, options);
}
}
}