Giter VIP home page Giter VIP logo

tts-typescript's Introduction

Typescript Declarations for Tabletop Simulator

Hello! These types are intended to be used with Typescript to Lua. 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
  1. Create tsconfig.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.

  1. Create src/index.ts
// 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 )
}
  1. 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
--[[ 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):

"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

tts-typescript's People

Contributors

aucacoyan avatar klutzybubbles avatar stevenlafl avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

tts-typescript's Issues

Missing Vector methods

I noticed the Vector methods listed here in the docs are missing from these types and it would be nice to have them.

PS thanks so much for making this repo, I'm working on a large TTS mod that gets transpiled from typescript and this is an absolute godsend ❤️

`tsconfig.json` schema errors on `module` key

Hello!
I setup a project and find out that the schema of tsconfig has changed 😮 .

From an empty project, I follow the tutorial and vs code warns:
Option 'module' must be set to 'NodeNext' when option 'moduleResolution' is set to 'NodeNext'.

So, now if we want to use

    "moduleResolution": "nodenext",

We need to add a second line:

    "moduleResolution": "nodenext",
    "module": "NodeNext",

Issues with local functions

Tried from the readme and it produces

--[[ 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 ]]
local ____exports = {}
local function onLoad(saveData)
    print("test")
end
return ____exports
 end,
}
return require("src.index", ...)

When run in game it does nothing unless the local in front of the onLoad function is removed.

Curious to whether you ran into this issue or if there are any solutions, currently i have just modified TypeScriptToLua to output all functions without local however i dont think this would be a viable option long term.

I need a guide on how to use the types 🦺

Hi! I'm very interested in using this library to build my lua scripts. Unfortunately I couldn't make it work :(
I feel strange with the

/// <reference path="./backgrounds.d.ts" />

all over the types.

Can you lend me a hand and help to setup a simple sample?
I would like to contribute if I'm able!

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.