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 Nodemon, ESLint and TypeScript on board.
The idea was to use Nodemon to start a local server that will be watching your mod files, then on each save make it build .ts
files to ES5 .js
files, place them inside OpenRCT2 plugin
directory, and let hot reload feature do the rest (i.e. reload the mod in-game).
- 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 runnpm install
- 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\openrct2.d.ts
)- alternatively, you can make a symbolic link instead of copying the file, which will keep the file up to date whenever you install new versions of OpenRCT2. To do this on Windows:
- run command prompt as administrator
cd
into your repo (wherever you cloned it)- run
mklink ./lib/openrct2.d.ts <path to openrct2.d.ts>
- alternatively, you can make a symbolic link instead of copying the file, which will keep the file up to date whenever you install new versions of OpenRCT2. To do this on Windows:
- Edit
./config.json
:modName
- will be used in./src/registerPlugin.ts
,./rollup.config.dev.js
and./rollup.config.prod.js
modURL
- will be used in./src/registerPlugin.ts
andpackage.json
- use the URL created as a result of step 2 (link to your mod repo) - it should look like
https://github.com/<author>/<repository>
- use the URL created as a result of step 2 (link to your mod repo) - it should look like
gamePath
- will be used in./rollup.config.dev.js
- make sure this path uses
/
instead of\
- this path is the one that holds the
plugin
folder, not the installation path - typically
C:\Users\<USER>\Documents\OpenRCT2
- make sure this path uses
- Run
npm run init
- it will replace all the data and then commit the results - You can start modding :)
Of course it's a template, so you can edit anything you like.
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 start
(this will place compiled and minified mod insidePATH_TO_OPENRCT2/plugin/
directory) - Open
./src/main.ts
in your code editor - Start OpenRCT2 with console and load save/start new game
- Each time you save any of the files in
./src/
, the server will compile./src/registerPlugin.ts
and place compiled file insidePATH_TO_OPENRCT2/plugin/
directory asMOD_NAME.js
- OpenRCT2 will notice file changes and it will reload the mods
Your mod files live in ./src/
directory. That's the ones you will be writing code in.
Upon starting Nodemon server, it will start watching changes you make to files in ./src/
, and it will build them accordingly.
The entry point is ./src/registerPlugin.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.
script | function |
---|---|
npm start |
starts Nodemon server that will be watching ./src/ directory for any changes you make to any files inside it |
npm run lint |
lints your .ts and .js files from ./src/ directory |
npm run build:dev |
compiles registerPlugin.ts and minifies it, then places it inside PATH_TO_OPENRCT2/plugin/ as MOD_NAME.js |
npm run build |
runs npm run lint and if no linting errors are found, compiles registerPlugin.ts and minifies it, then places it inside ./dist/ folder as MOD_NAME.js - this is your final mod file |
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.
Don't touch app.js
. Its existence makes Nodemon happy.
Nodemon is what watches your files for changes & fires off new dev builds for hot reloading. Furthermore, it's used for resolving root directory of the project - that's used, for example, in init script.
Nodemon will watch all the files in ./src/
directory. You can also freely create classes, modules, import them in your mod files.
Sky's the limit :)