import {LitElement, html, unsafeCSS, svg, nothing} from 'lit'; import {customElement, property} from 'lit/decorators.js'; import compentStyle from './main-engine.css?inline'; import {InstrumentState} from '../types'; import { atSetpoint, convertThrustAdvices, thrusterColors, thrusterTopSingleSided, setpointSvg, } from '../thruster/thruster'; import {LinearAdvice} from '../thruster/advice'; @customElement('obc-main-engine') export class ObcMainEngine extends LitElement { @property({type: Number}) thrust: number = 0; @property({type: Number}) thrustSetpoint: number | undefined; @property({type: Boolean}) thrustTouching: boolean = false; @property({type: Boolean}) atThrustSetpoint: boolean = false; @property({type: Number}) speed: number = 0; @property({type: Number}) speedSetpoint: number | undefined; @property({type: Boolean}) speedTouching: boolean = false; @property({type: Boolean}) atSpeedSetpoint: boolean = false; @property({type: Boolean}) disableAutoAtThrustSetpoint: boolean = false; @property({type: Boolean}) disableAutoAtSpeedSetpoint: boolean = false; @property({type: Number}) autoAtThrustSetpointDeadband: number = 1; @property({type: Number}) autoAtSpeedSetpointDeadband: number = 1; @property({type: Number}) thrustSetpointAtZeroDeadband: number = 0.5; @property({type: Number}) speedSetpointAtZeroDeadband: number = 0.5; @property({type: String}) state: InstrumentState = InstrumentState.inCommand; @property({type: Array}) thrustAdvices: LinearAdvice[] = []; override render() { const thrustSetpointAtZero = Math.abs(this.thrustSetpoint || 0) < this.thrustSetpointAtZeroDeadband; const speedSetpointAtZero = Math.abs(this.speedSetpoint || 0) < this.speedSetpointAtZeroDeadband; const thrustAtSetpoint = atSetpoint(this.thrust, this.thrustSetpoint, { atSetpoint: this.atThrustSetpoint, autoAtSetpoint: !this.disableAutoAtThrustSetpoint, autoSetpointDeadband: this.autoAtThrustSetpointDeadband, touching: this.thrustTouching, }); const cThrust = thrusterColors( { atSetpoint: thrustAtSetpoint, touching: this.thrustTouching, }, this.state ); const speedAtSetpoint = atSetpoint(this.speed, this.speedSetpoint, { atSetpoint: this.atSpeedSetpoint, autoAtSetpoint: !this.disableAutoAtSpeedSetpoint, autoSetpointDeadband: this.autoAtSpeedSetpointDeadband, touching: this.speedTouching, }); const cSpeed = thrusterColors( { atSetpoint: speedAtSetpoint, touching: this.speedTouching, }, this.state ); const container = svg``; const border = svg``; const frameLeft = svg``; const frameRight = svg``; const thrustCenter = svg``; const {topAdvices: topThrustAdvice, bottomAdvices: bottomThrustAdvice} = convertThrustAdvices(this.thrustAdvices, this.thrust); const thrustTop = svg` ${thrusterTopSingleSided( 174, Math.max(this.thrust, 0), {box: cThrust.boxColor, container: ''}, { hideContainer: true, hideTicks: cThrust.hideTicks, flipAdicePattern: false, narrow: false, }, topThrustAdvice )}`; const thrusterBottom = svg` ${thrusterTopSingleSided( 174, Math.max(-this.thrust, 0), {box: cThrust.boxColor, container: ''}, { hideContainer: true, hideTicks: cThrust.hideTicks, flipAdicePattern: false, narrow: false, }, bottomThrustAdvice )}`; const thrustSetpoint = this.thrustSetpoint !== undefined ? svg`${setpointSvg( 174, this.thrustSetpoint, thrustSetpointAtZero, { fill: cThrust.setPointColor, stroke: 'var(--border-silhouette-color)', }, { inCommand: this.state === InstrumentState.inCommand, singleSided: true, narrow: false, } )}` : nothing; const speedHeight = 352 * (this.speed / 100) + 2; const speedY = 176 - speedHeight; const speedBoxColor = this.state === InstrumentState.inCommand ? 'var(--instrument-enhanced-tertiary-color)' : 'var(--instrument-regular-tertiary-color)'; const speedBox = svg``; const speedLine = svg` `; const speedSetpoint = this.speedSetpoint !== undefined ? svg`${setpointSvg( 350, this.speedSetpoint, speedSetpointAtZero, { fill: cSpeed.setPointColor, stroke: 'var(--border-silhouette-color)', }, { inCommand: this.state === InstrumentState.inCommand, singleSided: true, narrow: false, } )}` : nothing; return html`
${container} ${frameLeft} ${frameRight} ${thrustCenter} ${thrustTop} ${thrusterBottom} ${speedBox} ${speedLine} ${border} ${thrustSetpoint} ${speedSetpoint}
`; } static override styles = unsafeCSS(compentStyle); } declare global { interface HTMLElementTagNameMap { 'obc-main-engine': ObcMainEngine; } }