https://github.com/stevenlafl/tts-typescript
Typescript Declarations for Tabletop Simulator
https://github.com/stevenlafl/tts-typescript
lua node-js tabletop-simulator typescript typescript-definitions typescript-to-lua
Last synced: about 1 year ago
JSON representation
Typescript Declarations for Tabletop Simulator
- Host: GitHub
- URL: https://github.com/stevenlafl/tts-typescript
- Owner: stevenlafl
- License: mit
- Created: 2023-04-16T02:00:33.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-02-16T16:04:24.000Z (over 2 years ago)
- Last Synced: 2025-03-31T06:19:09.019Z (about 1 year ago)
- Topics: lua, node-js, tabletop-simulator, typescript, typescript-definitions, typescript-to-lua
- Language: TypeScript
- Homepage:
- Size: 101 KB
- Stars: 9
- Watchers: 1
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Typescript Declarations for Tabletop Simulator
Hello! These types are intended to be used with [Typescript to Lua](https://typescripttolua.github.io). With that compiler you can transpile `.ts` files into `.lua` files. This package is the safety net for the Tabletop Simulator functions and objects. Let your editor have some nice autocompletion!.
### Usage
1. Install these packages and make a `src` directory:
```
npm i tts-types typescript typescript-to-lua
mkdir src
```
2. Create tsconfig.json:
```json
{
"compilerOptions": {
"rootDir": ".",
"outDir": "build",
"target": "ESNext",
"lib": ["ESNext"],
"moduleResolution": "nodenext",
"module": "NodeNext",
"declaration": false,
"declarationMap": false,
"strict": true,
"types": ["tts-types"],
},
"tstl": {
"luaTarget": "5.2",
"noImplicitSelf": true,
"tstlVerbose": true,
"luaBundle": "bundle.lua",
"luaBundleEntry": "src/index.ts",
},
}
```
note: we use `"luaTarget": "5.2"` to be compatible with the LUA version Tabletop Simulator uses.
3. Create `src/index.ts`
```typescript
// The OnLoad function. This is called after everything in the game save finishes loading.
// Most of your script code goes here.
function onLoad( saveData: any ) {
// Lock color-UI cube
let cube = getObjectFromGUID( "c1a0d1" )
cube.interactable = false
cube.setLock( true )
}
```
4. Your project is ready! run `npx tstl` to compile it into Lua
```
npx tstl
```
You will have some output like this:
```
Loaded 0 plugins
Parsing project settings
Transforming C:/Source/tts-test/src/index.ts
Printing C:/Source/tts-test/src/index.ts
Constructing emit plan
Resolving dependencies for C:/Source/tts-test/src/index.ts
Emitting output
Emitting C:/Source/tts-test/build/bundle.lua
Emit finished!
```
Your .lua file now exists at build/bundle.lua:
build/bundle.lua autogenerated file
```lua
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
local ____modules = {}
local ____moduleCache = {}
local ____originalRequire = require
local function require(file, ...)
if ____moduleCache[file] then
return ____moduleCache[file].value
end
if ____modules[file] then
local module = ____modules[file]
____moduleCache[file] = { value = (select("#", ...) > 0) and module(...) or module(file) }
return ____moduleCache[file].value
else
if ____originalRequire then
return ____originalRequire(file)
else
error("module '" .. file .. "' not found")
end
end
end
____modules = {
["src.index"] = function(...)
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
function onLoad(saveData)
local cube = getObjectFromGUID("c1a0d1")
cube.interactable = false
cube.setLock(true)
end
end,
}
return require("src.index", ...)
```
I use this to copy it in automatically (package.json):
```json
"scripts": {
"compile": "tstl && npm run deploy",
"deploy": "copy \"build\\bundle.lua\" \"%LOCALAPPDATA%\\Temp\\TabletopSimulator\\Tabletop Simulator Lua\\Global.-1.lua\""
}
```
So I can simply use `npm run compile`
### Contributing (TODO)
- Finish tests
- Create example projects
### Development
1. Clone
2. `npm install`
3. `npm run build` to build the project
4. `npm run test` to run tests