Git Product home page Git Product logo

cavalry-types's Introduction

cavalry-types

Typescript definitions for Cavalry

Note
Current supported API version is Cavalry 1.5.6

These definitions describe the whole Cavalry scripting API. Essentially it gives you all the documentation inside your editor. After installation and following the usage guidelines you can simply start writing your script and get suggestions about available methods and parameters.

If you're not sure how to start, follow the usage guidelines and press ctrl-space, then type cav and you'll see the cavalry namespace suggested along with its description. Press enter and type . to see a list of all the available methods.

A few pointers:

  • Hovering over a namespace, method or parameter will show its documentation along with examples (in most cases).
  • Red squiggly lines will appear when methods or parameters don't exist or when they're of the wrong type. Hover over them to find out about the problem.
  • Even though there might be errors and warnings in the code, it will still run (with or without errors). This is because the error checking happens only in your editor.
  • If you're writing in Typescript, the code will not run in Cavalry. You will have to compile the code first.

Note
This project is still in progress. There are some descriptions and Typescript features missing, but the API is mostly documented. The definition files were written by hand, so there might be some mistakes. Please report any issues you find.

Stallion

It's recommended that you use the Stallion VSCode extension if you're new to the Node ecosystem. It can insert the Typescript definitions without the need to install them.

Installation

Make sure you first initialise a new npm project. In your terminal run:

npm init --yes

then install the Typescript definitions:

npm install @scenery/cavalry-types --save-dev

Usage

You can either use Triple-Slash Directives for one-off scripts. Or for more involved projects, you can use a Typescript Config.

Triple-Slash Directives

Add the following triple-slash directive at the top of your script file.

/// <reference types="@scenery/cavalry-types"/>

Optionally include a @ts-check comment to enable type checking.

/// <reference types="@scenery/cavalry-types"/>
// @ts-check

Typescript Config

Create a tsconfig.json in your project folder and add @scenery/cavalry-types.

{
	"compilerOptions": {
		"types": ["@scenery/cavalry-types"]
	}
}

Versioning

The types will always point to the latest API version. Add a version number to the path to target a specific version.

Javascript

/// <reference types="@scenery/cavalry-types/versions/1.5.1" />

Typescript

{
	"compilerOptions": {
		"types": ["@scenery/cavalry-types/versions/1.5.1"]
	}
}

Specific Namespaces

Cavalry has namespaces for specific parts of the app, such as render for render scripts and ctx in the Javascript Utility. Add an additional Triple-Slash Directive to expose the types for it.

/// <reference types="@scenery/cavalry-types"/>
/// <reference types="@scenery/cavalry-types/render"/>

For a specific version

/// <reference types="@scenery/cavalry-types/versions/1.5.1"/>
/// <reference types="@scenery/cavalry-types/versions/1.5.1/render"/>
{
	"compilerOptions": {
		"types": ["@scenery/cavalry-types", "@scenery/cavalry-types/render"]
	}
}

cavalry-types's People

Contributors

klustre avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

aejuice-github

cavalry-types's Issues

Add missing methods for `Container`

Compare current methods with:

setRadius 
setLayout 
setBorder 
registerDragDropMimeType 
useHoverEvents 
setEnabled 
isEnabled 
setHidden 
isHidden 
setSize 
setFixedWidth 
setFixedHeight 
setToolTip 
setBackgroundColor 
getUUID 
update 

Hide username from types location

A slightly niche request but I don't script without Stallion (!) and the Types so always add this to the top of my files via the VS Code Extension (Insert Cavalry Types):

/// <reference path="/Users/[myUserName]/.vscode/extensions/scenery.cavalry-bridge-0.2.5/node_modules/@scenery/cavalry-types/index.d.ts"/>

I'm currently using this to write some scripts that will ship with Cavalry so, because I don't really want my username included, I'm removing this line from the final script. This is fine but if I then need to go back and update something I'm adding it back and then removing it again.

I think it would be a good thing to be able to keep this in (for convenience and for 'advertising' Stallion) so would it be possible to abstract the user name within the file path in some way (via a local configuration?) so that it's not included in the actual script?

This would also mean (in theory) anyone opening it and editing/improving it would be able to use it without needing to change it.

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.