Files
doodle-mini/miniprogram/service/drawServiceFactory.ts
T
2025-11-20 17:35:37 +08:00

48 lines
1.2 KiB
TypeScript

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);
}
}
}