| 16 | * @internal |
| 17 | */ |
| 18 | export class EffectBandSlot { |
| 19 | public bands: EffectBand[]; |
| 20 | |
| 21 | public shared: EffectBandSlotShared; |
| 22 | |
| 23 | public constructor() { |
| 24 | this.bands = []; |
| 25 | this.shared = new EffectBandSlotShared(); |
| 26 | } |
| 27 | |
| 28 | public update(effectBand: EffectBand): void { |
| 29 | // lock band to particular effect if needed |
| 30 | if (!effectBand.info.canShareBand) { |
| 31 | this.shared.uniqueEffectId = effectBand.info.effectId; |
| 32 | } |
| 33 | effectBand.slot = this; |
| 34 | this.bands.push(effectBand); |
| 35 | if (effectBand.height > this.shared.height) { |
| 36 | this.shared.height = effectBand.height; |
| 37 | } |
| 38 | if (!this.shared.firstBeat || effectBand.firstBeat!.isBefore(this.shared.firstBeat)) { |
| 39 | this.shared.firstBeat = effectBand.firstBeat; |
| 40 | } |
| 41 | if (!this.shared.lastBeat || effectBand.lastBeat!.isAfter(this.shared.lastBeat)) { |
| 42 | this.shared.lastBeat = effectBand.lastBeat; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | public canBeUsed(band: EffectBand): boolean { |
| 47 | const canShareBand = |
| 48 | (!this.shared.uniqueEffectId && band.info.canShareBand) || |
| 49 | band.info.effectId === this.shared.uniqueEffectId; |
| 50 | if (!canShareBand) { |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | // first beat in slot |
| 55 | if (!this.shared.firstBeat) { |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | // beat is already added and this is an "extended" band connecting to the previous bar |
| 60 | if(this.shared.lastBeat === band.firstBeat){ |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | // newly added band is after current beat |
| 65 | if (this.shared.lastBeat!.isBefore(band.firstBeat!)) { |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | // historical case, doesn't make much sense, but let's keep it for now |
| 70 | if (this.shared.lastBeat!.isBefore(this.shared.firstBeat)) { |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | return false; |
| 75 | } |
nothing calls this directly
no outgoing calls
no test coverage detected