npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@yantra-core/sdk

v0.4.3

Published

Yantra.gg Serverless Physics SDK for Node

Downloads

73

Readme

@yantra-core/sdk

@yantra-core/sdk is an SDK for interfacing with the Yantra serverless physics platform. With this SDK, you can create, manage, and interact with dynamic physics environments in the cloud. Below is a guide on how to use it.

Installation

Install the SDK CLI (Command Line Tool) with npm:

npm install -g @yantra-core/cli

Now you can run the yantra command on your system.


  __     __         _                _____ _      _____ 
  \ \   / /        | |              / ____| |    |_   _|
   \ \_/ /_ _ _ __ | |_ _ __ __ _  | |    | |      | |  
    \   / _` | '_ \| __| '__/ _` | | |    | |      | |  
     | | (_| | | | | |_| | | (_| | | |____| |____ _| |_ 
     |_|\__,_|_| |_|\__|_|  \__,_|  \_____|______|_____|
                                                        
 
Usage:  [options] [command]

Yantra Serverless Physics Platform CLI

Options:
  -V, --version   output the version number
  -h, --help      display help for command

Commands:
  init            Initialize a new world in the current directory
  clone           Clone a world from the Yantra library
  deploy          Deploy your physics world
  list            List your worlds
  info            Checks current directory for a Yantra world and displays information about it
  rm              Remove a world
  whoami          Display the current user
  login           Login to Yantra using OTP or create an account if it does not exist
  logout          Logs CLI client out of Yantra
  recover         Recover your account names by email address
  help [command]  display help for command

Features

  • Create Client: Generate a new instance of YantraClient
  • World Management: Connect to, or disconnect from, specific worlds.
  • Entity Management: Create and update entities in the physics world.
  • Physics Interactions: Apply forces, set velocities, and modify other physics-related attributes of entities.
  • Event Handling: React to various events and server messages.
  • World Deployment: Deploy physics world to cloud
  • Auto-scaling: Automatically scale resources for a given world in a specific region.

CLI Quick Start

Login / Register Account

Login with existing account name or register new account by email address

yantra login

Initialize and a new World

Installs base template for World development and deployment

mkdir my-world
cd my-world
yantra init

Clone existing Yantra World

Installs a pre-made World into current directory. Type yantra clone to view available Worlds

yantra clone pong
cd pong
npm start

Deploy World from localhost to cloud

Deploys local world to Yantra Cloud. Provides a default game client link via ayyo.gg

yantra clone snake
cd snake
yantra deploy

Client SDK Usage

Install the SDK Client with npm

npm install @yantra-core/client

Importing the Node SDK Client

import yantra from '@yantra-core/client';

Importing the Browser SDK

import yantra from '@yantra-core/client/client-browser.js';

Creating a Yantra Client

Basic Client Usage

const Y = yantra.createClient({
  owner: 'your_name',
  region: 'Washington_DC' // see https://yantra.gg/docs#regions
});

Connecting to a World

Using worldId. Will take a few seconds to boot if world is inactive.

await client.connect('my-world');

Interacting with Entities

Creating an entity

client.create(initialState);

Updating an entity

client.update(entityId, newState);

Applying force

client.applyForce(entityId, forceObject);

Setting velocity

client.setVelocity(entityId, velocityObject);

Setting a state You can also directly create, update, or destroy states by calling client.set(state)

client.set(state);

Listening to Events

Events: error, collision, gamestate

client.on('collision', data => {
  console.log('Received event:', data);
})
client.on('gamestate', function(snapshot){
  console.log(snapshot)
});
client.on('error', console.error);

Autoscaling

Games will autoscale based on maxPlayers settings and active connected players. When an instance is approaching maxPlayers, a new game instance will be created to help distribute the load.

Disconnecting

client.disconnect();

Building your Game on Yantra

Quick Start

In-Browser Development:

  • Editor: Use our browser-based Monaco Editor.
  • Run: Click "Run" to test your code against our servers.
  • Save: Click "Save" to store your code in our database.

Local Development:

  • Import the @yantra-core/client in your code.
  • Your game logic subscribes to the game state. Modify the state in response to each tick for dynamic gameplay.

Important:

  • No External Dependencies: Your code should run without requiring any external libraries or packages.
  • SDK Connection: When on our servers, @yantra-core/client auto-connects to the right localhost and port.

Running in Yantra's Environment:

When you upload your code to Yantra, it's executed in our optimized low-latency environment. Here's what you should know:

  • High Performance: Yantra's backend is fine-tuned to ensure your game logic runs smoothly.
  • Consistent Framerate: We prioritize a consistent, high framerate, ensuring your gameplay is fluid and responsive.
  • Direct Execution: Your uploaded code runs directly, 1:1, with no modifications or external dependencies. The performance you see locally will mirror what you get in our cloud environment.

Support

For issues, bugs, or feedback, please open an issue on our GitHub repository or visit us in our Discord