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

excaliburjs / Excalibur / 15354777440

30 May 2025 08:03PM UTC coverage: 87.858% (-1.5%) from 89.344%
15354777440

Pull #3385

github

web-flow
Merge a00f57733 into e6ec66358
Pull Request #3385: updated Meet action to add tolerance

5002 of 6948 branches covered (71.99%)

3 of 5 new or added lines in 2 files covered. (60.0%)

872 existing lines in 83 files now uncovered.

13661 of 15549 relevant lines covered (87.86%)

25187.01 hits per line

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

52.5
/src/engine/Graphics/TiledAnimation.ts
1
import type { ImageFiltering } from './Filtering';
2
import type { ImageWrapConfiguration } from './ImageSource';
3
import type { SourceView } from './Sprite';
4
import { Sprite } from './Sprite';
5
import type { ImageWrapping } from './Wrapping';
6
import type { AnimationOptions } from './Animation';
7
import { Animation } from './Animation';
8
import type { GraphicOptions } from './Graphic';
9
import { TiledSprite } from './TiledSprite';
10
import { watch } from '../Util/Watch';
11
import { Future } from '../Util/Future';
12

13
export interface TiledAnimationOptions {
14
  /**
15
   * Animation to tile
16
   */
17
  animation: Animation;
18
  /**
19
   * Optionally override source view on frame graphics
20
   */
21
  sourceView?: Partial<SourceView>;
22
  /**
23
   * Optionally override filtering options
24
   */
25
  filtering?: ImageFiltering;
26
  /**
27
   * Default wrapping is Repeat for TiledAnimation
28
   */
29
  wrapping?: ImageWrapConfiguration | ImageWrapping;
30
  /**
31
   * Total width in pixels for the tiling to take place
32
   */
33
  width: number;
34
  /**
35
   * Total height in pixels for the tiling to take place
36
   */
37
  height: number;
38
}
39

40
export class TiledAnimation extends Animation {
41
  private _ready = new Future<void>();
1✔
42
  public ready = this._ready.promise;
1✔
43
  private _tiledWidth: number = 0;
1✔
44
  private _tiledHeight: number = 0;
1✔
45
  private _sourceView: Partial<SourceView> = {};
1✔
46
  constructor(options: GraphicOptions & Omit<AnimationOptions, 'frames'> & TiledAnimationOptions) {
47
    super({
1✔
48
      ...options,
49
      frames: options.animation.frames.slice(),
50
      strategy: options.animation.strategy,
51
      frameDuration: options.animation.frameDuration,
52
      speed: options.animation.speed,
53
      reverse: options.animation.isReversed
54
    });
55
    this._sourceView = { ...options.sourceView };
1✔
56
    this._tiledWidth = options.width;
1✔
57
    this._tiledHeight = options.height;
1✔
58

59
    const promises: Promise<void>[] = [];
1✔
60
    for (let i = 0; i < this.frames.length; i++) {
1✔
61
      const graphic = this.frames[i].graphic;
56✔
62
      if (graphic && graphic instanceof Sprite) {
56!
63
        const tiledSprite = new TiledSprite({
56✔
64
          image: graphic.image,
65
          width: options.width,
66
          height: options.height,
67
          sourceView: { ...graphic.sourceView },
68
          wrapping: options.wrapping,
69
          filtering: options.filtering
70
        });
71
        this.frames[i].graphic = tiledSprite;
56✔
72

73
        // There is a new calc'd sourceView when ready
74
        tiledSprite.ready.then(() => {
56✔
75
          tiledSprite.sourceView = { ...tiledSprite.sourceView, ...this._sourceView };
56✔
76
        });
77
        promises.push(tiledSprite.ready);
56✔
78
      }
79
    }
80
    Promise.all(promises).then(() => this._ready.resolve());
1✔
81
  }
82

83
  public static fromAnimation(animation: Animation, options?: Omit<TiledAnimationOptions, 'animation'>): TiledAnimation {
UNCOV
84
    return new TiledAnimation({
×
85
      width: animation.width,
86
      height: animation.height,
87
      ...options,
88
      animation
89
    });
90
  }
91

92
  private _updateSourceView() {
93
    for (let i = 0; i < this.frames.length; i++) {
×
94
      const graphic = this.frames[i].graphic;
×
UNCOV
95
      if (graphic && graphic instanceof Sprite) {
×
UNCOV
96
        graphic.sourceView = { ...graphic.sourceView, ...this._sourceView };
×
97
      }
98
    }
99
  }
100

101
  get sourceView(): Partial<SourceView> {
UNCOV
102
    return watch(this._sourceView, () => this._updateSourceView());
×
103
  }
104

105
  set sourceView(sourceView: Partial<SourceView>) {
UNCOV
106
    this._sourceView = watch(sourceView, () => this._updateSourceView());
×
UNCOV
107
    this._updateSourceView();
×
108
  }
109

110
  private _updateWidthHeight() {
111
    for (let i = 0; i < this.frames.length; i++) {
×
112
      const graphic = this.frames[i].graphic;
×
113
      if (graphic && graphic instanceof Sprite) {
×
114
        graphic.sourceView.height = this._tiledHeight || graphic.height;
×
115
        graphic.destSize.height = this._tiledHeight || graphic.height;
×
UNCOV
116
        graphic.sourceView.width = this._tiledWidth || graphic.width;
×
UNCOV
117
        graphic.destSize.width = this._tiledWidth || graphic.width;
×
118
      }
119
    }
120
  }
121

122
  get width() {
123
    return this._tiledWidth;
1✔
124
  }
125

126
  get height() {
127
    return this._tiledHeight;
1✔
128
  }
129

130
  override set width(width: number) {
UNCOV
131
    this._tiledWidth = width;
×
UNCOV
132
    this._updateWidthHeight();
×
133
  }
134

135
  override set height(height: number) {
UNCOV
136
    this._tiledHeight = height;
×
UNCOV
137
    this._updateWidthHeight();
×
138
  }
139
}
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