You've already forked FrameTour-BE
refactor(puzzle): 重构元素DTO及新增元素基类
- 将ElementCreateRequest和PuzzleElementDTO中的elementType从Integer改为String - 删除所有类型特定字段,新增config和configMap支持JSON配置 - 新增BaseElement抽象基类定义元素通用行为 - 添加ElementConfig接口和具体实现类ImageConfig、TextConfig - 创建ElementFactory工厂类和ElementRegistrar注册器 - 新增ElementType枚举和ElementValidationException异常类 - 实现ImageElement和TextElement具体元素类 - 添加Position位置信息封装类
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package com.ycwl.basic.puzzle.element.renderer;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 渲染上下文
|
||||
* 封装渲染时需要的所有上下文信息
|
||||
*
|
||||
* @author Claude
|
||||
* @since 2025-01-18
|
||||
*/
|
||||
@Data
|
||||
public class RenderContext {
|
||||
|
||||
/**
|
||||
* 图形上下文
|
||||
*/
|
||||
private Graphics2D graphics;
|
||||
|
||||
/**
|
||||
* 动态数据(key=elementKey, value=实际值)
|
||||
*/
|
||||
private Map<String, String> dynamicData;
|
||||
|
||||
/**
|
||||
* 画布宽度
|
||||
*/
|
||||
private Integer canvasWidth;
|
||||
|
||||
/**
|
||||
* 画布高度
|
||||
*/
|
||||
private Integer canvasHeight;
|
||||
|
||||
/**
|
||||
* 是否启用抗锯齿
|
||||
*/
|
||||
private boolean antiAliasing = true;
|
||||
|
||||
/**
|
||||
* 是否启用高质量渲染
|
||||
*/
|
||||
private boolean highQuality = true;
|
||||
|
||||
public RenderContext(Graphics2D graphics, Map<String, String> dynamicData) {
|
||||
this.graphics = graphics;
|
||||
this.dynamicData = dynamicData;
|
||||
}
|
||||
|
||||
public RenderContext(Graphics2D graphics, Map<String, String> dynamicData,
|
||||
Integer canvasWidth, Integer canvasHeight) {
|
||||
this.graphics = graphics;
|
||||
this.dynamicData = dynamicData;
|
||||
this.canvasWidth = canvasWidth;
|
||||
this.canvasHeight = canvasHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取动态数据(带默认值)
|
||||
*
|
||||
* @param key 数据key
|
||||
* @param defaultValue 默认值
|
||||
* @return 数据值
|
||||
*/
|
||||
public String getDynamicData(String key, String defaultValue) {
|
||||
if (dynamicData == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
return dynamicData.getOrDefault(key, defaultValue);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user