Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Commit

Permalink
[fix] update node id splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
cedoor committed Jun 8, 2018
1 parent 44e5022 commit eecf2b4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/map/handlers/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ export default class History {
* Set the right counter value of the nodes.
*/
private setCounter() {
let id = this.map.nodes.getNodes().map((node: Node) => parseInt(node.id.split("_")[2]));
let id = this.map.nodes.getNodes().map((node: Node) => {
let words = node.id.split("_");
return parseInt(words[words.length - 1])
});
this.map.nodes.setCounter(Math.max(...id) + 1);
}

Expand All @@ -168,8 +171,8 @@ export default class History {
*/
private sanitizeNodeId(oldId: string) {
if (typeof oldId === "string") {
let oldIdSplitted = oldId.split("_");
return this.map.id + "_" + oldIdSplitted[1] + "_" + oldIdSplitted[2];
let words = oldId.split("_");
return this.map.id + "_" + words[words.length - 2] + "_" + words[words.length - 1];
}
}

Expand Down Expand Up @@ -271,7 +274,8 @@ export default class History {
private translateNodePositions(snapshot: MapSnapshot) {
let oldRootNode = this.map.nodes.getRoot(),
newRootNode = (<any>snapshot).find((node: ExportNodeProperties) => {
return node.id.split("_")[2] === "0";
let words = node.id.split("_");
return words[words.length - 1] === "0";
}),
dx = newRootNode.coordinates.x - oldRootNode.coordinates.x,
dy = newRootNode.coordinates.y - oldRootNode.coordinates.y;
Expand Down

0 comments on commit eecf2b4

Please sign in to comment.