feat: added serialisation for new feature
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 } {
|
||||
|
||||
Reference in New Issue
Block a user