Skip to content

elMuso/defold-annotations-typescript

Repository files navigation

Defold Annotations for Typescript

Hugely based around the idea of Defold annotations, this repository aims to be the same, for typescript, but better.

It parses the official documentation from Defold and translates it to 2 typescript definition files.

Node 20.15.1 was used for this. Might not run with other versions

Integrate with ts-defold

By default ts-defold provides their own types already on tsconfig.json. If you want to replace(or test) this repository i suggest you make a defold-ts project as normal, then after it's done, download the latest .zip Release and extract anywhere on your project folder.

You will need to change this line from tsconfig.json

"types": ["@typescript-to-lua/language-extensions", "@ts-defold/types"],

to

"types": ["@typescript-to-lua/language-extensions", "lua-types/5.1"],

Then extract index.d.ts on your @types folder (or anywhere, but this folder is already created by ts-defold) and dmsg.ts and dprop.ts on your src/modules folder (or anywhere inside the src folder, but again this folder is already created by ts-defold)

Now you should be good to go.

Use case

These annotations can be used by anyone just by dragging the file to your project

  • index.d.ts contains the Defold API, constants and functions
  • dmsg.ts contains a useful dmsg object that can serve as a helper to know what type of data a documented message expects. Ex: dmsg.sound.play_sound("#gameobject", {play_id:1, delay: 2, gain:0.5})
  • dprop.ts contains documented properties of each module, this properties are sent using msg.post(id, property, value). Ex: msg.post(".", dprop.go.position, vmath.vector3(10, 5, 0))

Manual Generation

Install Node, run npm install and then npm run start. The output will be on the api folder

Issues

If you find a typo in the annotations or outdated meta information, create an issue.

Settings

By default it uses Defold version 1.9.1 , you can change this by editing the src_new/settings.ts file. There are other useful conditionals there to remove information from the final build

Todo

  • Use namespace specific constants to have specific parameter return values. Maybe enums?
  • Expand table declarations from the official documentation
  • Remove implementations of table_array and table_map to more specific objects
  • Expand more table declarations from the official documentation
  • Make specific definitions compatible with https://github.com/ts-defold/library types
  • Improve documentation generation
  • Implement on a project