| 97 | } |
| 98 | |
| 99 | removeAllLinksOf(removedObject: gdjs.RuntimeObject) { |
| 100 | // Remove the other side of the links |
| 101 | // Note: don't use `this._getMapOfObjectsLinkedWith` as this would |
| 102 | // create an empty map of linked objects if not existing already. |
| 103 | const links = this._links.get(removedObject.id); |
| 104 | if (!links) { |
| 105 | // No existing links to other objects. |
| 106 | // This also means no links to the object from other objects. |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | for (const linkedObjects of links.linkedObjectMap.values()) { |
| 111 | for (let i = 0; i < linkedObjects.length; i++) { |
| 112 | // This is the object on the other side of the link. |
| 113 | // We find the removed object in its list of linked objects and remove it. |
| 114 | const linkedObject = linkedObjects[i]; |
| 115 | |
| 116 | if (this._links.has(linkedObject.id)) { |
| 117 | const otherObjList = this._links |
| 118 | .get(linkedObject.id)! |
| 119 | .linkedObjectMap.get(removedObject.getName()); |
| 120 | |
| 121 | if (!otherObjList) { |
| 122 | logger.error( |
| 123 | `Can't find link from ${linkedObject.id} (${linkedObject.name}) to ${removedObject.id} (${removedObject.name})` |
| 124 | ); |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | const index = otherObjList.indexOf(removedObject); |
| 129 | if (index !== -1) { |
| 130 | otherObjList.splice(index, 1); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | // Remove the links on the removedObject side. |
| 137 | this._links.delete(removedObject.id); |
| 138 | } |
| 139 | |
| 140 | removeLinkBetween(objA: gdjs.RuntimeObject, objB: gdjs.RuntimeObject) { |
| 141 | if (this._links.has(objA.id)) { |