make AutoLayout skip over coordinates if there is a mapping at that exact position
This commit is contained in:
parent
20a32afe3b
commit
bb013787b6
2 changed files with 21 additions and 6 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
import Active from './Active'
|
||||||
|
|
||||||
const AutoLayout = {
|
const AutoLayout = {
|
||||||
nextX: 0,
|
nextX: 0,
|
||||||
nextY: 0,
|
nextY: 0,
|
||||||
|
@ -7,7 +9,7 @@ const AutoLayout = {
|
||||||
nextYshift: 0,
|
nextYshift: 0,
|
||||||
timeToTurn: 0,
|
timeToTurn: 0,
|
||||||
|
|
||||||
getNextCoord: function () {
|
getNextCoord: function (opts = {}) {
|
||||||
var self = AutoLayout
|
var self = AutoLayout
|
||||||
var nextX = self.nextX
|
var nextX = self.nextX
|
||||||
var nextY = self.nextY
|
var nextY = self.nextY
|
||||||
|
@ -49,9 +51,22 @@ const AutoLayout = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
if (opts.map && self.coordsTaken(nextX, nextY, opts.map)) {
|
||||||
x: nextX,
|
// check if the coordinate is already taken on the current map
|
||||||
y: nextY
|
return self.getNextCoord(opts)
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
x: nextX,
|
||||||
|
y: nextY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
coordsTaken: function(x, y, map) {
|
||||||
|
const mappings = map.getMappings()
|
||||||
|
if (mappings.findWhere({ xloc: x, yloc: y })) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resetSpiral: function () {
|
resetSpiral: function () {
|
||||||
|
|
|
@ -227,7 +227,7 @@ const Import = {
|
||||||
parsedTopics.forEach(function (topic) {
|
parsedTopics.forEach(function (topic) {
|
||||||
let coords = { x: topic.x, y: topic.y }
|
let coords = { x: topic.x, y: topic.y }
|
||||||
if (!coords.x || !coords.y) {
|
if (!coords.x || !coords.y) {
|
||||||
coords = AutoLayout.getNextCoord()
|
coords = AutoLayout.getNextCoord({ map: Active.Map })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!topic.name && topic.link ||
|
if (!topic.name && topic.link ||
|
||||||
|
@ -349,7 +349,7 @@ const Import = {
|
||||||
handleURL: function (url, opts = {}) {
|
handleURL: function (url, opts = {}) {
|
||||||
let coords = opts.coords
|
let coords = opts.coords
|
||||||
if (!coords || coords.x === undefined || coords.y === undefined) {
|
if (!coords || coords.x === undefined || coords.y === undefined) {
|
||||||
coords = AutoLayout.getNextCoord()
|
coords = AutoLayout.getNextCoord({ map: Active.Map })
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = opts.name || 'Link'
|
const name = opts.name || 'Link'
|
||||||
|
|
Loading…
Reference in a new issue