For modders
Share data between mods
A small shared standard for Railroader mods. Your mod publishes a feed. Any other mod can find it and read it, with no dependency on yours. One file you drop into your project. Nothing for players to install.
Use it
- Copy
ModFeeds.csinto your project. Change only its namespace line,namespace MODFEEDS_NAMESPACE, to yours. Keep the rest exactly as it is. It needs nothing but .NET. - Read feeds, publish your own, or both. Call everything on the game's main thread.
The README has short C# examples for both sides.
Read a feed
ModFeeds.List() gives every feed loaded right now, each with its title, the mod and version that made it, its schema version, and a line describing each field.
ModFeeds.Read(id) gives that feed's answer. It never throws: a feed that isn't loaded, or one that fails, answers with an error instead.
Treat an answer as read only and ignore keys you don't know. Now and then one is large or deeply nested, so if you walk it, cap how deep and how many items you go.
Publish a feed
A feed is an id, a function that returns your data, a title people see, your mod's name and version, a schema version, and one line per top-level field saying what it means, with units.
Publish when your mod is switched on and withdraw when it's switched off. The first mod to publish an id keeps it. Publish returns false if the id is taken or isn't valid, so check it.
Ids are lowercase letters and digits, in words joined by single dashes, up to 64 characters: cars-waiting, my-feed-2.
The rules for a feed
- Plain data only: dictionaries, lists, strings, numbers, bools and null. Never your own types or the game's.
- Start with
apiandfeed: your schema version and the feed's id. - Add, don't change: a new key is fine. A key that changes meaning means a new
api. - Never throw. On a failure, answer with an error.
- Change nothing. Reading a feed has no side effects.
- Cheap: a reader may call it every couple of seconds.
- Private by default: no file paths, account names or machine names.
- Describe every top-level field, so anyone who finds your feed knows what it means.
Multiplayer
Each player's game answers for itself. If your data only exists on the host, add "host": true or false to your answer, so a reader on a client knows why it's empty.