/** @format */ import {EventBase, EventGraphicsDraw} from './NodeEvent' import {Data} from '../../GameControl' import {FightWorld} from '../worlds/FightWorld' import FrameAnimation from '../../uiutils/FrameAnimation' import {ccUtils} from '../../utils/ccUtils' const {ccclass, property} = cc._decorator @ccclass export class EventProcess extends cc.Component { world: FightWorld frameAnimation: FrameAnimation graphics: cc.Graphics = null public onAttach(): void {} public onDetach(): void {} public processEvent(event: EventBase): void {} public syncPos(x: number, y: number) { this.node.x = x this.node.y = y this.node.zIndex = -y } public syncDir(dir: cc.Vec2) {} public playFrameAni(url, isLoop: boolean = false, time: number = Infinity) { let res = Data.game.gameAssetMap.get(`atlas/${url}`) if (this.frameAnimation && this.frameAnimation.node && res) { this.frameAnimation.init(res, time / Data.game.gameSpeed, isLoop) this.frameAnimation.play(0, isLoop) } } public playAnimation(url) { let res = Data.game.gameAssetMap.get(`animation/${url}`) if (this.frameAnimation && this.frameAnimation.node && res) { let animation = this.frameAnimation.node.getComponent(cc.Animation) for (let i = animation.getClips().length - 1; i >= 0; i--) { if (animation.getClips()[i]) animation.removeClip(animation.getClips()[i]) } animation.addClip(res as cc.AnimationClip) ccUtils.playAni(res.name, 0, this.frameAnimation.node) } } protected graphicsDraw(event: EventGraphicsDraw) { let graphics = cc.find('graphics', this.node)?.getComponent(cc.Graphics) if (!graphics) return if (!event || event.points.length <= 0) { graphics.clear() return } for (const p of event.points) { p.subSelf(this.node.getPosition()) } graphics.strokeColor = event.color if (event.radius) { graphics.circle(event.points[0].x, event.points[0].y, event.radius) } else { graphics.moveTo(event.points[0].x, event.points[0].y) for (let i = 1; i < event.points.length; i++) { graphics.lineTo(event.points[i].x, event.points[i].y) } graphics.lineTo(event.points[0].x, event.points[0].y) } graphics.stroke() event.points.length = 0 } }