feat: added serialisation for new feature
This commit is contained in:
@@ -31,6 +31,7 @@ export type TrackSerial = {
|
|||||||
units: {
|
units: {
|
||||||
isOn: boolean[],
|
isOn: boolean[],
|
||||||
type: TrackUnitType[],
|
type: TrackUnitType[],
|
||||||
|
stickingType: TrackUnitStickingType[],
|
||||||
},
|
},
|
||||||
barCount: number,
|
barCount: number,
|
||||||
loopLength: number,
|
loopLength: number,
|
||||||
@@ -76,6 +77,7 @@ export default class Track implements IPublisher<TrackEvents> {
|
|||||||
const units = serial.units.isOn.map((isOn, i) => new TrackUnit({
|
const units = serial.units.isOn.map((isOn, i) => new TrackUnit({
|
||||||
on: isOn,
|
on: isOn,
|
||||||
type: serial.units.type[i],
|
type: serial.units.type[i],
|
||||||
|
stickingType: serial.units.stickingType[i],
|
||||||
parent: track,
|
parent: track,
|
||||||
}));
|
}));
|
||||||
track.unitRecord.length = 0;
|
track.unitRecord.length = 0;
|
||||||
@@ -213,6 +215,7 @@ export default class Track implements IPublisher<TrackEvents> {
|
|||||||
units: {
|
units: {
|
||||||
isOn: this.unitRecord.map(unit => unit.isOn()),
|
isOn: this.unitRecord.map(unit => unit.isOn()),
|
||||||
type: this.unitRecord.map(unit => unit.getType()),
|
type: this.unitRecord.map(unit => unit.getType()),
|
||||||
|
stickingType: this.unitRecord.map(unit => unit.getStickingType()),
|
||||||
},
|
},
|
||||||
barCount: this.barCount,
|
barCount: this.barCount,
|
||||||
loopLength: this.loopLength,
|
loopLength: this.loopLength,
|
||||||
@@ -227,6 +230,7 @@ export default class Track implements IPublisher<TrackEvents> {
|
|||||||
typeof serial.units === "object" &&
|
typeof serial.units === "object" &&
|
||||||
Array.isArray(serial.units.isOn) &&
|
Array.isArray(serial.units.isOn) &&
|
||||||
Array.isArray(serial.units.type) &&
|
Array.isArray(serial.units.type) &&
|
||||||
|
Array.isArray(serial.units.stickingType) &&
|
||||||
typeof serial.barCount === "number" &&
|
typeof serial.barCount === "number" &&
|
||||||
typeof serial.loopLength === "number" &&
|
typeof serial.loopLength === "number" &&
|
||||||
typeof serial.looping === "boolean";
|
typeof serial.looping === "boolean";
|
||||||
|
|||||||
@@ -24,11 +24,13 @@ export default class TrackUnit implements IPublisher<TrackUnitEvent> {
|
|||||||
constructor(options: {
|
constructor(options: {
|
||||||
on?: boolean,
|
on?: boolean,
|
||||||
type?: TrackUnitType,
|
type?: TrackUnitType,
|
||||||
|
stickingType?: TrackUnitStickingType,
|
||||||
parent: Track,
|
parent: Track,
|
||||||
}) {
|
}) {
|
||||||
this.parent = options.parent;
|
this.parent = options.parent;
|
||||||
this.on = options.on ?? false;
|
this.on = options.on ?? false;
|
||||||
this.setType(options.type ?? "Normal");
|
this.setType(options.type ?? "Normal");
|
||||||
|
this.setStickingType(options.stickingType ?? "none");
|
||||||
}
|
}
|
||||||
|
|
||||||
addSubscriber(subscriber: ISubscriber<TrackUnitEvent>, eventType: TrackUnitEvent[]): { unbind: () => void } {
|
addSubscriber(subscriber: ISubscriber<TrackUnitEvent>, eventType: TrackUnitEvent[]): { unbind: () => void } {
|
||||||
|
|||||||
Reference in New Issue
Block a user