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:
-
Create your own repository using this one as a template and clone it
-
Open cloned repository and modify
./config/default.json
:
MOD_NAME
- self explanatoryMOD_AUTHOR
- self explanatoryMOD_URL
- this is supposed to be a link to your mod repository on GitHub
- Create
local-dev.json
file inside./config
folder, copy below code inside it:
{
"OPENRCT2_PATH": "PATH_TO_OPENRCT2"
}
- replace
PATH_TO_OPENRCT2
with correct path to OpenRCT2 folder on your PC (usuallyC:\Users\<USER>\Documents\OpenRCT2
orC:\Program Files\OpenRCT2
) - make sure to use either escaped backslashes (
\\
) or forward slashes (/
) in the path you're pasting
- Run
nvm use && npm install && npm run init
If you want to alter plugin data, refer to OpenRCT2 scripting guide.
Part of the npm run init
is downloading the latest OpenRCT2 TypeScript API declaration file and saving it to lib
folder (CI pipeline does the same to ensure build and tests passing). If you'll want to use previous API declaration files (e.g. you want to write a mod for some previous version of OpenRCT2), you will need to replace openrct2.d.ts
file in lib
with your own (e.g. coming from your current game folder, usually C:\Users\<user>\Documents\OpenRCT2\bin
or C:\Program Files\OpenRCT2\bin
).
- Make sure you've enabled OpenRCT2 hot reload feature
- Run the project:
npm run start:dev
if you want to generate a dev buildnpm run start
if you want to generate a prod build- both command bundle mod files to
dist
and to{PATH_TO_OPENRCT2}/plugin
- dev builds are suffixed with
_dev
The template assumes your mod files will live in src
folder.
After running npm run start
or npm run start:dev
, Rollup will start watching files in src
and trigger a build anytime you save the file. The entry point is src/index.ts
.
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
.
From there, you can release it however you want.
-
If you've added a new mod folder to
{PATH_TO_OPENRCT2}/plugin
, and the OpenRCT2 didn't register it (e.g. 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 how it can be done -
Template uses config npm package to utilize different environments - new ones can be added simply by adding a new
<env_name>.json
file toconfig
folder and adding a correspondingrollup.config.<env>.ts
, refer to config documentation for more details