(sharedDataBag: Map<string, unknown> | null = null)
| 1193 | |
| 1194 | private _noteIdBag: NoteIdBag | null = null; |
| 1195 | public chain(sharedDataBag: Map<string, unknown> | null = null) { |
| 1196 | // mainly for backwards compat in case we reach this code from somewhere outside. |
| 1197 | if (sharedDataBag === null) { |
| 1198 | return; |
| 1199 | } |
| 1200 | |
| 1201 | // if we have some IDs from a serialization flow, |
| 1202 | // we need to lookup/register the notes correctly |
| 1203 | if (this._noteIdBag !== null) { |
| 1204 | // get or create lookup |
| 1205 | let noteIdLookup: Map<number, Note>; |
| 1206 | if (sharedDataBag.has(Note._noteIdLookupKey)) { |
| 1207 | noteIdLookup = sharedDataBag.get(Note._noteIdLookupKey) as Map<number, Note>; |
| 1208 | } else { |
| 1209 | noteIdLookup = new Map<number, Note>(); |
| 1210 | sharedDataBag.set(Note._noteIdLookupKey, noteIdLookup); |
| 1211 | } |
| 1212 | |
| 1213 | // if this note is a source note for any effect, remember it for later |
| 1214 | // the destination note will look it up for linking |
| 1215 | if ( |
| 1216 | this._noteIdBag.hammerPullDestinationNoteId !== -1 || |
| 1217 | this._noteIdBag.tieDestinationNoteId !== -1 || |
| 1218 | this._noteIdBag.slurDestinationNoteId !== -1 || |
| 1219 | this._noteIdBag.slideTargetNoteId !== -1 |
| 1220 | ) { |
| 1221 | noteIdLookup.set(this.id, this); |
| 1222 | } |
| 1223 | |
| 1224 | // on any effect destiniation, lookup the origin which should already be |
| 1225 | // registered |
| 1226 | if (this._noteIdBag.hammerPullOriginNoteId !== -1) { |
| 1227 | this.hammerPullOrigin = noteIdLookup.get(this._noteIdBag.hammerPullOriginNoteId)!; |
| 1228 | this.hammerPullOrigin.hammerPullDestination = this; |
| 1229 | } |
| 1230 | if (this._noteIdBag.tieOriginNoteId !== -1) { |
| 1231 | this.tieOrigin = noteIdLookup.get(this._noteIdBag.tieOriginNoteId)!; |
| 1232 | this.tieOrigin.tieDestination = this; |
| 1233 | } |
| 1234 | if (this._noteIdBag.slurOriginNoteId !== -1) { |
| 1235 | this.slurOrigin = noteIdLookup.get(this._noteIdBag.slurOriginNoteId)!; |
| 1236 | this.slurOrigin.slurDestination = this; |
| 1237 | } |
| 1238 | |
| 1239 | if (this._noteIdBag.slideOriginNoteId !== -1) { |
| 1240 | this.slideOrigin = noteIdLookup.get(this._noteIdBag.slideOriginNoteId)!; |
| 1241 | this.slideOrigin.slideTarget = this; |
| 1242 | } |
| 1243 | |
| 1244 | this._noteIdBag = null; // not needed anymore |
| 1245 | } else { |
| 1246 | // no tie destination at all? |
| 1247 | if (!this.isTieDestination && this.tieOrigin === null) { |
| 1248 | return; |
| 1249 | } |
| 1250 | |
| 1251 | const tieOrigin = this.tieOrigin ?? Note.findTieOrigin(this); |
| 1252 | if (!tieOrigin) { |
no test coverage detected