Skip to content

danielfvm/mental-ts

Repository files navigation

mental-ts

Write addons for the mental engine with TypeScript.

Why?

Types allow you to write safer code that won't have runtime errors duo to missspelling or using the wrong method name. image

It also allows for better integration in your IDE with proper intellisense. Documentation and example codes can directly be added to the type declarations. image image

Classes are supported by TypeScript out of the box and do not require some magic non-standardized lua code / preprocessor to implement them. image

How?

This project uses TypeScriptToLua to generate lua code from TypeScript. The generated lua files together with any other valid asset file (images, audio, etc) will be bundled together to an addon. See build.js for more details.

Setup

Download the project and run the setup script which will download the Engine / Sonic Game from the offical website, extract and renames it automatically. Then install the dependencies and you should be able to write your own addons. See the instructions below for more a detailed setup for your OS.

Linux

git clone https://github.com/danielfvm/mental-ts
cd mental-ts
./setup.sh
npm install

Windows

Not yet tested - setup.ps1 and build.js might now work. If that is the case please download the game manually, extract it and rename the folder to mental (place it in the project's root folder). You also might need to rename the paths inside the package.json>scripts to include the .exe.

git clone https://github.com/danielfvm/mental-ts
cd mental-ts
.\setup.ps1
npm install

Config

Inside the mntconfig.json you can configure your plugin.

{
  "output": "./mental/addons/my_addon",  // Generated addon destination path + name 
  "assets": [ "src/", "sounds/", "textures/", "scenes/" ], // Folders that build.js will look for assets
  "autorun": [ "./src/index.lua" ] // Scripts that should be run at startup
}

Write an addon

See index.ts for an example typescript addon that loads on startup. You can add your textures, audio, font, etc to the src/ folder or alternatively you can create separate folders for a more organized project structure. If you do so make sure to specify the new asset folder in the mntconfig.json!

Run

To start the game with your addon run:

npm run release

If you additionaly want to have the imgui debug window run:

npm run debug

Todo

  • Support entities / figure out how to move Entity class out of src/index.ts to /mental-types/
  • Add missing type declarations, see this
  • Add better comments with examples to type declarations
  • Move declaration to own package
  • Support for windows / test if setup.ps1 and build.js work.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published