• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

excaliburjs / Excalibur / 14804036802

02 May 2025 09:58PM UTC coverage: 5.927% (-83.4%) from 89.28%
14804036802

Pull #3404

github

web-flow
Merge 5c103d7f8 into 0f2ccaeb2
Pull Request #3404: feat: added Graph module to Math

234 of 8383 branches covered (2.79%)

229 of 246 new or added lines in 1 file covered. (93.09%)

13145 existing lines in 208 files now uncovered.

934 of 15759 relevant lines covered (5.93%)

4.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/engine/EntityComponentSystem/Components/TransformComponent.ts
1
import { Vector } from '../../Math/vector';
2
import { CoordPlane } from '../../Math/coord-plane';
3
import { Transform } from '../../Math/transform';
4
import { Component } from '../Component';
5
import { Entity } from '../Entity';
6
import { Observable } from '../../Util/Observable';
7
import { Logger } from '../../Util/Log';
8

9
export class TransformComponent extends Component {
UNCOV
10
  private _logger = Logger.getInstance();
×
UNCOV
11
  private _parentComponent: TransformComponent | null = null;
×
UNCOV
12
  private _transform = new Transform();
×
13
  public get() {
UNCOV
14
    return this._transform;
×
15
  }
16

UNCOV
17
  private _addChildTransform = (child: Entity) => {
×
UNCOV
18
    const childTxComponent = child.get(TransformComponent);
×
UNCOV
19
    if (childTxComponent) {
×
UNCOV
20
      childTxComponent._transform.parent = this._transform;
×
UNCOV
21
      childTxComponent._parentComponent = this;
×
22
    }
23
  };
24
  onAdd(owner: Entity): void {
UNCOV
25
    for (const child of owner.children) {
×
26
      this._addChildTransform(child);
×
27
    }
UNCOV
28
    owner.childrenAdded$.subscribe((child) => this._addChildTransform(child));
×
UNCOV
29
    owner.childrenRemoved$.subscribe((child) => {
×
UNCOV
30
      const childTxComponent = child.get(TransformComponent);
×
UNCOV
31
      if (childTxComponent) {
×
UNCOV
32
        childTxComponent._transform.parent = null;
×
UNCOV
33
        childTxComponent._parentComponent = null;
×
34
      }
35
    });
36
  }
37
  onRemove(_previousOwner: Entity): void {
UNCOV
38
    this._transform.parent = null;
×
UNCOV
39
    this._parentComponent = null;
×
40
  }
41

42
  /**
43
   * Observable that emits when the z index changes on this component
44
   */
UNCOV
45
  public zIndexChanged$ = new Observable<number>();
×
46

47
  /**
48
   * The z-index ordering of the entity, a higher values are drawn on top of lower values.
49
   * For example z=99 would be drawn on top of z=0.
50
   */
51
  public get z(): number {
UNCOV
52
    return this._transform.z;
×
53
  }
54

55
  public set z(val: number) {
UNCOV
56
    const oldz = this._transform.z;
×
UNCOV
57
    this._transform.z = val;
×
UNCOV
58
    if (oldz !== val) {
×
UNCOV
59
      this.zIndexChanged$.notifyAll(val);
×
60
    }
61
  }
62

63
  public get globalZ() {
UNCOV
64
    return this._transform.globalZ;
×
65
  }
66

67
  public set globalZ(z: number) {
UNCOV
68
    this._transform.globalZ = z;
×
69
  }
70

UNCOV
71
  private _coordPlane = CoordPlane.World;
×
72
  /**
73
   * The {@apilink CoordPlane | `coordinate plane`} for this transform for the entity.
74
   */
75
  public get coordPlane() {
UNCOV
76
    if (this._parentComponent) {
×
UNCOV
77
      return this._parentComponent.coordPlane;
×
78
    }
UNCOV
79
    return this._coordPlane;
×
80
  }
81

82
  public set coordPlane(value: CoordPlane) {
UNCOV
83
    if (!this._parentComponent) {
×
UNCOV
84
      this._coordPlane = value;
×
85
    } else {
UNCOV
86
      this._logger.warn(
×
87
        `Cannot set coordinate plane on child entity ${this.owner?.name}, children inherit their coordinate plane from their parents.`
×
88
      );
89
    }
90
  }
91

92
  get pos() {
UNCOV
93
    return this._transform.pos;
×
94
  }
95
  set pos(v: Vector) {
UNCOV
96
    this._transform.pos = v;
×
97
  }
98

99
  get globalPos() {
UNCOV
100
    return this._transform.globalPos;
×
101
  }
102
  set globalPos(v: Vector) {
UNCOV
103
    this._transform.globalPos = v;
×
104
  }
105

106
  get rotation() {
UNCOV
107
    return this._transform.rotation;
×
108
  }
109
  set rotation(rotation) {
UNCOV
110
    this._transform.rotation = rotation;
×
111
  }
112

113
  get globalRotation() {
UNCOV
114
    return this._transform.globalRotation;
×
115
  }
116
  set globalRotation(rotation) {
UNCOV
117
    this._transform.globalRotation = rotation;
×
118
  }
119

120
  get scale() {
UNCOV
121
    return this._transform.scale;
×
122
  }
123
  set scale(v: Vector) {
UNCOV
124
    this._transform.scale = v;
×
125
  }
126

127
  get globalScale() {
UNCOV
128
    return this._transform.globalScale;
×
129
  }
130
  set globalScale(v: Vector) {
UNCOV
131
    this._transform.globalScale = v;
×
132
  }
133

134
  applyInverse(v: Vector) {
UNCOV
135
    return this._transform.applyInverse(v);
×
136
  }
137

138
  apply(v: Vector) {
UNCOV
139
    return this._transform.apply(v);
×
140
  }
141

142
  clone(): TransformComponent {
UNCOV
143
    const component = new TransformComponent();
×
UNCOV
144
    component._transform = this._transform.clone();
×
UNCOV
145
    return component;
×
146
  }
147
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc