1 """ A navigable graph of actors. """
5 """ A navigable graph of actors. """
10 self._current_id = None
14 return self._actors.get(self._current_id)
16 def connect_pair(self, a1, a2, edge):
17 self._actors[id(a1)] = a1
18 self._actors[id(a2)] = a2
19 if self._current_id is None:
20 self._current_id = id(a1)
21 a1edges = self._graph.setdefault(id(a1), {})
22 a1edges[edge] = id(a2)
24 def connect(self, actors, edges, reverse=None, wrap=True):
25 if not edges or not actors:
27 first, previous, current = None, None, None
29 previous, current = current, actor
34 self.connect_pair(previous, current, edge)
35 if wrap and first is not current:
37 self.connect_pair(current, first, edge)
38 if reverse is not None:
39 self.connect(list(reversed(actors)), reverse)
41 def follow(self, edge):
42 future = self._graph.get(self._current_id, {}).get(edge)
44 old, self._current_id = self._current_id, future
45 return self._actors[old], self._actors[future]