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
) - Edit
./config.json
:modName
- will be used in./src/registerPlugin.ts
,./rollup.config.dev.js
and./rollup.config.prod.js
modAuthor
- will be used in./src/registerPlugin.ts
pathToOpenRCT2
- will be used in./rollup.config.dev.js
(make sure this path uses/
instead of\
)
- After editing
./config.json
runnpm 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.
cd
into repo- run
npm run build:develop
(this will place compiled and minified mod insidePATH_TO_OPENRCT2/plugin/
directory) - Make sure you've enabled OpenRCT2 hot reload feature
- Open
./src/main.ts
in your code editor - Run
npm start
- 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.
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.
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 :)