GraphController is the central service object of the Constellations application. It holds the activeDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tutosrive/Constellations/llms.txt
Use this file to discover all available pages before exploring further.
Graph instance, delegates to dijkstra_simple and LongestPathWithDonkey for path computation, and maintains the highlight_edges list consumed by GraphView to draw highlighted connections on screen. All file I/O is performed through FilesUtils, keeping the controller free of direct filesystem concerns.
Constructor
| Attribute | Type | Initial value |
|---|---|---|
self.graph | Graph | Empty Graph() instance |
self.filename | str | None | None |
self.highlight_edges | list | [] |
Methods
load_graph
Reads a JSON file from disk viaFilesUtils.read_json, builds an id → label mapping, then calls add_vertex and add_edge to populate self.graph.
Path to the JSON file containing the constellation graph data (e.g.
"src/data/Constellations.json").bool — True on success; False if the file is missing, unreadable, or the JSON does not contain a "constellations" key.
get_graph
Returns the currently loadedGraph instance.
Returns Graph — the active graph held in self.graph.
get_json_data
Re-reads the original JSON file fromself.filename and returns the parsed dictionary without modifying self.graph.
Returns dict | None — the parsed JSON object, or None if self.filename is not set or the file cannot be read.
reload_graph
Reloads the graph from the most recently loaded file. Falls back to"src/data/Constellations.json" if self.filename is None.
Returns bool — result of the underlying load_graph call.
add_star
Adds a single vertex to the graph before or after a game session begins.The label used as the vertex key inside the graph.
Arbitrary metadata associated with the star (coordinates, type, etc.).
None.
toggle_edge
Flips theblocked flag on the edge running from from_label to to_label. Because edges are stored directionally, only the specified direction is toggled; call the method a second time with arguments reversed to toggle the reverse direction.
Label of the source vertex.
Label of the destination vertex.
None. Prints a warning if the edge does not exist.
get_shortest_path
Runs Dijkstra’s algorithm between two star labels and stores the resulting edge list inself.highlight_edges.
Label of the starting vertex.
Label of the destination vertex.
tuple[dict, dict, list]:
dist— mapping from vertex label to shortest distance fromstartpred— mapping from vertex label to its predecessor on the shortest pathpath— ordered list of vertex labels fromstarttoend
get_shortest_path_avoiding
Builds a filtered subgraph that excludes all vertices inforbidden (except start and end), then runs dijkstra_simple on that subgraph. Stores the result in self.highlight_edges.
Label of the starting vertex. Always included even if present in
forbidden.Label of the destination vertex. Always included even if present in
forbidden.Set of vertex labels to exclude from the subgraph. Defaults to an empty set (equivalent to a normal shortest-path query).
tuple[dict, dict, list] — same structure as get_shortest_path.
get_longest_path_with_donkey
InstantiatesLongestPathWithDonkey with the current graph and the supplied Donkey, then calls find_longest_path. Stores the result edge list in self.highlight_edges.
Label of the vertex from which the DFS begins.
A
Donkey instance carrying the initial resource values (energy, health, grass).tuple[list, float]:
best_path— ordered list of vertex labels representing the longest viable routemax_distance— total distance of that route
highlight_edges is populated after every path computation (get_shortest_path, get_shortest_path_avoiding, and get_longest_path_with_donkey). It holds a list of (from_label, to_label) tuples and is read by GraphView to draw yellow highlighted edges over the constellation map. It is reset to [] when no path could be found.