https://github.com/samthor/traingraph
Train graph ππππ
https://github.com/samthor/traingraph
choo choochoo
Last synced: about 1 month ago
JSON representation
Train graph ππππ
- Host: GitHub
- URL: https://github.com/samthor/traingraph
- Owner: samthor
- License: apache-2.0
- Created: 2021-06-12T08:31:53.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-08-06T06:10:51.000Z (about 4 years ago)
- Last Synced: 2025-03-12T05:29:46.888Z (7 months ago)
- Topics: choo, choochoo
- Language: JavaScript
- Homepage:
- Size: 231 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Work in progress train graph + game demo on top.
# Play
Fetch, run `npm install`, and run with `dhost` or something that will rewrite your ESM imports:
```js
dhost -m
```Focus and tap "a" to add a line.
Use your mouse and click to finish the line (potentially joining to other lines).Tap "s" to add a train (it's basically a snake).
Trains just bounce around forever.Tap "p" to start pathfinding when focused on a line.
This is just a demo and nothing uses this yet.## Configure
Some constants are in "src/shared.js", around units and so on.
# Design
The `Game` class uses `GraphType` for its graph code, as well as `SnakeMan` to manage trains.
Trains are basically snakes, and move by growing on one side and shrinking on another.## Graph
This is based on a generic `GraphType` interface (and `Graph` implementation in "src/graph.js") which contains edges and nodes.
* Each edge has at least two nodes (end nodes) and can be split by adding further nodes.
* These edges don't exist in physical space, and can be joined in non-euclidian ways, although do have physical length (as an integer).
* Nodes can be merged with other nodes (although they don't _have_ to "pair"βthink a line crossing over another).
* They can be paired via `Graph.join`, which creates a path between them (in the game, this is where a red line appear to show connectivity).
* Nodes will be on at least one edge, but perhaps multiple.* There are some restrictions on graph operations for sanity.
* Nodes cannot exist at multiple places on the same edge.
* Edges can only be joined together at one place.
* Because of this, it's possible to unambiguously match a segment via a request for two distinct nodes on the same edge.# Goals
The SVG renderer is really just a demo over the graph code.
I have a personal goal to write a train gameβwhile this might be used for casual games, I'm inspiring more from Factorio or similar in terms of the feature set.