import { ContainerAbstract } from '@hatiolab/things-scene' import { getPopupData } from '@fmsim/api' import { MCSStatusMixin, MCSStatusMixinProperties } from './features/mcs-status-mixin' import { LEGEND_UNIT, Legend } from './features/mcs-status-default' import { ParentObjectMixin, ParentObjectMixinProperties } from './features/parent-object-mixin' /** * MCS용 Unit들의 공통 속성을 정의한 오브젝트 */ export default class MCSUnit extends MCSStatusMixin(ParentObjectMixin(ContainerAbstract)) { static get properties(): any { return [...MCSStatusMixinProperties, ...ParentObjectMixinProperties] } get hasTextProperty() { return true } get decorators() { return ['decotag'] } getTheme() { const { legendName } = this.state if (legendName) { return (this.root as any)?.style?.[legendName] } } get status() { return this.data?.STATUS } get auxStatus() { return this.data?.STATUS } get legend(): Legend { return this.getTheme() || this.getLegendFallback() } get auxLegend() { return this.legend } getLegendFallback() { return LEGEND_UNIT } /** * In 2D, ignore `state.alpha`; preserve inherited alpha + editMode-hidden dim. * See MCSMachine.prerender for the full rationale. */ prerender(ctx: any) { const inherited = ctx.globalAlpha super.prerender(ctx) const dim = this.app.isEditMode && this.hidden ? 0.5 : 1 ctx.globalAlpha = inherited * dim } contains(x, y) { var { left, top, width, height, lineWidth = 0 } = this.state var extend = lineWidth / 2 return ( x < Math.max(left + width, left) + extend && x > Math.min(left + width, left) - extend && y < Math.max(top + height, top) + extend && y > Math.min(top + height, top) - extend ) } set path(path) { var left_top = path[0] var right_bottom = path[2] this.set({ left: left_top.x, top: left_top.y, width: right_bottom.x - left_top.x, height: right_bottom.y - left_top.y }) } get path() { var { left = 0, top = 0, width = 0, height = 0 } = this.state return [ { x: left, y: top }, { x: left + width, y: top }, { x: left + width, y: top + height }, { x: left, y: top + height } ] } async detailInfo() { const { type, id } = this.state if (!id) { return } return await getPopupData(type, id) } }