Coder Social home page Coder Social logo

gorp-ts's Introduction

gorp-ts

Fork of gorp for Roblox-ts.

Differences to Luau version

  • This package is versioned with <gorp version>-ts.<x> where x is incremented for any changes to the TS version in particular.

Code sample with ecr

The following requires the gorp-ecr package

Server

import ecr from "@rbxts/ecr";
import gorp from "@rbxts/gorp";
import gorp_ecr from "@rbxts/gorp-ecr";

// Required, sets up the ecs layer for ecr
gorp_ecr.init({ ecr, gorp });

Client

import ecr from "@rbxts/ecr";
import gorp from "@rbxts/gorp";
import gorp_ecr from "@rbxts/gorp-ecr";

// Required, sets up the ecs layer for ecr
gorp_ecr.init({ ecr, gorp });

// Create components
const Position = ecr.component(() => Vector3.zero);
const Velocity = ecr.component<Vector3>();

// Assign names to components
gorp.names({ pos: Position, vel: Velocity });

// Create world and assign name
const world = ecr.registry();
gorp.hook_world(world, "main_world");

// Get the client and mount the selector interface
const client = gorp.get_client();
client.gorp_selector();

// Create entity, assign components
const ent = world.create();
world.add(ent, Position);
world.set(ent, Velocity, Vector3.xAxis);

// Create scheduler
const scheduler = gorp.scheduler("main_scheduler");

function position_system(dt: number) {
	for (const [id, pos, vel] of world.view(Position, Velocity)) {
		world.set(id, Position, pos.add(vel.mul(dt)));
	}
}

// Run the system every frame in the scheduler
game.GetService("RunService").RenderStepped.Connect((dt) => {
	scheduler.system("position_system", position_system, dt);
	scheduler.finish();
});

// Connect F keybind to toggle the interface
game.GetService("UserInputService").InputBegan.Connect((input) => {
	if (input.KeyCode === Enum.KeyCode.F) {
		client.enabled(!client.enabled());
	}
});

gorp-ts's People

Contributors

returnedtrue avatar aloroid avatar

Watchers

 avatar

Forkers

aloroid

gorp-ts's Issues

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.