Skip to content

🎢 Template repository for OpenRCT2 mods written in TypeScript.

License

Notifications You must be signed in to change notification settings

mgovea/openrct2-typescript-mod-template

 
 

Repository files navigation

🎢 openrct2-typescript-mod-template

GitHub GitHub code size in bytes Dependabot

Template repository for OpenRCT2 mods written in TypeScript.

Table of contents

About

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).

Installation

  1. Install latest versions of Node and npm
  2. Create your own repository using this one as a template and clone it anywhere to your PC
  3. cd into it and run npm install
  4. Find openrct2.d.ts TypeScript API declaration file in OpenRCT2 files and copy it to lib folder (this file can usually be found in C:\Users\<user>\Documents\OpenRCT2\bin)
  5. 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 \)
  6. After editing ./config.json run npm run init - it will replace all the data and then commit the results
  7. 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.

Usage

  1. cd into repo
  2. run npm run build:develop (this will place compiled and minified mod inside PATH_TO_OPENRCT2/plugin/ directory)
  3. Make sure you've enabled OpenRCT2 hot reload feature
  4. Open ./src/main.ts in your code editor
  5. Run npm start
  6. Start OpenRCT2 with console and load save/start new game
  7. Each time you save any of the files in ./src/, the server will compile ./src/registerPlugin.ts and place compiled file inside PATH_TO_OPENRCT2/plugin/ directory as MOD_NAME.js
  8. OpenRCT2 will notice file changes and it will reload the mods

How it works

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.

npm scripts

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

Releasing your mod

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.

Notes

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 :)

Useful links

About

🎢 Template repository for OpenRCT2 mods written in TypeScript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 50.9%
  • JavaScript 49.1%