From b16e20a86ae4a4c9e532ec288c8d23b68bd156b7 Mon Sep 17 00:00:00 2001 From: Daniel Ledda Date: Wed, 4 Jan 2023 13:25:25 +0100 Subject: [PATCH] feat: added serialisation for new feature --- src/Track.ts | 6 +++++- src/TrackUnit.ts | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Track.ts b/src/Track.ts index 680e7bc..3d45d05 100644 --- a/src/Track.ts +++ b/src/Track.ts @@ -31,6 +31,7 @@ export type TrackSerial = { units: { isOn: boolean[], type: TrackUnitType[], + stickingType: TrackUnitStickingType[], }, barCount: number, loopLength: number, @@ -76,6 +77,7 @@ export default class Track implements IPublisher { const units = serial.units.isOn.map((isOn, i) => new TrackUnit({ on: isOn, type: serial.units.type[i], + stickingType: serial.units.stickingType[i], parent: track, })); track.unitRecord.length = 0; @@ -213,6 +215,7 @@ export default class Track implements IPublisher { units: { isOn: this.unitRecord.map(unit => unit.isOn()), type: this.unitRecord.map(unit => unit.getType()), + stickingType: this.unitRecord.map(unit => unit.getStickingType()), }, barCount: this.barCount, loopLength: this.loopLength, @@ -227,6 +230,7 @@ export default class Track implements IPublisher { typeof serial.units === "object" && Array.isArray(serial.units.isOn) && Array.isArray(serial.units.type) && + Array.isArray(serial.units.stickingType) && typeof serial.barCount === "number" && typeof serial.loopLength === "number" && typeof serial.looping === "boolean"; @@ -236,4 +240,4 @@ export default class Track implements IPublisher { alertDeepChange(): void { this.publisher.notifySubs(TrackEvents.DeepChange); } -} \ No newline at end of file +} diff --git a/src/TrackUnit.ts b/src/TrackUnit.ts index 13ea2e7..ecbcdc1 100644 --- a/src/TrackUnit.ts +++ b/src/TrackUnit.ts @@ -24,11 +24,13 @@ export default class TrackUnit implements IPublisher { constructor(options: { on?: boolean, type?: TrackUnitType, + stickingType?: TrackUnitStickingType, parent: Track, }) { this.parent = options.parent; this.on = options.on ?? false; this.setType(options.type ?? "Normal"); + this.setStickingType(options.stickingType ?? "none"); } addSubscriber(subscriber: ISubscriber, eventType: TrackUnitEvent[]): { unbind: () => void } {