gorp-ts
Fork of gorp for Roblox-ts.
Notice
It is preferred that you use jabby / ebba for new work.
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";
gorp_ecr.init({ ecr, gorp });
Client
import ecr from "@rbxts/ecr";
import gorp from "@rbxts/gorp";
import gorp_ecr from "@rbxts/gorp-ecr";
gorp_ecr.init({ ecr, gorp });
const Position = ecr.component(() => Vector3.zero);
const Velocity = ecr.component<Vector3>();
gorp.names({ pos: Position, vel: Velocity });
const world = ecr.registry();
gorp.hook_world(world, "main_world");
const client = gorp.get_client();
client.gorp_selector();
const ent = world.create();
world.add(ent, Position);
world.set(ent, Velocity, Vector3.xAxis);
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)));
}
}
game.GetService("RunService").RenderStepped.Connect((dt) => {
scheduler.system("position_system", position_system, dt);
scheduler.finish();
});
game.GetService("UserInputService").InputBegan.Connect((input) => {
if (input.KeyCode === Enum.KeyCode.F) {
client.enabled(!client.enabled());
}
});