feat: added serialisation for new feature

This commit is contained in:
Daniel Ledda
2023-01-04 13:25:25 +01:00
parent 4955bf6c92
commit b16e20a86a
2 changed files with 7 additions and 1 deletions

View File

@@ -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<TrackEvents> {
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<TrackEvents> {
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<TrackEvents> {
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<TrackEvents> {
alertDeepChange(): void {
this.publisher.notifySubs(TrackEvents.DeepChange);
}
}
}

View File

@@ -24,11 +24,13 @@ export default class TrackUnit implements IPublisher<TrackUnitEvent> {
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<TrackUnitEvent>, eventType: TrackUnitEvent[]): { unbind: () => void } {