buildgraph: add support vor levelconnectors
This commit is contained in:
parent
3779398d16
commit
516d7921ce
2 changed files with 33 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
|||
from itertools import permutations
|
||||
|
||||
from c3nav.mapdata.models import Level
|
||||
from c3nav.routing.graph.connection import GraphConnection
|
||||
from c3nav.routing.graph.level import GraphLevel
|
||||
|
@ -7,6 +9,7 @@ class Graph():
|
|||
def __init__(self):
|
||||
self.levels = {}
|
||||
self.connections = []
|
||||
self.levelconnector_points = {}
|
||||
|
||||
def build(self):
|
||||
for level in Level.objects.all():
|
||||
|
@ -14,7 +17,19 @@ class Graph():
|
|||
|
||||
for level in self.levels.values():
|
||||
level.build()
|
||||
|
||||
self.connect_levelconnectors()
|
||||
|
||||
for level in self.levels.values():
|
||||
level.draw_png()
|
||||
|
||||
def add_levelconnector_point(self, levelconnector, point):
|
||||
self.levelconnector_points.setdefault(levelconnector.name, []).append(point)
|
||||
|
||||
def connect_levelconnectors(self):
|
||||
for levelconnector_name, points in self.levelconnector_points.items():
|
||||
for from_point, to_point in permutations(points, 2):
|
||||
self.add_connection(from_point, to_point)
|
||||
|
||||
def add_connection(self, from_point, to_point):
|
||||
self.connections.append(GraphConnection(self, from_point, to_point))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue