Skip to content

Commit db96f7d

Browse files
authored
feat: Add page for third-party train schedule libraries (#16)
1 parent 621bfce commit db96f7d

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

.vitepress/sidebars/users.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export default {
4848
text: "Train schedule",
4949
link: "/users/cc-tweaked-integration/train/train-schedule",
5050
},
51+
{
52+
text: "Libraries",
53+
link: "/users/cc-tweaked-integration/train/libraries",
54+
},
5155
],
5256
},
5357
{
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Community-written libraries exist for interacting with schedules. These are not
2+
made by or affiliated with the Create team. The ones below stem from the
3+
[Minecraft Computer Mods Discord Server](https://discord.computercraft.cc/), and
4+
can be used to contact the developers!
5+
6+
## trainlib
7+
8+
A pseudo-OOP library for building train schedules.
9+
10+
In this example, we will assign a schedule to drive to Station 1, then wait for
11+
a player (or more) to mount, after which it will drive to Station 2 and wait for
12+
them to dismount.
13+
14+
```lua
15+
local tl = require("trainlib")
16+
17+
local schedule = tl.schedule(true) -- cyclic / looping!
18+
local conditions = tl.condition_set_or():addCondition(tl.conditions.player_count(1, false))
19+
local conditions_destination = tl.condition_set_or():addCondition(tl.conditions.player_count(0, true))
20+
21+
schedule
22+
:addEntry(tl.entry(tl.instructions.destination("Station 1"), conditions))
23+
:addEntry(tl.entry(tl.instructions.destination("Station 2"), conditions_destination))
24+
25+
station.setSchedule(schedule)
26+
```
27+
28+
[Download](https://github.com/scmcgowen/trainlib) (MIT license) •
29+
[View in Discord](https://canary.discord.com/channels/477910221872824320/1292217740416778240/1292217740416778240)
30+
31+
## Scheduler
32+
33+
A minimalistic "it just works" library for magically building train schedules.
34+
Also supports Steam 'n' Rails, Crafts & Additions, and Railways Navigator, and
35+
is easily extensible. Full LuaLS documentation is included in the library.
36+
37+
In this example, we will assign a schedule to drive to Station 1, then wait for
38+
5 seconds, and then wait for the station to be powered, or until the time hits
39+
14:00 (every day), then drive to Station 2 and wait for a second.
40+
41+
```lua
42+
local Scheduler = require("scheduler")
43+
44+
local schedule = Scheduler.new(true) -- cyclic / looping!
45+
:to("Station 1")
46+
:wait(5):powered()
47+
:OR():time(14, 0, "daily")
48+
:to("Station 2")
49+
:wait(1)
50+
51+
station.setSchedule(schedule)
52+
```
53+
54+
[Download](https://github.com/tizu69/cclibs/tree/main/scheduler) (MIT license) •
55+
[View in Discord](https://canary.discord.com/channels/477910221872824320/1299066980581773353/1299066980581773353)
56+
57+
## Create Scheduler / DSL for Create Train Schedules
58+
59+
A domain-specific language for writing schedules.
60+
61+
In this example, we will assign a schedule to drive to Station 1, then wait 5
62+
minutes, and then wait for the station to be powered, or until the time hits
63+
14:00, then drive to Station 2 and wait for a minute, use this DSL code:
64+
65+
```scheduler
66+
cyclic
67+
to "Station 1" {
68+
wait 5m, powered
69+
time = 14:00 daily
70+
}
71+
to "Station 2" { wait 1m }
72+
```
73+
74+
Then, turn it into a schedule like so:
75+
76+
```lua
77+
local mksched = require "create-scheduler"
78+
local schedule = mksched("cyclic to ...")
79+
station.setSchedule(schedule)
80+
```
81+
82+
[Download](https://gist.github.com/MCJack123/94071c7724045dc048777395afc04eb1) (CC0 license) •
83+
[View in Discord](https://discord.com/channels/477910221872824320/1299074371540746310/1299074371540746310)

src/users/cc-tweaked-integration/train/train-schedule.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ schedule = {
4343
}
4444
```
4545

46+
If this seems a bit confusing, you may also check out some community-made
47+
[libraries](./libraries) for creating schedules.
48+
4649
---
4750

4851
## Instructions

0 commit comments

Comments
 (0)