Template repository for OpenRCT2 mods written in TypeScript.
This repository was created to serve as a template TypeScript mod repository for OpenRCT2.
I wanted to leverage OpenRCT2 hot reload feature to make it even more painless to write and debug mods in real time.
This template repository comes with TypeScript, Rollup, ESLint and Jest on board.
- Install latest versions of Node and npm
- Create your own repository using this one as a template and clone it anywhere to your PC
cd
into it and edit fields in./config/default.json
MOD_NAME
- self explanatoryMOD_AUTHOR
- self explanatoryMOD_URL
is supposed to be a link to your repository on GitHub (the one you've created in a previous step)
- Find
openrct2.d.ts
TypeScript API declaration file in OpenRCT2 files and copy it tolib
folder (this file can usually be found inC:\Users\<USER>\Documents\OpenRCT2\bin
orC:\Program Files\OpenRCT2
)- alternatively, you can make a symbolic link through command prompt/terminal on your OS (example:
mklink
on Windows)
- alternatively, you can make a symbolic link through command prompt/terminal on your OS (example:
- Create
local-dev.json
file inside./config
folder, it should look like the following:
{
"OPENRCT2_PATH": "PATH_TO_OPENRCT2"
}
- replace
PATH_TO_OPENRCT2
with correct path to OpenRCT2 folder on your machine (same path as in step 4) - make sure to replace any forward slashes (
/
) or backslashes (\
) in your path, with escaped backslashes (\\
)
- Run
npm run init
and wait for it to finish
If you want to alter plugin data, refer to OpenRCT2 scripting guide.
- Make sure you've enabled OpenRCT2 hot reload feature by setting
enable_hot_reloading = true
in your/OpenRCT2/config.ini
cd
into repo- run
npm run start:dev
(this will place compiled and minified mod file insidePATH_TO_OPENRCT2/plugin/
directory and insidedist
directory inside the repo)
Prod builds can be done through npm start
and npm run build
respectively.
Your mod files live in ./src/
directory. That's the ones you will be writing code in most of the time.
Upon starting Rollup, it will start watching changes you make to files in ./src/
, and it will build them accordingly.
The entry point is ./src/index.ts
. Any file, class, module you create in ./src/
needs to be imported to registerPlugin.ts
one way or another.
Template uses Terser to minify your output mod bundle file and to resolve any dependencies.
After running npm run build
locally, ./dist/
directory will be created that will contain MOD_NAME.js
.
It's up to you, if you want to edit .gitignore
to actually include ./dist/
contents and push them to your remote or if you want to manually copy the contents of ./dist/
and publish them somewhere. However creating a GitHub release using contents of ./dist/
directory sounds like a cool idea. You would have your mod file available for download straight from the repo.
Don't forget to update README.md
to reflect your mod and update version numbers for future releases.
-
If you've added a new mod folder to
plugin
, and the OpenRCT2 didn't seem like it registered it (and you had a running park), just load the save/start a new park, so OpenRCT2 loads the mods again. Now when you overwrite them during development, there shouldn't be any problems with hot reload noticing file changes. -
Template comes with full Jest support however if you'll want to add tests that will be meaningful, you will need to mock a lot of things coming from the
openrct2.d.ts
- refer tojest.setup.ts
I've created to see what I mean -
Template uses config npm package to utilize different environments - new ones can be added simply adding a new
<env_name>.json
file to./config
folder and adding a correspondingrollup.config.<env>.ts
, refer to config docs for more info on how env vars are getting loaded