Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | 1x 1x 1x 1x 1x 1x 1x 1x 36x 36x 36x 36x 36x 53x 53x 53x 53x 53x 36x 1x 1x 1x 1x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 53x 53x 53x 53x 53x 53x 36x 36x 36x 36x 36x 36x 111x 1x 1x 110x 110x 36x 36x 36x 36x 36x 36x 22x 22x 22x 22x 36x 36x 36x 36x 36x 36x 36x 3x 3x 3x 3x 3x 36x 36x 36x 36x 36x 36x 36x 36x 2x 2x 2x 36x 36x 36x 36x 36x 36x 36x 2x 2x 2x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 1x 1x 1x 36x 36x 36x 36x 36x 36x 36x 36x 1x 1x 1x 36x 36x 36x 36x 36x 36x 36x 2x 2x 2x 36x 36x 36x 36x 36x 36x 36x 1x 1x 1x 36x 36x 36x 36x 36x 36x 36x 36x 36x 2x 2x 2x 36x 36x 36x 36x 36x 36x 36x 36x 36x 2x 2x 2x 36x 36x 36x 36x 36x 36x 36x 36x 36x 2x 2x 2x 36x 36x 36x 36x 36x 36x 36x 2x 2x 2x 36x 36x 36x 36x 36x 36x 36x 36x 2x 2x 2x 36x 36x 36x 36x 36x 36x 36x 2x 2x 2x 36x 36x 36x 36x 36x 36x 36x 2x 2x 2x 36x 36x 36x 36x 36x 36x 2x 2x 2x 36x 36x 36x 36x 36x 36x 36x 2x 2x 2x 36x 36x 36x 36x 36x 36x 36x 36x 13x 13x 1x 1x 12x 12x 12x 12x 12x 36x 36x 36x 36x 36x 36x 36x 3x 3x 3x 3x 3x 3x 3x 3x 36x 36x 36x 36x 36x 36x 2x 2x 2x 2x 36x 36x 36x 36x 36x 36x 36x 2x 2x 2x 36x 1x 1x | import { getUUID } from '../../utils/get-uuid';
import { illusionService } from '../illusion-service';
import { sourceHandler } from './source-handler';
import { filterHandler } from './filter-handler';
import { FillType } from '../../enums/fill-type';
import { MixerType } from '../../enums/mixer-type';
import { FilterType } from '../../enums/filter-type';
class Layer {
public source: string;
public filters: Array<string>;
constructor(
public cLayer: CLayer,
) {
this.source = '';
this.filters = [];
}
}
/**
* 图层工具类
*/
export class LayerHandler {
idPoll: number;
map: Map<string, Layer>;
constructor() {
this.map = new Map();
this.idPoll = 0;
}
/**
* 创建图层实例
* @param layerId - 图层 id
* @returns 图层实例 id,与传入的图层 id 不一致
*/
create() {
const id = getUUID();
const cLayer = new illusionService.module.Layer(this.idPoll);
this.idPoll += 1;
this.map.set(id, new Layer(cLayer));
return { id };
}
/**
* 获取图层实例
* @param id - 图层实例 id
*/
getLayer(id: string): Layer {
if(!this.map.has(id)) {
throw new Error(`layer: ${id} is not exist`);
}
return this.map.get(id)!;
}
/**
* 销毁图层实例
* @param id - 图层实例 id
*/
destory(id: string) {
const layer = this.getLayer(id);
layer.cLayer.delete();
this.map.delete(id);
}
/**
* 设置图层数据源
* @param id - 图层实例 id
* @param sourceId - 数据源 id
*/
setSource(id: string, sourceId: string) {
const layer = this.getLayer(id);
const source = sourceHandler.getSource(sourceId);
layer.cLayer.setSource(source.cSource);
layer.source = sourceId;
}
/**
* 设置渲染时间段,不在时间周期内时不作渲染,默认全程渲染
* @param id - 图层实例 id
* @param startTime - 开始时间
* @param duration - 持续时间
*/
setTimeRange(id: string, startTime: number, duration: number): void {
const layer = this.getLayer(id);
layer.cLayer.setTimeRange(startTime, duration);
}
/**
* 设置图层顺序
* @param id - 图层实例 id
* @param zOrder - 越高的图层在越上面
*/
setZOrder(id: string,zOrder: number): void {
const layer = this.getLayer(id);
layer.cLayer.setZOrder(zOrder);
}
/**
* 设置图层最终显示视口区域
* @param id - 图层实例 id
* @param x - 起始 x 坐标
* @param y - 起始 y 坐标
* @param width - 视口宽度
* @param height - 视口高度
*/
setViewPort(id: string, x: number, y: number, width: number, height: number): void {
const layer = this.getLayer(id);
layer.cLayer.setViewPort(x, y, width, height);
}
/**
* 翻转视口
* @param id - 图层实例 id
* @param vertical - 垂直翻转
* @param horizontal - 水平翻转
*/
setFlip(id: string, vertical: boolean, horizontal: boolean): void {
const layer = this.getLayer(id);
layer.cLayer.setFlip(vertical, horizontal);
}
/**
* 设置图层不透明度
* @param id - 图层实例 id
* @param opacity - 不透明度
*/
setOpacity(id: string, opacity: number): void {
const layer = this.getLayer(id);
layer.cLayer.setOpacity(opacity);
}
/**
* 设置图层填充方案
* @param id - 图层实例 id
* @param type - 填充方案
*/
setFillType(id: string, type: FillType): void {
const layer = this.getLayer(id);
layer.cLayer.setFillType(type);
}
/**
* 平移图层
* @param id - 图层实例 id
* @param x - x 轴平移量
* @param y - y 轴平移量
* @param z - z 轴平移量
*/
translate(id: string, x: number, y: number, z: number): void {
const layer = this.getLayer(id);
layer.cLayer.translate(x, y, z);
}
/**
* 缩放图层
* @param id - 图层实例 id
* @param x - x 轴缩放比
* @param y - y 轴缩放比
* @param z - z 轴缩放比
*/
scale(id: string, x: number, y: number, z: number): void {
const layer = this.getLayer(id);
layer.cLayer.scale(x, y, z);
}
/**
* 旋转图层
* @param id - 图层实例 id
* @param x - x 轴旋转角度
* @param y - y 轴旋转角度
* @param z - z 轴旋转角度
*/
rotate(id: string, x: number, y: number, z: number): void {
const layer = this.getLayer(id);
layer.cLayer.rotate(x, y, z);
}
/**
* 设置图层混合类型
* @param id - 图层实例 id
* @param type - 混合类型
*/
setMixerType(id: string, type: MixerType): void {
const layer = this.getLayer(id);
layer.cLayer.setMixerType(type);
}
/**
* 设置混合模式的参数
* @param id - 图层实例 id
* @param name - 参数名
* @param value - 参数值
*/
updateMixerValue(id: string, name: string, value: number): void {
const layer = this.getLayer(id);
layer.cLayer.updateMixerValue(name, value);
}
/**
* 设置图层入场动画
* @param id - 图层实例 id
* @param type - 动画类型
*/
setEnterAnimation(id: string, type: FilterType): void {
const layer = this.getLayer(id);
layer.cLayer.setEnterAnimation(type);
}
/**
* 更新进场动画进度
* @param id - 图层实例 id
* @param progress - 进度 [0.0, 1.0]
*/
updateEnterAnimationProgress(id:string, progress: number): void {
const layer = this.getLayer(id);
layer.cLayer.updateEnterAnimationProgress(progress);
}
/**
* 设置图层出场动画
* @param id - 图层实例 id
* @param type - 动画类型
*/
setExitAnimation(id: string, type: any): void {
const layer = this.getLayer(id);
layer.cLayer.setExitAnimation(type);
}
/**
* 更新出场动画进度
* @param id - 图层实例 id
* @param progress - 进度 [0.0, 1.0]
*/
updateExitAnimationProgress(id: string, progress: number): void {
const layer = this.getLayer(id);
layer.cLayer.updateExitAnimationProgress(progress);
}
/**
* 添加图层的叠加效果(滤镜)
* @param id - 图层实例 id
* @param filterId - 叠加效果(滤镜) id
* @param wrapPixelAround 是否重复边缘像素,[是]则在transform之前叠加效果,[否]则在transform之后叠加效果
*/
addEffect(id: string, filterId: string, wrapPixelAround: boolean = true): void {
const layer = this.getLayer(id);
if(layer.filters.includes(filterId)) {
return;
}
const filter = filterHandler.getFilter(filterId);
layer.cLayer.addEffect(filter.cFilter, wrapPixelAround);
layer.filters.push(filterId);
}
/**
* 移除指定效果(滤镜)
* @param id - 图层实例 id
* @param filterId - 叠加效果(滤镜) id
*/
removeEffect(id: string, filterId: string): void {
const layer = this.getLayer(id);
const index = layer.filters.indexOf(filterId);
if(index >= 0) {
const filter = filterHandler.getFilter(filterId);
layer.cLayer.removeEffect(filter.cFilter);
layer.filters.splice(index, 1);
}
}
/**
* 清空所有特效列表
* @param id - 图层实例 id
*/
clearEffects(id: string): void {
const layer = this.getLayer(id);
layer.cLayer.clearEffects();
layer.filters = [];
}
/**
* 更新图层最终效果强度
* @param id - 图层实例 id
* @param intensity 强度,[0.0, 1.0]
*/
updateEffectIntensity(id: string, intensity: number): void {
const layer = this.getLayer(id);
return layer.cLayer.updateEffectIntensity(intensity);
}
}
export const layerHandler = new LayerHandler(); |