make AutoLayout skip over coordinates if there is a mapping at that exact position

This commit is contained in:
Devin Howard 2016-10-01 13:34:52 +08:00
parent 20a32afe3b
commit bb013787b6
2 changed files with 21 additions and 6 deletions

View file

@ -1,3 +1,5 @@
import Active from './Active'
const AutoLayout = {
nextX: 0,
nextY: 0,
@ -7,7 +9,7 @@ const AutoLayout = {
nextYshift: 0,
timeToTurn: 0,
getNextCoord: function () {
getNextCoord: function (opts = {}) {
var self = AutoLayout
var nextX = self.nextX
var nextY = self.nextY
@ -49,9 +51,22 @@ const AutoLayout = {
}
}
return {
x: nextX,
y: nextY
if (opts.map && self.coordsTaken(nextX, nextY, opts.map)) {
// check if the coordinate is already taken on the current map
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 () {

View file

@ -227,7 +227,7 @@ const Import = {
parsedTopics.forEach(function (topic) {
let coords = { x: topic.x, y: topic.y }
if (!coords.x || !coords.y) {
coords = AutoLayout.getNextCoord()
coords = AutoLayout.getNextCoord({ map: Active.Map })
}
if (!topic.name && topic.link ||
@ -349,7 +349,7 @@ const Import = {
handleURL: function (url, opts = {}) {
let coords = opts.coords
if (!coords || coords.x === undefined || coords.y === undefined) {
coords = AutoLayout.getNextCoord()
coords = AutoLayout.getNextCoord({ map: Active.Map })
}
const name = opts.name || 'Link'