Giter Club home page Giter Club logo

openrct2-typescript-mod-template's Introduction

DISCONTINUED, TREAT IT LIKE A MODDERS RESOURCE

๐ŸŽข openrct2-typescript-mod-template

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:

Installation

  1. Install Node v.18.12.1 (it comes with npm by default)

  2. Create your own repository using this one as a template and clone it

  3. Open cloned repository and modify ./config/default.json:

  • MOD_NAME - self explanatory
  • MOD_AUTHOR - self explanatory
  • MOD_URL - this is supposed to be a link to your mod repository on GitHub
  1. 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 (usually C:\Users\<USER>\Documents\OpenRCT2 or C:\Program Files\OpenRCT2)
  • make sure to use either escaped backslashes (\\) or forward slashes (/) in the path you're pasting
  1. 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).

Usage

Hot reload

  1. Make sure you've enabled OpenRCT2 hot reload feature
  2. Run the project:
  • npm run start:dev if you want to generate a dev build
  • npm 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

How it works

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.

Releasing your mod

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.

Notes

  • 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 to jest.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 to config folder and adding a corresponding rollup.config.<env>.ts, refer to config documentation for more details

Useful links

openrct2-typescript-mod-template's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar mgovea avatar wisnia74 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

openrct2-typescript-mod-template's Issues

Readme assumes NVM is installed even though it does not ship with Node.js

Hey,

In step 6 of the installation chapter of the readme (here) the user is asked to run nvm use, but this command-line program is not mentioned anywhere else in the readme and does not ship with Node.js mentioned in step 1, so for most users this would return a "command not found" error.

Thank you for your time. ๐Ÿ™‚

Externally imported NPM dependencies do not get shipped in plugin

Hey,

Externally installed NPM packages (like for example my FlexUI library) do not get shipped with plugins using this template.

After installing FlexUI using npm install openrct2-flexui@next and using this script:

import { window } from 'openrct2-flexui';

function main(): void
{
  const w = window({
    width: 100, height: 100, content: []
  });

  w.open();
}

export default main;

The output from npm run build:dev for the main function is as follows (trimmed and beautified for readability):

var openrct2Flexui=require('openrct2-flexui');
function main(){
  var w=openrct2Flexui.window({
    width:100,
    height:100,content:[]
  });
  w.open()
}

And the following errors have occured during the build:

(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
openrct2-flexui (imported by src/main.ts)

At last, when using the plugin ingame, the plugin crashes because the require() function could not be found.

I would guess the expected behaviour would be to have the used functions from FlexUI be inlined into the output file.

Thank you for your time. ๐Ÿ™‚

If npm run init fails, it cannot be run a second time

Hey,

If you run npm run init and it fails due to an error, it cannot be run again because the init gulp script is deleted from the gulp directory.

In my case I skipped step 3 because I just wanted it to download openrct2.d.ts automatically (because the Readme said that is what it does). But when you do this, it errors because the MOD_URL is not a valid url yet. After that, it's not possible to run npm run init a second time because the gulp init script has already been deleted from disk.

Thank you for your time! ๐Ÿ™‚

Property 'targetApiVersion' is missing in type but required in type 'PluginMetadata'

Hey,

Running any of the NPM start or build commands causes the following Typescript warning:

(!) Plugin typescript: @rollup/plugin-typescript TS2345: Argument of type '{ name: string; version: string; authors: string[]; type: "local"; licence: string; main: () => void; }' is not assignable to parameter of type 'PluginMetadata'.
  Property 'targetApiVersion' is missing in type '{ name: string; version: string; authors: string[]; type: "local"; licence: string; main: () => void; }' but required in type 'PluginMetadata'.

This missing field was added here last December and is now required by the interface for new plugins.

Thank you for your time. ๐Ÿ™‚

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.